summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-08-15 17:25:15 +0200
committerTomaž Vajngerl <quikee@gmail.com>2023-08-25 14:05:46 +0200
commit286bde4f083470490251c2f43ffb7ea9b236b4fd (patch)
treead85796eac8c41d99e43cb7a8ba553e8f6f0f1e1 /sd
parent7d7b2747751c442b7c75680d9960de70037e38d8 (diff)
sd: add undo/redo for line/fill styles theme change
Change-Id: I780e261c013a44426ce1baa3b10ddcf497dd54c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155817 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/source/core/ThemeColorChanger.cxx84
1 files changed, 60 insertions, 24 deletions
diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx
index d0a84c866495..84a00527069c 100644
--- a/sd/source/core/ThemeColorChanger.cxx
+++ b/sd/source/core/ThemeColorChanger.cxx
@@ -17,6 +17,13 @@
#include <svx/xlnclit.hxx>
#include <svx/xflclit.hxx>
#include <svx/xdef.hxx>
+#include <svx/dialmgr.hxx>
+#include <svx/strings.hrc>
+#include <editeng/eeitem.hxx>
+
+#include <unchss.hxx>
+#include <ViewShell.hxx>
+#include <ViewShellBase.hxx>
using namespace css;
@@ -43,46 +50,73 @@ void changeTheTheme(SdrPage* pMasterPage, std::shared_ptr<model::ColorSet> const
pTheme->setColorSet(pColorSet);
}
-bool changeStyles(sd::DrawDocShell* pDocShell, std::shared_ptr<model::ColorSet> const& pColorSet)
+bool changeStyle(sd::DrawDocShell* pDocShell, SdStyleSheet* pStyle,
+ std::shared_ptr<model::ColorSet> const& pColorSet)
{
- SfxStyleSheetBasePool* pPool = pDocShell->GetStyleSheetPool();
+ bool bChanged = false;
- SdStyleSheet* pStyle = static_cast<SdStyleSheet*>(pPool->First(SfxStyleFamily::Para));
- while (pStyle)
+ auto aItemSet = pStyle->GetItemSet();
+ if (const XFillColorItem* pItem = aItemSet.GetItemIfSet(XATTR_FILLCOLOR, false))
{
- auto& rItemSet = pStyle->GetItemSet();
- if (const XFillColorItem* pItem = rItemSet.GetItemIfSet(XATTR_FILLCOLOR, false))
+ model::ComplexColor const& rComplexColor = pItem->getComplexColor();
+ if (rComplexColor.isValidThemeType())
{
- model::ComplexColor const& rComplexColor = pItem->getComplexColor();
- if (rComplexColor.isValidThemeType())
- {
- Color aNewColor = pColorSet->resolveColor(rComplexColor);
- std::unique_ptr<XFillColorItem> pNewItem(pItem->Clone());
- pNewItem->SetColorValue(aNewColor);
- rItemSet.Put(*pNewItem);
- }
+ Color aNewColor = pColorSet->resolveColor(rComplexColor);
+ std::unique_ptr<XFillColorItem> pNewItem(pItem->Clone());
+ pNewItem->SetColorValue(aNewColor);
+ aItemSet.Put(*pNewItem);
+ bChanged = true;
}
- if (const XLineColorItem* pItem = rItemSet.GetItemIfSet(XATTR_LINECOLOR, false))
+ }
+ if (const XLineColorItem* pItem = aItemSet.GetItemIfSet(XATTR_LINECOLOR, false))
+ {
+ model::ComplexColor const& rComplexColor = pItem->getComplexColor();
+ if (rComplexColor.isValidThemeType())
{
- model::ComplexColor const& rComplexColor = pItem->getComplexColor();
- if (rComplexColor.isValidThemeType())
- {
- Color aNewColor = pColorSet->resolveColor(rComplexColor);
- std::unique_ptr<XLineColorItem> pNewItem(pItem->Clone());
- pNewItem->SetColorValue(aNewColor);
- rItemSet.Put(*pNewItem);
- }
+ Color aNewColor = pColorSet->resolveColor(rComplexColor);
+ std::unique_ptr<XLineColorItem> pNewItem(pItem->Clone());
+ pNewItem->SetColorValue(aNewColor);
+ aItemSet.Put(*pNewItem);
+ bChanged = true;
}
+ }
+ if (bChanged)
+ {
+ pDocShell->GetUndoManager()->AddUndoAction(
+ std::make_unique<StyleSheetUndoAction>(pDocShell->GetDoc(), pStyle, &aItemSet));
+ pStyle->GetItemSet().Put(aItemSet);
+ pStyle->Broadcast(SfxHint(SfxHintId::DataChanged));
+ }
+ return bChanged;
+}
+
+bool changeStyles(sd::DrawDocShell* pDocShell, std::shared_ptr<model::ColorSet> const& pColorSet)
+{
+ bool bChanged = false;
+ SfxStyleSheetBasePool* pPool = pDocShell->GetStyleSheetPool();
+
+ SdStyleSheet* pStyle = static_cast<SdStyleSheet*>(pPool->First(SfxStyleFamily::Para));
+ while (pStyle)
+ {
+ bChanged = changeStyle(pDocShell, pStyle, pColorSet) || bChanged;
pStyle = static_cast<SdStyleSheet*>(pPool->Next());
}
- return true;
+ return bChanged;
}
} // end anonymous ns
void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet)
{
+ auto* pUndoManager = mpDocShell->GetUndoManager();
+
+ ViewShellId nViewShellId(-1);
+ if (sd::ViewShell* pViewShell = mpDocShell->GetViewShell())
+ nViewShellId = pViewShell->GetViewShellBase().GetViewShellId();
+ pUndoManager->EnterListAction(SvxResId(RID_SVXSTR_UNDO_THEME_COLOR_CHANGE), "", 0,
+ nViewShellId);
+
changeStyles(mpDocShell, pColorSet);
SdrModel& rModel = mpMasterPage->getSdrModelFromSdrPage();
@@ -112,6 +146,8 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet)
}
changeTheTheme(mpMasterPage, pColorSet);
+
+ pUndoManager->LeaveListAction();
}
} // end sd namespace