From cae2f77daf045408b683d194bbf1b09061edb872 Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Wed, 24 Mar 2021 11:01:09 -0400 Subject: [PATCH] Add command line parameter for adding specified string to app title bar Fix #9539, #9704 --- PowerEditor/src/Notepad_plus.cpp | 7 +++++++ PowerEditor/src/Notepad_plus_Window.h | 3 ++- PowerEditor/src/Parameters.h | 12 ++++++++++++ PowerEditor/src/winmain.cpp | 16 ++++++++++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 99e53da70..704e020c9 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3466,6 +3466,13 @@ void Notepad_plus::setTitle() if (_isAdministrator) result += TEXT(" [Administrator]"); + generic_string tbAdd = (NppParameters::getInstance()).getTitleBarAdd(); + if (!tbAdd.empty()) + { + result += TEXT(" - "); + result += tbAdd; + } + ::SendMessage(_pPublicInterface->getHSelf(), WM_SETTEXT, 0, reinterpret_cast(result.c_str())); } diff --git a/PowerEditor/src/Notepad_plus_Window.h b/PowerEditor/src/Notepad_plus_Window.h index b3c77e20b..6fce60d81 100644 --- a/PowerEditor/src/Notepad_plus_Window.h +++ b/PowerEditor/src/Notepad_plus_Window.h @@ -20,7 +20,7 @@ const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\ \r\ -notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-pPosition] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qn=\"Easter egg name\" | -qt=\"a text to display.\" | -qf=\"D:\\my quote.txt\"] [-qSpeed1|2|3] [-quickPrint] [-settingsDir=\"d:\\your settings dir\\\"] [-openFoldersAsWorkspace] [filePath]\r\ +notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-pPosition] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qn=\"Easter egg name\" | -qt=\"a text to display.\" | -qf=\"D:\\my quote.txt\"] [-qSpeed1|2|3] [-quickPrint] [-settingsDir=\"d:\\your settings dir\\\"] [-openFoldersAsWorkspace] [-titleAdd=\"additional title bar text\"][filePath]\r\ \r\ --help : This help message\r\ -multiInst : Launch another Notepad++ instance\r\ @@ -48,6 +48,7 @@ notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNum -quickPrint : Print the file given as argument then quit Notepad++\r\ -settingsDir=\"d:\\your settings dir\\\": Override the default settings dir\r\ -openFoldersAsWorkspace: open filePath of folder(s) as workspace\r\ +-titleAdd=\"string\": add string to Notepad++ title bar\r\ filePath : file or folder name to open (absolute or relative path name)\r\ "); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index e06bcd92e..d0148809d 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1676,6 +1676,16 @@ public: _cmdSettingsDir = settingsDir; }; + void setTitleBarAdd(const generic_string& titleAdd) + { + _titleBarAdditional = titleAdd; + } + + const generic_string& getTitleBarAdd() const + { + return _titleBarAdditional; + } + DPIManager _dpiManager; generic_string static getSpecialFolderLocation(int folderKind); @@ -1756,6 +1766,8 @@ private: generic_string _cmdSettingsDir; + generic_string _titleBarAdditional; + public: void setShortcutDirty() { _isAnyShortcutModified = true; }; void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; } diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 1c6d1b5af..ee7ac7530 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -308,6 +308,7 @@ const TCHAR FLAG_PRINTANDQUIT[] = TEXT("-quickPrint"); const TCHAR FLAG_NOTEPAD_COMPATIBILITY[] = TEXT("-notepadStyleCmdline"); const TCHAR FLAG_OPEN_FOLDERS_AS_WORKSPACE[] = TEXT("-openFoldersAsWorkspace"); const TCHAR FLAG_SETTINGS_DIR[] = TEXT("-settingsDir="); +const TCHAR FLAG_TITLEBAR_ADD[] = TEXT("-titleAdd="); void doException(Notepad_plus_Window & notepad_plus_plus) { @@ -467,11 +468,22 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int) nppParameters.setCmdSettingsDir(path); } + generic_string titleBarAdditional; + if (getParamValFromString(FLAG_TITLEBAR_ADD, params, titleBarAdditional)) + { + if (titleBarAdditional.length() >= 2) + { + if (titleBarAdditional.front() == '"' && titleBarAdditional.back() == '"') + { + titleBarAdditional = titleBarAdditional.substr(1, titleBarAdditional.length() - 2); + } + } + nppParameters.setTitleBarAdd(titleBarAdditional); + } + if (showHelp) ::MessageBox(NULL, COMMAND_ARG_HELP, TEXT("Notepad++ Command Argument Help"), MB_OK); - - if (cmdLineParams._localizationPath != TEXT("")) { // setStartWithLocFileName() should be called before parameters are loaded