summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-04-27 10:58:45 -0400
committerJustin Luth <jluth@mail.com>2024-05-03 17:58:15 +0200
commitda86bfd89e529e787da0bbb3e3150c1f5d4e0dfd (patch)
treedd9c55105dbe65117e402603696b2385c87aaa7d /sfx2
parent9d95eb980ef12678f6fb978badcbe1cacbe0c4dc (diff)
tdf#160349: add .uno:ChangeTheme to notebookbar to toggle dark mode
A temporary (ugly, but appropriate) icon has been assigned. The toggle can be customize-assigned to keyboard, menu, and toolbar, and can be found by searching for "Dark Mode". In the menu, it is checked when in Dark mode, and in the toolbar it is "depressed" or highlighted as active. Dark mode has been added to the view tab of notebookbar.ui. I added it as NOT VISIBLE, for several reasons. - dark mode is rather new and not so stable, so don't over-promote it. - notebookbars cannot be infinitely customized by the end user, so developers have to add all items. Users only enable or disable. - toggling dark mode really ought to be done at the OS level, and typically should be a one-time setting, therefore not appropriate to waste precious toolbar space. The primary benefit of making it available in the menu is for QA testers who want to easily switch back and forth. WARNING: by customizing the notebookbar, you prevent seeing any future NBB changes made to the program (until you reset to defaults or blow away the user profile). Dark Mode can easily be added to a menu, toolbar or keyboard shortcut by the end user, so I didn't bother adding it anywhere else. To avoid completely cluttering up this commit, I only added Dark mode to the main notebookbar. Once this commit has been finalized, the other writer-apps and notebookbars can also gain this command. Change-Id: Ia7594ad81e305ead922abd0ad7b41d6fc0413053 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166781 Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org> Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/sdi/appslots.sdi1
-rw-r--r--sfx2/sdi/sfx.sdi5
-rw-r--r--sfx2/source/appl/appserv.cxx55
3 files changed, 55 insertions, 6 deletions
diff --git a/sfx2/sdi/appslots.sdi b/sfx2/sdi/appslots.sdi
index 4b2e0a5357bf..22aaf5ecc2ad 100644
--- a/sfx2/sdi/appslots.sdi
+++ b/sfx2/sdi/appslots.sdi
@@ -67,6 +67,7 @@ interface Application
FN_CHANGE_THEME // ole(no) api(final/play/rec)
[
ExecMethod = MiscExec_Impl ;
+ StateMethod = MiscState_Impl ;
]
SID_CONFIG // ole(no) api(final/play/rec)
[
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index 721ab116f60e..da8876a6f9c1 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -5933,11 +5933,14 @@ SfxVoidItem ChangeTheme FN_CHANGE_THEME
[
AutoUpdate = FALSE,
FastCall = FALSE,
- ReadOnlyDoc = FALSE,
+ ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
+ AccelConfig = TRUE,
+ MenuConfig = TRUE,
+ ToolBoxConfig = TRUE,
GroupId = SfxGroupId::Application;
]
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index 5dd93dc54a25..b7fa6c9f608f 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -620,20 +620,57 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
case FN_CHANGE_THEME:
{
const SfxStringItem* pNewThemeArg = rReq.GetArg<SfxStringItem>(FN_PARAM_NEW_THEME);
+ OUString sSchemeName
+ = pNewThemeArg ? pNewThemeArg->GetValue() : "COLOR_SCHEME_LIBREOFFICE_AUTOMATIC";
if (!pNewThemeArg)
{
- SAL_WARN("sfx.appl", "FN_CHANGE_THEME: no theme name");
- break;
+ // toggle between light and dark mode
+
+ // There are two separate things that can be dark mode themed: UI and document
+ // The modes can be 0 (automatic - what the OS/VCL asks for), 1 (light), or 2 (dark)
+
+ // Since only gtk/osx/win support UI theme, toggle based on document colors
+ // Automatic in this case means "whatever GetUseDarkMode() says"
+ const bool bWasInDarkMode
+ = MiscSettings::GetAppColorMode() == 2
+ || (MiscSettings::GetAppColorMode() == 0 && MiscSettings::GetUseDarkMode());
+
+ // Set the UI theme. It would be nicest to use automatic whenever possible
+ sal_Int32 nUseMode = 0; // automatic
+ if (MiscSettings::GetDarkMode() != 0)
+ MiscSettings::SetDarkMode(nUseMode);
+
+ if (MiscSettings::GetUseDarkMode() == bWasInDarkMode)
+ {
+ // automatic didn't toggle, so force the desired theme
+ nUseMode = bWasInDarkMode ? 1 : 2;
+ MiscSettings::SetDarkMode(nUseMode);
+ }
+
+ // Now set the document theme
+ // If the UI can be themed, then the document theme can always remain on automatic.
+ nUseMode = 0;
+ // NOTE: since SetDarkMode has run, GetUseDarkMode might return a different result.
+ if (MiscSettings::GetUseDarkMode() == bWasInDarkMode)
+ {
+ nUseMode = bWasInDarkMode ? 1 : 2;
+ sSchemeName = bWasInDarkMode ? u"Light" : u"Dark";
+ }
+ MiscSettings::SetAppColorMode(nUseMode);
}
- const OUString& rSchemeName = pNewThemeArg->GetValue();
svtools::EditableColorConfig aEditableConfig;
// kit explicitly ignores changes to the global color scheme, except for the current ViewShell,
// so an attempted change to the same global color scheme when the now current ViewShell ignored
// the last change requires re-sending the change. In which case individual shells will have to
// decide if this color-scheme change is a change from their perspective to avoid unnecessary
// invalidations.
- if (aEditableConfig.GetCurrentSchemeName() != rSchemeName || comphelper::LibreOfficeKit::isActive())
- aEditableConfig.LoadScheme(rSchemeName);
+ if (!pNewThemeArg || comphelper::LibreOfficeKit::isActive()
+ || aEditableConfig.GetCurrentSchemeName() != sSchemeName)
+ {
+ aEditableConfig.LoadScheme(sSchemeName);
+ }
+
+ Invalidate(FN_CHANGE_THEME);
break;
}
@@ -1233,6 +1270,14 @@ void SfxApplication::MiscState_Impl(SfxItemSet &rSet)
break;
#endif
+ case FN_CHANGE_THEME:
+ {
+ const bool bIsDarkMode
+ = MiscSettings::GetAppColorMode() == 2
+ || (!MiscSettings::GetAppColorMode() && MiscSettings::GetUseDarkMode());
+ rSet.Put(SfxBoolItem(FN_CHANGE_THEME, bIsDarkMode));
+ break;
+ }
case SID_HELPTIPS:
{
rSet.Put( SfxBoolItem( SID_HELPTIPS, Help::IsQuickHelpEnabled() ) );