diff --git a/PowerEditor/gcc/makefile b/PowerEditor/gcc/makefile index 5a976190a..cc9ef1e3f 100644 --- a/PowerEditor/gcc/makefile +++ b/PowerEditor/gcc/makefile @@ -26,7 +26,7 @@ BIN_DIRECTORY := ../bin INSTALLER_DIRECTORY := ../installer TARGET_BINARY := notepad++.exe -SRC_DATA := contextMenu.xml langs.model.xml shortcuts.xml stylers.model.xml tabContextMenu_example.xml toolbarIcons.xml +SRC_DATA := contextMenu.xml langs.model.xml shortcuts.xml stylers.model.xml tabContextMenu_example.xml toolbarButtonsConf_example.xml toolbarIcons.xml BIN_DATA := change.log doLocalConf.xml nppLogNulContentCorruptionIssue.xml readme.txt userDefineLangs/ INSTALLER_DATA := autoCompletion/ functionList/ localization/ themes/ diff --git a/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh b/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh index d85877d8b..999a7d770 100644 --- a/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh +++ b/PowerEditor/installer/nsisInclude/mainSectionFuncs.nsh @@ -75,6 +75,7 @@ Function copyCommonFiles SetOutPath "$UPDATE_PATH\" File "..\bin\contextMenu.xml" File "..\src\tabContextMenu_example.xml" + File "..\src\toolbarButtonsConf_example.xml" File "..\src\toolbarIcons.xml" SetOverwrite on diff --git a/PowerEditor/installer/nsisInclude/uninstall.nsh b/PowerEditor/installer/nsisInclude/uninstall.nsh index 95468bab4..ee1f5dc72 100644 --- a/PowerEditor/installer/nsisInclude/uninstall.nsh +++ b/PowerEditor/installer/nsisInclude/uninstall.nsh @@ -243,6 +243,7 @@ Section Uninstall Delete "$INSTDIR\langs.model.xml" Delete "$INSTDIR\stylers.model.xml" Delete "$INSTDIR\tabContextMenu_example.xml" + Delete "$INSTDIR\toolbarButtonsConf_example.xml" Delete "$INSTDIR\stylers_remove.xml" Delete "$INSTDIR\localization\english.xml" Delete "$INSTDIR\LINEDRAW.TTF" @@ -277,6 +278,7 @@ Section Uninstall Delete "$APPDATA\${APPNAME}\insertExt.ini" Delete "$APPDATA\${APPNAME}\nppLogNulContentCorruptionIssue.log" Delete "$APPDATA\${APPNAME}\tabContextMenu_example.xml" + Delete "$APPDATA\${APPNAME}\toolbarButtonsConf_example.xml" Delete "$APPDATA\${APPNAME}\toolbarIcons.xml" Delete "$APPDATA\${APPNAME}\userDefineLangs\userDefinedLang-markdown.default.modern.xml" Delete "$APPDATA\${APPNAME}\userDefineLangs\markdown._preinstalled.udl.xml" diff --git a/PowerEditor/installer/packageAll.bat b/PowerEditor/installer/packageAll.bat index a0d9d5a82..8a18c4ef7 100644 --- a/PowerEditor/installer/packageAll.bat +++ b/PowerEditor/installer/packageAll.bat @@ -111,6 +111,8 @@ copy /Y ..\src\contextMenu.xml .\minimalist\ If ErrorLevel 1 goto End copy /Y ..\src\tabContextMenu_example.xml .\minimalist\ If ErrorLevel 1 goto End +copy /Y ..\src\toolbarButtonsConf_example.xml .\minimalist\ +If ErrorLevel 1 goto End copy /Y ..\src\shortcuts.xml .\minimalist\ If ErrorLevel 1 goto End copy /Y ..\bin\doLocalConf.xml .\minimalist\ @@ -146,6 +148,8 @@ copy /Y ..\src\contextMenu.xml .\minimalist64\ If ErrorLevel 1 goto End copy /Y ..\src\tabContextMenu_example.xml .\minimalist64\ If ErrorLevel 1 goto End +copy /Y ..\src\toolbarButtonsConf_example.xml .\minimalist64\ +If ErrorLevel 1 goto End copy /Y ..\src\shortcuts.xml .\minimalist64\ If ErrorLevel 1 goto End copy /Y ..\bin\doLocalConf.xml .\minimalist64\ @@ -181,6 +185,8 @@ copy /Y ..\src\contextMenu.xml .\minimalistArm64\ If ErrorLevel 1 goto End copy /Y ..\src\tabContextMenu_example.xml .\minimalistArm64\ If ErrorLevel 1 goto End +copy /Y ..\src\toolbarButtonsConf_example.xml .\minimalistArm64\ +If ErrorLevel 1 goto End copy /Y ..\src\shortcuts.xml .\minimalistArm64\ If ErrorLevel 1 goto End copy /Y ..\bin\doLocalConf.xml .\minimalistArm64\ @@ -267,6 +273,8 @@ copy /Y ..\src\contextMenu.xml .\zipped.package.release\ If ErrorLevel 1 goto End copy /Y ..\src\tabContextMenu_example.xml .\zipped.package.release\ If ErrorLevel 1 goto End +copy /Y ..\src\toolbarButtonsConf_example.xml .\zipped.package.release\ +If ErrorLevel 1 goto End copy /Y ..\src\shortcuts.xml .\zipped.package.release\ If ErrorLevel 1 goto End copy /Y ..\bin\doLocalConf.xml .\zipped.package.release\ @@ -295,6 +303,8 @@ copy /Y ..\src\contextMenu.xml .\zipped.package.release64\ If ErrorLevel 1 goto End copy /Y ..\src\tabContextMenu_example.xml .\zipped.package.release64\ If ErrorLevel 1 goto End +copy /Y ..\src\toolbarButtonsConf_example.xml .\zipped.package.release64\ +If ErrorLevel 1 goto End copy /Y ..\src\shortcuts.xml .\zipped.package.release64\ If ErrorLevel 1 goto End copy /Y ..\bin\doLocalConf.xml .\zipped.package.release64\ @@ -322,6 +332,8 @@ copy /Y ..\src\contextMenu.xml .\zipped.package.releaseArm64\ If ErrorLevel 1 goto End copy /Y ..\src\tabContextMenu_example.xml .\zipped.package.releaseArm64\ If ErrorLevel 1 goto End +copy /Y ..\src\toolbarButtonsConf_example.xml .\zipped.package.releaseArm64\ +If ErrorLevel 1 goto End copy /Y ..\src\shortcuts.xml .\zipped.package.releaseArm64\ If ErrorLevel 1 goto End copy /Y ..\bin\doLocalConf.xml .\zipped.package.releaseArm64\ diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index cdb04a73e..d92692ca0 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -150,11 +150,17 @@ Notepad_plus::Notepad_plus() nppParam.setNativeLangSpeaker(&_nativeLangSpeaker); TiXmlDocument *toolIconsDocRoot = nppParam.getCustomizedToolIcons(); + TiXmlDocument *toolButtonsDocRoot = nppParam.getCustomizedToolButtons(); if (toolIconsDocRoot) { - _toolBar.initTheme(toolIconsDocRoot); - } + _toolBar.initTheme(toolIconsDocRoot); + } + + if (toolButtonsDocRoot) + { + _toolBar.initHideButtonsConf(toolButtonsDocRoot, toolBarIcons, sizeof(toolBarIcons) / sizeof(ToolBarButtonUnit)); + } // Determine if user is administrator. BOOL is_admin; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 8aae667a2..64ce26772 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1498,6 +1498,21 @@ bool NppParameters::load() isAllLoaded = false; } + //---------------------------------------// + // toolbarButtonsConf.xml : for per user // + //---------------------------------------// + std::wstring toolbarButtonsConfXmlPath(_userPath); + pathAppend(toolbarButtonsConfXmlPath, L"toolbarButtonsConf.xml"); + + _pXmlToolButtonsConfDoc = new TiXmlDocument(toolbarButtonsConfXmlPath); + loadOkay = _pXmlToolButtonsConfDoc->LoadFile(); + if (!loadOkay) + { + delete _pXmlToolButtonsConfDoc; + _pXmlToolButtonsConfDoc = nullptr; + isAllLoaded = false; + } + //------------------------------// // shortcuts.xml : for per user // //------------------------------// @@ -1724,6 +1739,7 @@ void NppParameters::destroyInstance() delete _pXmlNativeLangDocA; delete _pXmlToolIconsDoc; + delete _pXmlToolButtonsConfDoc; delete _pXmlShortcutDocA; delete _pXmlContextMenuDocA; delete _pXmlTabContextMenuDocA; diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 9fb8a3f2b..89a2a90f1 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1630,7 +1630,8 @@ public: TiXmlDocumentA * getNativeLangA() const {return _pXmlNativeLangDocA;}; - TiXmlDocument * getCustomizedToolIcons() const {return _pXmlToolIconsDoc;}; + TiXmlDocument* getCustomizedToolIcons() const {return _pXmlToolIconsDoc;}; + TiXmlDocument* getCustomizedToolButtons() const {return _pXmlToolButtonsConfDoc;}; bool isTransparentAvailable() const { return (_winVersion >= WV_VISTA); @@ -1875,6 +1876,7 @@ private: TiXmlDocument *_pXmlUserLangDoc = nullptr; // userDefineLang.xml std::vector _pXmlUserLangsDoc; // userDefineLang customized XMLs TiXmlDocument *_pXmlToolIconsDoc = nullptr; // toolbarIcons.xml + TiXmlDocument * _pXmlToolButtonsConfDoc = nullptr; // toolbarButtonsConf.xml TiXmlDocumentA *_pXmlShortcutDocA = nullptr; // shortcuts.xml diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index 738c39a11..781f3d027 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -67,6 +67,81 @@ ToolbarIconIdUnit toolbarIconIDs[] = { { L"save-macro", true } }; +void ToolBar::initHideButtonsConf(TiXmlDocument* toolButtonsDocRoot, ToolBarButtonUnit* buttonUnitArray, int arraySize) +{ + TiXmlNode* toolButtons = toolButtonsDocRoot->FirstChild(L"NotepadPlus"); + if (toolButtons) + { + toolButtons = toolButtons->FirstChild(L"ToolbarButtons"); + if (toolButtons) + { + // Standard toolbar button + TiXmlNode* standardToolButtons = toolButtons->FirstChild(L"Standard"); + if (standardToolButtons) + { + _toolbarStdButtonsConfArray = new bool[arraySize]; + + TiXmlElement* stdBtnElement = standardToolButtons->ToElement(); + const wchar_t* isHideAll = stdBtnElement->Attribute(L"hideAll"); + if (isHideAll && (lstrcmp(isHideAll, L"yes") == 0)) + { + for (int i = 0; i < arraySize; ++i) + _toolbarStdButtonsConfArray[i] = false; + return; + } + + for (int i = 0; i < arraySize; ++i) + _toolbarStdButtonsConfArray[i] = true; + + for (TiXmlNode* childNode = standardToolButtons->FirstChildElement(L"Button"); + childNode; + childNode = childNode->NextSibling(L"Button")) + { + TiXmlElement* element = childNode->ToElement(); + int cmdID =0; + const wchar_t* cmdIDStr = element->Attribute(L"id", &cmdID); + + int index = 0; + const wchar_t* orderStr = element->Attribute(L"index", &index); + + const wchar_t* isHide = element->Attribute(L"hide"); + + if (cmdIDStr && orderStr && isHide && (lstrcmp(isHide, L"yes") == 0)) + { + if (index < arraySize && buttonUnitArray[index]._cmdID == cmdID) + _toolbarStdButtonsConfArray[index] = false; + } + } + } + + // Plugin toolbar button + TiXmlNode* pluginToolButtons = toolButtons->FirstChild(L"Plugin"); + if (pluginToolButtons) + { + TiXmlElement* pluginBtnElement = pluginToolButtons->ToElement(); + const wchar_t* isHideAll = pluginBtnElement->Attribute(L"hideAll"); + if (isHideAll && (lstrcmp(isHideAll, L"yes") == 0)) + { + _toolbarPluginButtonsConf._isHideAll = true; + return; + } + + for (TiXmlNode* childNode = pluginToolButtons->FirstChildElement(L"Button"); + childNode; + childNode = childNode->NextSibling(L"Button")) + { + bool doShow = true; + TiXmlElement* element = childNode->ToElement(); + const wchar_t* isHide = element->Attribute(L"hide"); + + doShow = !(isHide && (lstrcmp(isHide, L"yes") == 0)); + _toolbarPluginButtonsConf._showPluginButtonsArray.push_back(doShow); + } + } + } + } +} + void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot) { _toolIcons = toolIconsDocRoot->FirstChild(L"NotepadPlus"); @@ -122,7 +197,7 @@ void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot) } } -bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBarButtonUnit *buttonUnitArray, int arraySize) +bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBarButtonUnit* buttonUnitArray, int arraySize) { Window::init(hInst, hPere); @@ -141,7 +216,7 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBar InitCommonControlsEx(&icex); //Create the list of buttons - _nbButtons = arraySize; + _nbButtons = arraySize; _nbDynButtons = _vDynBtnReg.size(); _nbTotalButtons = _nbButtons + (_nbDynButtons ? _nbDynButtons + 1 : 0); _pTBB = new TBBUTTON[_nbTotalButtons]; //add one for the extra separator @@ -150,6 +225,7 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBar int bmpIndex = -1; BYTE style = 0; size_t i = 0; + for (; i < _nbButtons && i < _nbTotalButtons; ++i) { cmd = buttonUnitArray[i]._cmdID; @@ -158,38 +234,42 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBar case 0: { style = BTNS_SEP; - break; } + break; case IDM_VIEW_ALL_CHARACTERS: { ++bmpIndex; style = BTNS_DROPDOWN; - break; } + break; default: { ++bmpIndex; style = BTNS_BUTTON; - break; } } _pTBB[i].iBitmap = (cmd != 0 ? bmpIndex : 0); _pTBB[i].idCommand = cmd; - _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsState = TBSTATE_ENABLED | (_toolbarStdButtonsConfArray ? (_toolbarStdButtonsConfArray[i] ? 0 : TBSTATE_HIDDEN) : 0); _pTBB[i].fsStyle = style; _pTBB[i].dwData = 0; _pTBB[i].iString = 0; } + bool doHideAllPluginButtons = _toolbarPluginButtonsConf._isHideAll; + size_t nbPluginButtonsConf = _toolbarPluginButtonsConf._showPluginButtonsArray.size(); + if (_nbDynButtons > 0 && i < _nbTotalButtons) { + unsigned char addedStateFlag = doHideAllPluginButtons ? TBSTATE_HIDDEN : (nbPluginButtonsConf > 0 ? (_toolbarPluginButtonsConf._showPluginButtonsArray[0] ? 0 : TBSTATE_HIDDEN) : 0); + //add separator _pTBB[i].iBitmap = 0; _pTBB[i].idCommand = 0; - _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsState = TBSTATE_ENABLED | addedStateFlag; _pTBB[i].fsStyle = BTNS_SEP; _pTBB[i].dwData = 0; _pTBB[i].iString = 0; @@ -201,9 +281,11 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBar cmd = _vDynBtnReg[j]._message; ++bmpIndex; + addedStateFlag = doHideAllPluginButtons ? TBSTATE_HIDDEN : (nbPluginButtonsConf > j + 1 ? (_toolbarPluginButtonsConf._showPluginButtonsArray[j + 1] ? 0 : TBSTATE_HIDDEN) : 0); + _pTBB[i].iBitmap = bmpIndex; _pTBB[i].idCommand = cmd; - _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsState = TBSTATE_ENABLED | addedStateFlag; _pTBB[i].fsStyle = BTNS_BUTTON; _pTBB[i].dwData = 0; _pTBB[i].iString = 0; diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.h b/PowerEditor/src/WinControls/ToolBar/ToolBar.h index bd6ac0920..46bc60a44 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.h +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.h @@ -43,6 +43,12 @@ struct iconLocator { : _listIndex(iList), _iconIndex(iIcon), _iconLocation(iconLoc){}; }; +struct ToolbarPluginButtonsConf +{ + bool _isHideAll = false; + std::vector _showPluginButtonsArray; +}; + class ReBar; class TiXmlDocument; class TiXmlNode; @@ -53,9 +59,10 @@ public : ToolBar() = default; ~ToolBar() = default; - void initTheme(TiXmlDocument *toolIconsDocRoot); - virtual bool init(HINSTANCE hInst, HWND hPere, toolBarStatusType type, - ToolBarButtonUnit *buttonUnitArray, int arraySize); + void initTheme(TiXmlDocument* toolIconsDocRoot); + void initHideButtonsConf(TiXmlDocument* toolButtonsDocRoot, ToolBarButtonUnit* buttonUnitArray, int arraySize); + + virtual bool init(HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBarButtonUnit* buttonUnitArray, int arraySize); virtual void destroy(); void enable(int cmdID, bool doEnable) const { @@ -116,8 +123,10 @@ private : ReBar * _pRebar = nullptr; REBARBANDINFO _rbBand = {}; std::vector _customIconVect; + bool* _toolbarStdButtonsConfArray = nullptr; + ToolbarPluginButtonsConf _toolbarPluginButtonsConf; - TiXmlNode *_toolIcons = nullptr; + TiXmlNode* _toolIcons = nullptr; DPIManagerV2 _dpiManager; diff --git a/PowerEditor/src/toolbarButtonsConf_example.xml b/PowerEditor/src/toolbarButtonsConf_example.xml new file mode 100644 index 000000000..48821a28c --- /dev/null +++ b/PowerEditor/src/toolbarButtonsConf_example.xml @@ -0,0 +1,76 @@ + + + + + +