Switch to default dark theme as dark mode is enabled

1. Add default dark theme.
2. Switch to default dark theme when dark mode is enabled considering both situations:
   Style Configurator is or ont launched.

Close #9847
pull/9945/head
Don HO 2021-05-10 04:06:27 +02:00
parent db27172ca8
commit 4aa459ef47
7 changed files with 1462 additions and 11 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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<generic_string, generic_string> & 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;

View File

@ -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)
{

View File

@ -895,7 +895,7 @@ NppParameters::~NppParameters()
}
bool NppParameters::reloadStylers(TCHAR* stylePath)
bool NppParameters::reloadStylers(const TCHAR* stylePath)
{
delete _pXmlUserStylerDoc;

View File

@ -1277,7 +1277,7 @@ public:
void addDefaultThemeFromXml(const generic_string& xmlFullPath)
{
_themeList.push_back(std::pair<generic_string, generic_string>(TEXT("Default (stylers.xml)"), xmlFullPath));
_themeList.push_back(std::pair<generic_string, generic_string>(_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<std::pair<generic_string, generic_string>> _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();

View File

@ -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<LPARAM>(themeName));
if (iTheme == CB_ERR)
return false;
::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, iTheme, 0);
applyCurrentSelectedThemeAndUpdateUI();
return true;
}
void WordStyleDlg::setStyleListFromLexer(int index)
{
_currentLexerIndex = index;

View File

@ -107,6 +107,7 @@ public :
::SendMessage(_hSwitch2ThemeCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(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();
};