diff --git a/PowerEditor/installer/themes/DarkModeDefault.xml b/PowerEditor/installer/themes/DarkModeDefault.xml
new file mode 100644
index 000000000..9d54812e5
--- /dev/null
+++ b/PowerEditor/installer/themes/DarkModeDefault.xml
@@ -0,0 +1,1385 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp
index 09a68217b..48d10674c 100644
--- a/PowerEditor/src/Notepad_plus.cpp
+++ b/PowerEditor/src/Notepad_plus.cpp
@@ -7546,6 +7546,43 @@ void Notepad_plus::refreshDarkMode()
break;
}
+
+ NppParameters& nppParams = NppParameters::getInstance();
+ ThemeSwitcher & themeSwitcher = nppParams.getThemeSwitcher();
+ generic_string themePath;
+ generic_string themeName;
+ const TCHAR darkModeXmlFileName[] = TEXT("DarkModeDefault.xml");
+ if (NppDarkMode::isEnabled())
+ {
+ themePath = themeSwitcher.getThemeDirPath();
+ PathAppend(themePath, darkModeXmlFileName);
+
+ themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str());
+ }
+ else
+ {
+ //use _stylerPath;
+
+ pair & themeInfo = themeSwitcher.getElementFromIndex(0);
+ themePath = themeInfo.second;
+ themeName = themeSwitcher.getDefaultThemeLabel();
+ }
+
+ if (::PathFileExists(themePath.c_str()))
+ {
+ nppParams.getNppGUI()._themeName = themePath;
+
+ if (_configStyleDlg.isCreated())
+ {
+ _configStyleDlg.selectThemeByName(themeName.c_str());
+ }
+ else
+ {
+ nppParams.reloadStylers(themePath.c_str());
+ ::SendMessage(_pPublicInterface->getHSelf(), WM_UPDATESCINTILLAS, 0, 0);
+ }
+ }
+
if (NppDarkMode::isExperimentalEnabled())
{
RECT rcClient;
diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp
index d0b786f4f..a0053fe6f 100644
--- a/PowerEditor/src/Notepad_plus_Window.cpp
+++ b/PowerEditor/src/Notepad_plus_Window.cpp
@@ -203,6 +203,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
{
themeDir = nppParams.getAppDataNppDir();
PathAppend(themeDir, TEXT("themes\\"));
+ themeSwitcher.setThemeDirPath(themeDir);
_notepad_plus_plus_core.getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false);
for (size_t i = 0, len = fileNames.size() ; i < len ; ++i)
{
diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp
index b537e1841..79aad0154 100644
--- a/PowerEditor/src/Parameters.cpp
+++ b/PowerEditor/src/Parameters.cpp
@@ -895,7 +895,7 @@ NppParameters::~NppParameters()
}
-bool NppParameters::reloadStylers(TCHAR* stylePath)
+bool NppParameters::reloadStylers(const TCHAR* stylePath)
{
delete _pXmlUserStylerDoc;
diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h
index 1eecfb7d9..cd5c96374 100644
--- a/PowerEditor/src/Parameters.h
+++ b/PowerEditor/src/Parameters.h
@@ -1277,7 +1277,7 @@ public:
void addDefaultThemeFromXml(const generic_string& xmlFullPath)
{
- _themeList.push_back(std::pair(TEXT("Default (stylers.xml)"), xmlFullPath));
+ _themeList.push_back(std::pair(_defaultThemeLabel, xmlFullPath));
}
generic_string getThemeFromXmlFileName(const TCHAR *fn) const;
@@ -1312,8 +1312,15 @@ public:
return _themeList[index];
}
+ void setThemeDirPath(generic_string themeDirPath) { _themeDirPath = themeDirPath; }
+ generic_string getThemeDirPath() const { return _themeDirPath; }
+
+ generic_string getDefaultThemeLabel() const { return _defaultThemeLabel; }
+
private:
std::vector> _themeList;
+ generic_string _themeDirPath;
+ const generic_string _defaultThemeLabel = TEXT("Default (stylers.xml)");
generic_string _stylesXmlPath;
};
@@ -1364,7 +1371,7 @@ public:
bool load();
bool reloadLang();
- bool reloadStylers(TCHAR *stylePath = nullptr);
+ bool reloadStylers(const TCHAR *stylePath = nullptr);
void destroyInstance();
generic_string getSettingsFolder();
diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp
index 07d2e220a..7ea2ef2f5 100644
--- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp
+++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp
@@ -226,8 +226,8 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
NppParameters& nppParamInst = NppParameters::getInstance();
if (_restoreInvalid)
{
- generic_string str( nppParamInst.getNppGUI()._themeName );
- nppParamInst.reloadStylers( &str[0] );
+ generic_string str(nppParamInst.getNppGUI()._themeName);
+ nppParamInst.reloadStylers(str.c_str());
}
LexerStylerArray & lsArray = nppParamInst.getLStylerArray();
@@ -395,11 +395,7 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
break;
case IDC_SWITCH2THEME_COMBO :
- switchToTheme();
- setVisualFromStyleList();
- notifyDataModified();
- _isThemeDirty = false;
- apply();
+ applyCurrentSelectedThemeAndUpdateUI();
break;
}
return TRUE;
@@ -646,13 +642,35 @@ void WordStyleDlg::switchToTheme()
if ( mb_response == IDYES )
(NppParameters::getInstance()).writeStyles(_lsArray, _globalStyles);
}
- nppParamInst.reloadStylers(&_themeName[0]);
+ nppParamInst.reloadStylers(_themeName.c_str());
loadLangListFromNppParam();
_restoreInvalid = true;
}
+void WordStyleDlg::applyCurrentSelectedThemeAndUpdateUI()
+{
+ switchToTheme();
+ setVisualFromStyleList();
+ notifyDataModified();
+ _isThemeDirty = false;
+ apply();
+}
+
+bool WordStyleDlg::selectThemeByName(const TCHAR* themeName)
+{
+ LRESULT iTheme = ::SendMessage(_hSwitch2ThemeCombo, CB_FINDSTRING, 1, reinterpret_cast(themeName));
+ if (iTheme == CB_ERR)
+ return false;
+
+ ::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, iTheme, 0);
+
+ applyCurrentSelectedThemeAndUpdateUI();
+
+ return true;
+}
+
void WordStyleDlg::setStyleListFromLexer(int index)
{
_currentLexerIndex = index;
diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h
index ea5dc9bfa..efa638416 100644
--- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h
+++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h
@@ -107,6 +107,7 @@ public :
::SendMessage(_hSwitch2ThemeCombo, CB_ADDSTRING, 0, reinterpret_cast(themeInfo.first.c_str()));
};
+ bool selectThemeByName(const TCHAR* themeName);
private :
ColourPicker *_pFgColour = nullptr;
@@ -225,4 +226,6 @@ private :
::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_UNDERLINE_CHECK), show?SW_SHOW:SW_HIDE);
_isShownGOCtrls = show;
};
+
+ void applyCurrentSelectedThemeAndUpdateUI();
};