diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-04-08 19:57:04 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-04-08 20:57:59 +0000 |
commit | effa6dcb553bd3fc6df89ac88604816feda98873 (patch) | |
tree | 9a4b29d11159395ba13fc325274e634c274278ea /sc/source/ui | |
parent | uitest: disable failing assert (diff) | |
download | core-effa6dcb553bd3fc6df89ac88604816feda98873.tar.gz core-effa6dcb553bd3fc6df89ac88604816feda98873.zip |
support undo of whole conditional format list, tdf#95617
Change-Id: I3ff0ddb05f794064e33164c60cd1b4e6b89dbcca
Reviewed-on: https://gerrit.libreoffice.org/36295
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 36 | ||||
-rw-r--r-- | sc/source/ui/inc/undoblk.hxx | 21 | ||||
-rw-r--r-- | sc/source/ui/src/globstr.src | 5 | ||||
-rw-r--r-- | sc/source/ui/undo/undoblk.cxx | 60 |
4 files changed, 114 insertions, 8 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index dda9430eb37e..1619865cf7e9 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -5470,22 +5470,42 @@ void ScDocFunc::SetConditionalFormatList( ScConditionalFormatList* pList, SCTAB if(rDoc.IsTabProtected(nTab)) return; - // first remove all old entries - ScConditionalFormatList* pOldList = rDoc.GetCondFormList(nTab); - for(ScConditionalFormatList::const_iterator itr = pOldList->begin(), itrEnd = pOldList->end(); itr != itrEnd; ++itr) + bool bUndo = rDoc.IsUndoEnabled(); + ScDocument* pUndoDoc = nullptr; + if (bUndo) { - rDoc.RemoveCondFormatData((*itr)->GetRange(), nTab, (*itr)->GetKey()); + pUndoDoc = new ScDocument(SCDOCMODE_UNDO); + pUndoDoc->InitUndo( &rDoc, nTab, nTab ); + + ScConditionalFormatList* pOld = rDoc.GetCondFormList(nTab); + + if (pOld) + pUndoDoc->SetCondFormList(new ScConditionalFormatList(pUndoDoc, *pOld), nTab); + else + pUndoDoc->SetCondFormList(nullptr, nTab); + } + // first remove all old entries + ScConditionalFormatList* pOldList = rDoc.GetCondFormList(nTab); + pOldList->RemoveFromDocument(&rDoc); + // then set new entries - for(ScConditionalFormatList::iterator itr = pList->begin(); itr != pList->end(); ++itr) - { - rDoc.AddCondFormatData((*itr)->GetRange(), nTab, (*itr)->GetKey()); - } + pList->AddToDocument(&rDoc); rDoc.SetCondFormList(pList, nTab); rDocShell.PostPaintGridAll(); + if(bUndo) + { + ScDocument* pRedoDoc = new ScDocument(SCDOCMODE_UNDO); + pRedoDoc->InitUndo( &rDoc, nTab, nTab ); + pRedoDoc->SetCondFormList(new ScConditionalFormatList(pRedoDoc, *pList), nTab); + + rDocShell.GetUndoManager()->AddUndoAction( + new ScUndoConditionalFormatList(&rDocShell, pUndoDoc, pRedoDoc, nTab)); + } + rDoc.SetStreamValid(nTab, false); aModificator.SetDocumentModified(); SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScAreasChanged)); diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx index c558b44227ab..b5cc4ad789c1 100644 --- a/sc/source/ui/inc/undoblk.hxx +++ b/sc/source/ui/inc/undoblk.hxx @@ -631,6 +631,27 @@ private: ScRange maRange; }; +class ScUndoConditionalFormatList : public ScSimpleUndo +{ +public: + ScUndoConditionalFormatList( ScDocShell* pNewDocShell, + ScDocument* pUndoDoc, ScDocument* pRedoDoc, SCTAB nTab); + virtual ~ScUndoConditionalFormatList() override; + + virtual void Undo() override; + virtual void Redo() override; + virtual void Repeat(SfxRepeatTarget& rTarget) override; + virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; + + virtual OUString GetComment() const override; + +private: + void DoChange(ScDocument* pDoc); + std::unique_ptr<ScDocument> mpUndoDoc; + std::unique_ptr<ScDocument> mpRedoDoc; + SCTAB mnTab; +}; + class ScUndoUseScenario: public ScSimpleUndo { public: diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src index 0a26724c0a7b..79365253deb6 100644 --- a/sc/source/ui/src/globstr.src +++ b/sc/source/ui/src/globstr.src @@ -1873,6 +1873,11 @@ String STR_UNDO_CONDFORMAT+RID_GLOBSTR_OFFSET Text [ en-US ] = "Conditional Format"; }; +String STR_UNDO_CONDFORMAT_LIST+RID_GLOBSTR_OFFSET +{ + Text [ en-US ] = "Conditional Formats"; +}; + String STR_UNDO_FORMULA_TO_VALUE+RID_GLOBSTR_OFFSET { Text [ en-US ] = "Convert Formula To Value"; diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx index 217022845109..dccc583e1317 100644 --- a/sc/source/ui/undo/undoblk.cxx +++ b/sc/source/ui/undo/undoblk.cxx @@ -1535,6 +1535,66 @@ bool ScUndoConditionalFormat::CanRepeat(SfxRepeatTarget& ) const return false; } +ScUndoConditionalFormatList::ScUndoConditionalFormatList(ScDocShell* pNewDocShell, + ScDocument* pUndoDoc, ScDocument* pRedoDoc, SCTAB nTab): + ScSimpleUndo( pNewDocShell ), + mpUndoDoc(pUndoDoc), + mpRedoDoc(pRedoDoc), + mnTab(nTab) +{ +} + +ScUndoConditionalFormatList::~ScUndoConditionalFormatList() +{ +} + +OUString ScUndoConditionalFormatList::GetComment() const +{ + return ScGlobal::GetRscString( STR_UNDO_CONDFORMAT_LIST ); +} + +void ScUndoConditionalFormatList::Undo() +{ + DoChange(mpUndoDoc.get()); +} + +void ScUndoConditionalFormatList::Redo() +{ + DoChange(mpRedoDoc.get()); +} + +void ScUndoConditionalFormatList::DoChange(ScDocument* pSrcDoc) +{ + ScDocument& rDoc = pDocShell->GetDocument(); + + if (pSrcDoc == mpUndoDoc.get()) + { + mpRedoDoc->GetCondFormList(mnTab)->RemoveFromDocument(&rDoc); + mpUndoDoc->GetCondFormList(mnTab)->AddToDocument(&rDoc); + } + else + { + mpUndoDoc->GetCondFormList(mnTab)->RemoveFromDocument(&rDoc); + mpRedoDoc->GetCondFormList(mnTab)->AddToDocument(&rDoc); + } + rDoc.SetCondFormList(new ScConditionalFormatList(&rDoc, *pSrcDoc->GetCondFormList(mnTab)), mnTab); + + pDocShell->PostPaintGridAll(); + pDocShell->PostDataChanged(); + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (pViewShell) + pViewShell->CellContentChanged(); +} + +void ScUndoConditionalFormatList::Repeat(SfxRepeatTarget& ) +{ +} + +bool ScUndoConditionalFormatList::CanRepeat(SfxRepeatTarget& ) const +{ + return false; +} + ScUndoUseScenario::ScUndoUseScenario( ScDocShell* pNewDocShell, const ScMarkData& rMark, /*C*/ const ScArea& rDestArea, |