From 4cc3d9fd1a5d4eeb7be093729a8885d3f049b622 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 6 Aug 2021 22:59:40 +0200 Subject: [PATCH] Add Markdown UDL of dark mode in release packages Add Markdown UDL of dark mode and the ability to apply it: After dark mode being swiched in, all files with extension .md will be opened by applying Markdown UDL of dark mode. When light mode is switched back, the default Markdown UDL (of light mode) will be applied to the new opened .md file. Please note that all .md files opened before switching to new mode, will remain in the previous mode. User has to close and reopen these files to have the right Markdown UDL applied. Fix #10196, close #10347 --- .../markdown._preinstalled_DM.udl.xml | 76 +++++++++++++++++++ .../nsisInclude/mainSectionFuncs.nsh | 1 + .../installer/nsisInclude/uninstall.nsh | 2 + PowerEditor/installer/packageAll.bat | 6 ++ PowerEditor/src/Parameters.cpp | 39 ++++++++-- PowerEditor/src/Parameters.h | 5 +- 6 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 PowerEditor/bin/userDefineLangs/markdown._preinstalled_DM.udl.xml diff --git a/PowerEditor/bin/userDefineLangs/markdown._preinstalled_DM.udl.xml b/PowerEditor/bin/userDefineLangs/markdown._preinstalled_DM.udl.xml new file mode 100644 index 000000000..5a6bcff8d --- /dev/null +++ b/PowerEditor/bin/userDefineLangs/markdown._preinstalled_DM.udl.xml @@ -0,0 +1,76 @@ + + + + + + + + + 00# 01 02((EOL)) 03<!-- 04--> + + + + + . + . + + @ < > \< \> \\ \` \* \_ \{ \} \[ \] \( \) \# \+ \- \. \! \~ \| |:-: |:--: |:---: | :-: :--: :---: :|: |: :| + - + :- :-- :--- : + + + + + + + + + + ../ (../ http:// (http:// https:// (https:// mailto: (mailto: ftp:// (ftp:// ftps:// (ftps:// (/ / + ==== ---- + *** ___ + ** __ + * _ + ** __ + * _ + + 00![ 00[ 01\ 02] 02] 03``` 03` 03~~~ 04\ 05``` 05((EOL `)) 05~~~ 06*** 07\ 08((EOL ***)) 09** 10\ 11((EOL **)) 12* 13\ 14((EOL *)) 15** 16\ 17((EOL **)) 18* 19\ 20((EOL *)) 21 22 23 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh b/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh index e7563ddd6..7a0450134 100644 --- a/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh +++ b/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh @@ -104,6 +104,7 @@ Function copyCommonFiles SetOutPath "$UPDATE_PATH\userDefineLangs\" Delete "$UPDATE_PATH\userDefineLangs\userDefinedLang-markdown.default.modern.xml" File "..\bin\userDefineLangs\markdown._preinstalled.udl.xml" + File "..\bin\userDefineLangs\markdown._preinstalled_DM.udl.xml" ; Localization ; Default language English diff --git a/PowerEditor/installer/nsisInclude/uninstall.nsh b/PowerEditor/installer/nsisInclude/uninstall.nsh index b795116bb..00e91f16a 100644 --- a/PowerEditor/installer/nsisInclude/uninstall.nsh +++ b/PowerEditor/installer/nsisInclude/uninstall.nsh @@ -244,6 +244,7 @@ Section Uninstall Delete "$INSTDIR\userDefinedLang-markdown.default.modern.xml" Delete "$INSTDIR\userDefineLangs\userDefinedLang-markdown.default.modern.xml" Delete "$INSTDIR\userDefineLangs\markdown._preinstalled.udl.xml" + Delete "$INSTDIR\userDefineLangs\markdown._preinstalled_DM.udl.xml" Delete "$INSTDIR\doLocalConf.xml" Delete "$INSTDIR\uninstall.ini" @@ -266,6 +267,7 @@ Section Uninstall Delete "$APPDATA\${APPNAME}\insertExt.ini" Delete "$APPDATA\${APPNAME}\userDefineLangs\userDefinedLang-markdown.default.modern.xml" Delete "$APPDATA\${APPNAME}\userDefineLangs\markdown._preinstalled.udl.xml" + Delete "$APPDATA\${APPNAME}\userDefineLangs\markdown._preinstalled_DM.udl.xml" RMDir /r "$APPDATA\${APPNAME}\plugins\" RMDir /r "$APPDATA\${APPNAME}\backup\" ; Remove backup folder recursively if not empty RMDir "$APPDATA\${APPNAME}\themes\" ; has no effect as not empty at this moment, but it is taken care at un.onUninstSuccess diff --git a/PowerEditor/installer/packageAll.bat b/PowerEditor/installer/packageAll.bat index d7d796c9e..442c3c43a 100644 --- a/PowerEditor/installer/packageAll.bat +++ b/PowerEditor/installer/packageAll.bat @@ -345,6 +345,12 @@ copy /Y "..\bin\userDefineLangs\markdown._preinstalled.udl.xml" .\zipped.package If ErrorLevel 1 goto End copy /Y "..\bin\userDefineLangs\markdown._preinstalled.udl.xml" .\zipped.package.releaseArm64\userDefineLangs\ If ErrorLevel 1 goto End +copy /Y "..\bin\userDefineLangs\markdown._preinstalled_DM.udl.xml" .\zipped.package.release\userDefineLangs\ +If ErrorLevel 1 goto End +copy /Y "..\bin\userDefineLangs\markdown._preinstalled_DM.udl.xml" .\zipped.package.release64\userDefineLangs\ +If ErrorLevel 1 goto End +copy /Y "..\bin\userDefineLangs\markdown._preinstalled_DM.udl.xml" .\zipped.package.releaseArm64\userDefineLangs\ +If ErrorLevel 1 goto End rem theme: Copy all files into Notepad++ 32-bit/64-bit package folders copy /Y ".\themes\*.xml" .\zipped.package.release\themes\ diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index ca05d5db2..fb3a13ddd 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1536,17 +1536,34 @@ const TCHAR* NppParameters::getUserDefinedLangNameFromExt(TCHAR *ext, TCHAR *ful return nullptr; std::vector extVect; + int iMatched = -1; for (int i = 0 ; i < _nbUserLang ; ++i) { extVect.clear(); cutString(_userLangArray[i]->_ext.c_str(), extVect); + // Force to use dark mode UDL in dark mode or to use light mode UDL in light mode for (size_t j = 0, len = extVect.size(); j < len; ++j) { if (!generic_stricmp(extVect[j].c_str(), ext) || (_tcschr(fullName, '.') && !generic_stricmp(extVect[j].c_str(), fullName))) - return _userLangArray[i]->_name.c_str(); + { + // preserve ext matched UDL + iMatched = i; + + if (((NppDarkMode::isEnabled() && _userLangArray[i]->_isDarkModeTheme)) || + ((!NppDarkMode::isEnabled() && !_userLangArray[i]->_isDarkModeTheme))) + return _userLangArray[i]->_name.c_str(); + } } } + + // In case that we are in dark mode but no dark UDL or we are in light mode but no light UDL + // We use it anyway + if (iMatched >= 0) + { + return _userLangArray[iMatched]->_name.c_str(); + } + return nullptr; } @@ -2715,9 +2732,10 @@ std::pair NppParameters::feedUserLang(TiXmlNode *n childNode && (_nbUserLang < NB_MAX_USER_LANG); childNode = childNode->NextSibling(TEXT("UserLang")) ) { - const TCHAR *name = (childNode->ToElement())->Attribute(TEXT("name")); - const TCHAR *ext = (childNode->ToElement())->Attribute(TEXT("ext")); - const TCHAR *udlVersion = (childNode->ToElement())->Attribute(TEXT("udlVersion")); + const TCHAR* name = (childNode->ToElement())->Attribute(TEXT("name")); + const TCHAR* ext = (childNode->ToElement())->Attribute(TEXT("ext")); + const TCHAR* darkModeTheme = (childNode->ToElement())->Attribute(TEXT("darkModeTheme")); + const TCHAR* udlVersion = (childNode->ToElement())->Attribute(TEXT("udlVersion")); if (!name || !name[0] || !ext) { @@ -2725,11 +2743,16 @@ std::pair NppParameters::feedUserLang(TiXmlNode *n continue; } + bool isDarkModeTheme = false; + + if (darkModeTheme && darkModeTheme[0]) + { + isDarkModeTheme = (lstrcmp(TEXT("yes"), darkModeTheme) == 0); + } + try { - if (!udlVersion) - _userLangArray[_nbUserLang] = new UserLangContainer(name, ext, TEXT("")); - else - _userLangArray[_nbUserLang] = new UserLangContainer(name, ext, udlVersion); + _userLangArray[_nbUserLang] = new UserLangContainer(name, ext, isDarkModeTheme, udlVersion ? udlVersion : TEXT("")); + ++_nbUserLang; TiXmlNode *settingsRoot = childNode->FirstChildElement(TEXT("Settings")); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 4d909f35f..0ae730013 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1083,7 +1083,8 @@ public: init(); } - UserLangContainer(const TCHAR *name, const TCHAR *ext, const TCHAR *udlVer) : _name(name), _ext(ext), _udlVersion(udlVer) + UserLangContainer(const TCHAR *name, const TCHAR *ext, bool isDarkModeTheme, const TCHAR *udlVer): + _name(name), _ext(ext), _isDarkModeTheme(isDarkModeTheme), _udlVersion(udlVer) { init(); } @@ -1094,6 +1095,7 @@ public: { this->_name = ulc._name; this->_ext = ulc._ext; + this->_isDarkModeTheme = ulc._isDarkModeTheme; this->_udlVersion = ulc._udlVersion; this->_isCaseIgnored = ulc._isCaseIgnored; this->_styleArray = ulc._styleArray; @@ -1129,6 +1131,7 @@ private: generic_string _name; generic_string _ext; generic_string _udlVersion; + bool _isDarkModeTheme = false; TCHAR _keywordLists[SCE_USER_KWLIST_TOTAL][max_char]; bool _isPrefix[SCE_USER_TOTAL_KEYWORD_GROUPS];