summaryrefslogtreecommitdiff
path: root/svx/source/styles
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-04-25 23:10:35 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-04-25 20:38:25 +0200
commit8e5df127d26e42c3535e66f1733730e32e12df4d (patch)
treeaef69e291f9f7771b29d730153fbd7028c7546cf /svx/source/styles
parent5cde4f2781fc80ed32aac2ad9c81cadab80860e8 (diff)
svx: rework the theme dialog to allow editing theme colors
In addition to editing of theme colors, this also changes the way how theme colors are represented in the theme dialog and the behaviour when changing applying a theme color change. Previously a theme colors were applied with double-click, now a double-click still applies, but automatically exits the dialog. The selected theme is applied also when OK button is pressed. Change-Id: Ic0f8399ede180d6ab0001a7f8b5dda0e7c49fa3c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150975 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source/styles')
-rw-r--r--svx/source/styles/ColorSets.cxx51
1 files changed, 44 insertions, 7 deletions
diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index 438a9a36b01c..cfdeb83df442 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -11,6 +11,7 @@
#include <svx/ColorSets.hxx>
#include <utility>
+#include <unordered_set>
#include <docmodel/theme/ColorSet.hxx>
using namespace com::sun::star;
@@ -157,20 +158,56 @@ model::ColorSet const* ColorSets::getColorSet(std::u16string_view rName) const
}
return nullptr;
}
+namespace
+{
-void ColorSets::insert(model::ColorSet const& rNewColorSet)
+OUString findUniqueName(std::unordered_set<OUString> const& rNames, OUString const& rNewName)
{
- for (model::ColorSet& rColorSet : maColorSets)
+ auto iterator = rNames.find(rNewName);
+ if (iterator == rNames.cend())
+ return rNewName;
+
+ int i = 1;
+ OUString aName;
+ do
{
- if (rColorSet.getName() == rNewColorSet.getName())
+ aName = rNewName + "_" + OUString::number(i);
+ i++;
+ iterator = rNames.find(aName);
+ } while (iterator != rNames.cend());
+
+ return aName;
+}
+
+} // end anonymous namespace
+
+void ColorSets::insert(model::ColorSet const& rNewColorSet, IdenticalNameAction eAction)
+{
+ if (eAction == IdenticalNameAction::Overwrite)
+ {
+ for (model::ColorSet& rColorSet : maColorSets)
{
- rColorSet = rNewColorSet;
- return;
+ if (rColorSet.getName() == rNewColorSet.getName())
+ {
+ rColorSet = rNewColorSet;
+ return;
+ }
}
+ // color set not found, so insert it
+ maColorSets.push_back(rNewColorSet);
}
+ else if (eAction == IdenticalNameAction::AutoRename)
+ {
+ std::unordered_set<OUString> aNames;
+ for (model::ColorSet& rColorSet : maColorSets)
+ aNames.insert(rColorSet.getName());
- // color set not found, so insert it
- maColorSets.push_back(rNewColorSet);
+ OUString aName = findUniqueName(aNames, rNewColorSet.getName());
+
+ model::ColorSet aNewColorSet = rNewColorSet;
+ aNewColorSet.setName(aName);
+ maColorSets.push_back(aNewColorSet);
+ }
}
} // end of namespace svx