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
This commit is contained in:
Don Ho 2021-08-06 22:59:40 +02:00
parent a36a12257a
commit 4cc3d9fd1a
6 changed files with 120 additions and 9 deletions

View File

@ -0,0 +1,76 @@
<!--//
Markdown-plus-plus is a project to support Markdown syntax in Notepad++.
All UDLs are carefully designed by human, rather than generated by machine.
Want an UDL for different theme?
Want to change its preference?
Want to create your own?
Go get it: https://github.com/Edditoria/markdown-plus-plus
Please read the README file for details.
Welcome issues and pull requests via the above link.
Copyright (c) Edditoria. Open source under the MIT license:
https://github.com/Edditoria/markdown-plus-plus/blob/master/LICENSE.txt
//-->
<NotepadPlus>
<UserLang name="Markdown (preinstalled dark mode)" ext="md markdown" darkModeTheme="yes" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="2" decimalSeparator="0" />
<Prefix Keywords1="yes" Keywords2="yes" Keywords3="yes" Keywords4="yes" Keywords5="yes" Keywords6="yes" Keywords7="yes" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00# 01 02((EOL)) 03&lt;!-- 04--&gt;</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1">.</Keywords>
<Keywords name="Numbers, suffix2">.</Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">@ &lt; &gt; \&lt; \&gt; \\ \` \* \_ \{ \} \[ \] \( \) \# \+ \- \. \! \~ \| |:-: |:--: |:---: | :-: :--: :---: :|: |: :|</Keywords>
<Keywords name="Operators2">- + :- :-- :--- :</Keywords>
<Keywords name="Folders in code1, open"></Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close"></Keywords>
<Keywords name="Folders in code2, open"></Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close"></Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">../ (../ http:// (http:// https:// (https:// mailto: (mailto: ftp:// (ftp:// ftps:// (ftps:// (/ /</Keywords>
<Keywords name="Keywords2">==== ----</Keywords>
<Keywords name="Keywords3">*** ___</Keywords>
<Keywords name="Keywords4">** __</Keywords>
<Keywords name="Keywords5">* _</Keywords>
<Keywords name="Keywords6">** __</Keywords>
<Keywords name="Keywords7">* _</Keywords>
<Keywords name="Keywords8"></Keywords>
<Keywords name="Delimiters">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</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="2" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="FF8040" bgColor="3F3F3F" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="8CD0D3" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="EDD6ED" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="FF8040" bgColor="3F3F3F" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="2" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="DFC47D" bgColor="3F3F3F" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="EDD6ED" bgColor="3F3F3F" fontName="" fontStyle="2" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="CEDF99" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="1" nesting="65600" />
<WordsStyle name="DELIMITERS5" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="2" nesting="32800" />
<WordsStyle name="DELIMITERS6" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="3" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>

View File

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

View File

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

View File

@ -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\

View File

@ -1536,17 +1536,34 @@ const TCHAR* NppParameters::getUserDefinedLangNameFromExt(TCHAR *ext, TCHAR *ful
return nullptr;
std::vector<generic_string> 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<unsigned char, unsigned char> 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<unsigned char, unsigned char> 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"));

View File

@ -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];