Fix theme not changed issue after switching dark/light mode in some cases
1. Fix custom theme (in %APPDATA%) not changing if it is not in default theme dir (in the installation location). 2. Fix default dark theme not applied in dark mode if config is missing (For example, the 1st launch of Notepad++ after its installation). 3. Fix theme not working in cloud issue and portable mode. Fix #6092, fix #10801, fix #12296, close #12662
This commit is contained in:
parent
a0c41cc5a5
commit
6518f3e4b8
|
@ -7929,9 +7929,19 @@ void Notepad_plus::refreshDarkMode(bool resetStyle)
|
||||||
|
|
||||||
generic_string xmlFileName = NppDarkMode::getThemeName();
|
generic_string xmlFileName = NppDarkMode::getThemeName();
|
||||||
if (!xmlFileName.empty())
|
if (!xmlFileName.empty())
|
||||||
|
{
|
||||||
|
if (!nppParams.isLocal() || nppParams.isCloud())
|
||||||
|
{
|
||||||
|
themePath = nppParams.getUserPath();
|
||||||
|
pathAppend(themePath, TEXT("themes\\"));
|
||||||
|
pathAppend(themePath, xmlFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (::PathFileExists(themePath.c_str()) == FALSE || themePath.empty())
|
||||||
{
|
{
|
||||||
themePath = themeSwitcher.getThemeDirPath();
|
themePath = themeSwitcher.getThemeDirPath();
|
||||||
pathAppend(themePath, xmlFileName);
|
pathAppend(themePath, xmlFileName);
|
||||||
|
}
|
||||||
|
|
||||||
themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str());
|
themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str());
|
||||||
}
|
}
|
||||||
|
@ -7944,7 +7954,7 @@ void Notepad_plus::refreshDarkMode(bool resetStyle)
|
||||||
themeName = themeSwitcher.getDefaultThemeLabel();
|
themeName = themeSwitcher.getDefaultThemeLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (::PathFileExists(themePath.c_str()))
|
if (::PathFileExists(themePath.c_str()) == TRUE)
|
||||||
{
|
{
|
||||||
nppParams.getNppGUI()._themeName = themePath;
|
nppParams.getNppGUI()._themeName = themePath;
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
timestampBegin = time(NULL);
|
timestampBegin = time(NULL);
|
||||||
|
|
||||||
Window::init(hInst, parent);
|
Window::init(hInst, parent);
|
||||||
WNDCLASS nppClass;
|
WNDCLASS nppClass{};
|
||||||
|
|
||||||
nppClass.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS;
|
nppClass.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS;
|
||||||
nppClass.lpfnWndProc = Notepad_plus_Proc;
|
nppClass.lpfnWndProc = Notepad_plus_Proc;
|
||||||
|
@ -128,7 +128,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WINDOWPLACEMENT posInfo;
|
WINDOWPLACEMENT posInfo{};
|
||||||
posInfo.length = sizeof(WINDOWPLACEMENT);
|
posInfo.length = sizeof(WINDOWPLACEMENT);
|
||||||
posInfo.flags = 0;
|
posInfo.flags = 0;
|
||||||
if (_isPrelaunch)
|
if (_isPrelaunch)
|
||||||
|
@ -215,10 +215,9 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
// Get themes from both npp install themes dir and app data themes dir with the per user
|
// Get themes from both npp install themes dir and app data themes dir with the per user
|
||||||
// overriding default themes of the same name.
|
// overriding default themes of the same name.
|
||||||
|
|
||||||
generic_string appDataThemeDir;
|
generic_string appDataThemeDir = nppParams.isCloud() ? nppParams.getUserPath() : nppParams.getAppDataNppDir();
|
||||||
if (nppParams.getAppDataNppDir() && nppParams.getAppDataNppDir()[0])
|
if (!appDataThemeDir.empty())
|
||||||
{
|
{
|
||||||
appDataThemeDir = nppParams.getAppDataNppDir();
|
|
||||||
pathAppend(appDataThemeDir, TEXT("themes\\"));
|
pathAppend(appDataThemeDir, TEXT("themes\\"));
|
||||||
_notepad_plus_plus_core.getMatchedFileNames(appDataThemeDir.c_str(), 0, patterns, fileNames, false, false);
|
_notepad_plus_plus_core.getMatchedFileNames(appDataThemeDir.c_str(), 0, patterns, fileNames, false, false);
|
||||||
for (size_t i = 0, len = fileNames.size() ; i < len ; ++i)
|
for (size_t i = 0, len = fileNames.size() ; i < len ; ++i)
|
||||||
|
@ -230,7 +229,10 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
fileNames.clear();
|
fileNames.clear();
|
||||||
|
|
||||||
generic_string nppThemeDir;
|
generic_string nppThemeDir;
|
||||||
|
if (!nppParams.isLocal())
|
||||||
|
{
|
||||||
nppThemeDir = nppDir.c_str(); // <- should use the pointer to avoid the constructor of copy
|
nppThemeDir = nppDir.c_str(); // <- should use the pointer to avoid the constructor of copy
|
||||||
|
}
|
||||||
pathAppend(nppThemeDir, TEXT("themes\\"));
|
pathAppend(nppThemeDir, TEXT("themes\\"));
|
||||||
|
|
||||||
// Set theme directory to their installation directory
|
// Set theme directory to their installation directory
|
||||||
|
@ -240,7 +242,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
for (size_t i = 0, len = fileNames.size(); i < len ; ++i)
|
for (size_t i = 0, len = fileNames.size(); i < len ; ++i)
|
||||||
{
|
{
|
||||||
generic_string themeName( themeSwitcher.getThemeFromXmlFileName(fileNames[i].c_str()) );
|
generic_string themeName( themeSwitcher.getThemeFromXmlFileName(fileNames[i].c_str()) );
|
||||||
if (!themeSwitcher.themeNameExists(themeName.c_str()) )
|
if (!themeSwitcher.themeNameExists(themeName.c_str()))
|
||||||
{
|
{
|
||||||
themeSwitcher.addThemeFromXml(fileNames[i]);
|
themeSwitcher.addThemeFromXml(fileNames[i]);
|
||||||
|
|
||||||
|
@ -265,17 +267,27 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
generic_string themePath;
|
generic_string themePath;
|
||||||
generic_string xmlFileName = NppDarkMode::getThemeName();
|
generic_string xmlFileName = NppDarkMode::getThemeName();
|
||||||
if (!xmlFileName.empty())
|
if (!xmlFileName.empty())
|
||||||
|
{
|
||||||
|
if (!nppParams.isLocal() || nppParams.isCloud())
|
||||||
|
{
|
||||||
|
themePath = nppParams.getUserPath();
|
||||||
|
pathAppend(themePath, TEXT("themes\\"));
|
||||||
|
pathAppend(themePath, xmlFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (::PathFileExists(themePath.c_str()) == FALSE || themePath.empty())
|
||||||
{
|
{
|
||||||
themePath = themeSwitcher.getThemeDirPath();
|
themePath = themeSwitcher.getThemeDirPath();
|
||||||
pathAppend(themePath, xmlFileName);
|
pathAppend(themePath, xmlFileName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto& themeInfo = themeSwitcher.getElementFromIndex(0);
|
auto& themeInfo = themeSwitcher.getElementFromIndex(0);
|
||||||
themePath = themeInfo.second;
|
themePath = themeInfo.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (::PathFileExists(themePath.c_str()))
|
if (::PathFileExists(themePath.c_str()) == TRUE)
|
||||||
{
|
{
|
||||||
nppGUI._themeName.assign(themePath);
|
nppGUI._themeName.assign(themePath);
|
||||||
nppParams.reloadStylers(themePath.c_str());
|
nppParams.reloadStylers(themePath.c_str());
|
||||||
|
@ -305,7 +317,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
::SendMessage(_hSelf, NPPM_INTERNAL_ENABLECHANGEHISTORY, 0, 0);
|
::SendMessage(_hSelf, NPPM_INTERNAL_ENABLECHANGEHISTORY, 0, 0);
|
||||||
|
|
||||||
// Notify plugins that Notepad++ is ready
|
// Notify plugins that Notepad++ is ready
|
||||||
SCNotification scnN;
|
SCNotification scnN{};
|
||||||
scnN.nmhdr.code = NPPN_READY;
|
scnN.nmhdr.code = NPPN_READY;
|
||||||
scnN.nmhdr.hwndFrom = _hSelf;
|
scnN.nmhdr.hwndFrom = _hSelf;
|
||||||
scnN.nmhdr.idFrom = 0;
|
scnN.nmhdr.idFrom = 0;
|
||||||
|
|
|
@ -100,8 +100,8 @@ namespace NppDarkMode
|
||||||
{
|
{
|
||||||
bool _enableWindowsMode = false;
|
bool _enableWindowsMode = false;
|
||||||
|
|
||||||
NppDarkMode::AdvOptDefaults _darkDefaults{};
|
NppDarkMode::AdvOptDefaults _darkDefaults{ L"DarkModeDefault.xml", 0, 2, false };
|
||||||
NppDarkMode::AdvOptDefaults _lightDefaults{};
|
NppDarkMode::AdvOptDefaults _lightDefaults{ L"", 4, 0, true };
|
||||||
};
|
};
|
||||||
|
|
||||||
void initDarkMode(); // pulls options from NppParameters
|
void initDarkMode(); // pulls options from NppParameters
|
||||||
|
|
|
@ -1180,7 +1180,8 @@ bool NppParameters::load()
|
||||||
//
|
//
|
||||||
// the 2nd priority: cloud Choice Path
|
// the 2nd priority: cloud Choice Path
|
||||||
//
|
//
|
||||||
if (::PathFileExists(cloudChoicePath.c_str()))
|
_isCloud = (::PathFileExists(cloudChoicePath.c_str()) == TRUE);
|
||||||
|
if (_isCloud)
|
||||||
{
|
{
|
||||||
// Read cloud choice
|
// Read cloud choice
|
||||||
std::string cloudChoiceStr = getFileContent(cloudChoicePath.c_str());
|
std::string cloudChoiceStr = getFileContent(cloudChoicePath.c_str());
|
||||||
|
@ -1193,6 +1194,10 @@ bool NppParameters::load()
|
||||||
_nppGUI._cloudPath = cloudChoiceStrW;
|
_nppGUI._cloudPath = cloudChoiceStrW;
|
||||||
_initialCloudChoice = _nppGUI._cloudPath;
|
_initialCloudChoice = _nppGUI._cloudPath;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_isCloud = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -1704,6 +1704,10 @@ public:
|
||||||
return _isLocal;
|
return _isLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isCloud() const {
|
||||||
|
return _isCloud;
|
||||||
|
}
|
||||||
|
|
||||||
void saveConfig_xml();
|
void saveConfig_xml();
|
||||||
|
|
||||||
generic_string getUserPath() const {
|
generic_string getUserPath() const {
|
||||||
|
@ -1831,6 +1835,7 @@ private:
|
||||||
WNDPROC _enableThemeDialogTextureFuncAddr = nullptr;
|
WNDPROC _enableThemeDialogTextureFuncAddr = nullptr;
|
||||||
bool _isLocal = false;
|
bool _isLocal = false;
|
||||||
bool _isx64 = false; // by default 32-bit
|
bool _isx64 = false; // by default 32-bit
|
||||||
|
bool _isCloud = false;
|
||||||
|
|
||||||
generic_string _cmdSettingsDir;
|
generic_string _cmdSettingsDir;
|
||||||
generic_string _titleBarAdditional;
|
generic_string _titleBarAdditional;
|
||||||
|
|
Loading…
Reference in New Issue