summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-08-27 22:34:13 +0200
committerTomaž Vajngerl <quikee@gmail.com>2023-08-28 18:10:50 +0200
commit54d9425bc3165ed2bbab67c4719e6a0146a2c663 (patch)
tree0fa2fc4a35d07b7bb04040b8249935f6c2ec8401 /sd
parentb04ab5b24a431d51d9941545ac1b81a165fd287e (diff)
sd: add undo/redo action for changing the model::ColorSet
And add the undo action when changing the theme colors in the ThemeColorChanger. Change-Id: Ibeee8aeff420b42fd961e0abd630569e74075585 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156178 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit d3b06d044fafec0b31ada9ecbaf60f396555fb12) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156189 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Ashod Nakashian <ash@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/Library_sd.mk1
-rw-r--r--sd/source/core/ThemeColorChanger.cxx19
-rw-r--r--sd/source/ui/dlg/UndoThemeChange.cxx55
-rw-r--r--sd/source/ui/inc/UndoThemeChange.hxx39
4 files changed, 111 insertions, 3 deletions
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk
index 24e3c985a4ee..1d7333176c16 100644
--- a/sd/Library_sd.mk
+++ b/sd/Library_sd.mk
@@ -246,6 +246,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
sd/source/ui/dlg/sdtreelb \
sd/source/ui/dlg/titledockwin \
sd/source/ui/dlg/unchss \
+ sd/source/ui/dlg/UndoThemeChange \
sd/source/ui/docshell/docshel2 \
sd/source/ui/docshell/docshel3 \
sd/source/ui/docshell/docshel4 \
diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx
index 8d2a80aec281..573a5f085dd4 100644
--- a/sd/source/core/ThemeColorChanger.cxx
+++ b/sd/source/core/ThemeColorChanger.cxx
@@ -24,6 +24,8 @@
#include <unchss.hxx>
#include <ViewShell.hxx>
#include <ViewShellBase.hxx>
+#include <undo/undomanager.hxx>
+#include <UndoThemeChange.hxx>
using namespace css;
@@ -39,7 +41,8 @@ ThemeColorChanger::~ThemeColorChanger() = default;
namespace
{
-void changeTheTheme(SdrPage* pMasterPage, std::shared_ptr<model::ColorSet> const& pColorSet)
+void changeThemeColors(sd::DrawDocShell* pDocShell, SdrPage* pMasterPage,
+ std::shared_ptr<model::ColorSet> const& pNewColorSet)
{
auto pTheme = pMasterPage->getSdrPageProperties().getTheme();
if (!pTheme)
@@ -47,7 +50,17 @@ void changeTheTheme(SdrPage* pMasterPage, std::shared_ptr<model::ColorSet> const
pTheme = std::make_shared<model::Theme>("Office");
pMasterPage->getSdrPageProperties().setTheme(pTheme);
}
- pTheme->setColorSet(pColorSet);
+
+ std::shared_ptr<model::ColorSet> const& pOldColorSet = pTheme->getColorSet();
+
+ auto* pUndoManager = pDocShell->GetUndoManager();
+ if (pUndoManager)
+ {
+ pUndoManager->AddUndoAction(std::make_unique<UndoThemeChange>(
+ pDocShell->GetDoc(), pMasterPage, pOldColorSet, pNewColorSet));
+ }
+
+ pTheme->setColorSet(pNewColorSet);
}
bool changeStyle(sd::DrawDocShell* pDocShell, SdStyleSheet* pStyle,
@@ -164,7 +177,7 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet)
}
}
- changeTheTheme(mpMasterPage, pColorSet);
+ changeThemeColors(mpDocShell, mpMasterPage, pColorSet);
pUndoManager->LeaveListAction();
}
diff --git a/sd/source/ui/dlg/UndoThemeChange.cxx b/sd/source/ui/dlg/UndoThemeChange.cxx
new file mode 100644
index 000000000000..1270dc06cab7
--- /dev/null
+++ b/sd/source/ui/dlg/UndoThemeChange.cxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <UndoThemeChange.hxx>
+#include <svx/dialmgr.hxx>
+#include <svx/strings.hrc>
+
+namespace sd
+{
+UndoThemeChange::UndoThemeChange(SdDrawDocument* pDocument, SdrPage* pMasterPage,
+ std::shared_ptr<model::ColorSet> const& pOldColorSet,
+ std::shared_ptr<model::ColorSet> const& pNewColorSet)
+ : SdUndoAction(pDocument)
+ , mpMasterPage(pMasterPage)
+ , mpOldColorSet(pOldColorSet)
+ , mpNewColorSet(pNewColorSet)
+{
+ SetComment(SvxResId(RID_SVXSTR_UNDO_THEME_COLOR_CHANGE));
+}
+
+namespace
+{
+std::shared_ptr<model::Theme> getTheme(SdrPage* pMasterPage)
+{
+ auto pTheme = pMasterPage->getSdrPageProperties().getTheme();
+ if (!pTheme)
+ {
+ pTheme = std::make_shared<model::Theme>("Office");
+ pMasterPage->getSdrPageProperties().setTheme(pTheme);
+ }
+ return pTheme;
+}
+}
+
+void UndoThemeChange::Undo()
+{
+ auto pTheme = getTheme(mpMasterPage);
+ pTheme->setColorSet(mpOldColorSet);
+}
+
+void UndoThemeChange::Redo()
+{
+ auto pTheme = getTheme(mpMasterPage);
+ pTheme->setColorSet(mpNewColorSet);
+}
+
+} // end sd namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/inc/UndoThemeChange.hxx b/sd/source/ui/inc/UndoThemeChange.hxx
new file mode 100644
index 000000000000..798f2adb50bf
--- /dev/null
+++ b/sd/source/ui/inc/UndoThemeChange.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <memory>
+#include <sdundo.hxx>
+#include <svx/svdpage.hxx>
+#include <docmodel/theme/Theme.hxx>
+
+class SdDrawDocument;
+
+namespace sd
+{
+class UndoThemeChange : public SdUndoAction
+{
+private:
+ SdrPage* mpMasterPage;
+ std::shared_ptr<model::ColorSet> mpOldColorSet;
+ std::shared_ptr<model::ColorSet> mpNewColorSet;
+
+public:
+ UndoThemeChange(SdDrawDocument* pDocument, SdrPage* pMasterPage,
+ std::shared_ptr<model::ColorSet> const& pOldColorSet,
+ std::shared_ptr<model::ColorSet> const& pNewColorSet);
+
+ virtual void Undo() override;
+ virtual void Redo() override;
+};
+
+} // namespace sd
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */