Add command line parameter for adding specified string to app title bar

Fix #9539, #9704
This commit is contained in:
Scott Sumner 2021-03-24 11:01:09 -04:00 committed by Don HO
parent bdae2aef92
commit cae2f77daf
4 changed files with 35 additions and 3 deletions

View File

@ -3466,6 +3466,13 @@ void Notepad_plus::setTitle()
if (_isAdministrator) if (_isAdministrator)
result += TEXT(" [Administrator]"); result += TEXT(" [Administrator]");
generic_string tbAdd = (NppParameters::getInstance()).getTitleBarAdd();
if (!tbAdd.empty())
{
result += TEXT(" - ");
result += tbAdd;
}
::SendMessage(_pPublicInterface->getHSelf(), WM_SETTEXT, 0, reinterpret_cast<LPARAM>(result.c_str())); ::SendMessage(_pPublicInterface->getHSelf(), WM_SETTEXT, 0, reinterpret_cast<LPARAM>(result.c_str()));
} }

View File

@ -20,7 +20,7 @@
const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\ const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\
\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\ \r\
--help : This help message\r\ --help : This help message\r\
-multiInst : Launch another Notepad++ instance\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\ -quickPrint : Print the file given as argument then quit Notepad++\r\
-settingsDir=\"d:\\your settings dir\\\": Override the default settings dir\r\ -settingsDir=\"d:\\your settings dir\\\": Override the default settings dir\r\
-openFoldersAsWorkspace: open filePath of folder(s) as workspace\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\ filePath : file or folder name to open (absolute or relative path name)\r\
"); ");

View File

@ -1676,6 +1676,16 @@ public:
_cmdSettingsDir = settingsDir; _cmdSettingsDir = settingsDir;
}; };
void setTitleBarAdd(const generic_string& titleAdd)
{
_titleBarAdditional = titleAdd;
}
const generic_string& getTitleBarAdd() const
{
return _titleBarAdditional;
}
DPIManager _dpiManager; DPIManager _dpiManager;
generic_string static getSpecialFolderLocation(int folderKind); generic_string static getSpecialFolderLocation(int folderKind);
@ -1756,6 +1766,8 @@ private:
generic_string _cmdSettingsDir; generic_string _cmdSettingsDir;
generic_string _titleBarAdditional;
public: public:
void setShortcutDirty() { _isAnyShortcutModified = true; }; void setShortcutDirty() { _isAnyShortcutModified = true; };
void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; } void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; }

View File

@ -308,6 +308,7 @@ const TCHAR FLAG_PRINTANDQUIT[] = TEXT("-quickPrint");
const TCHAR FLAG_NOTEPAD_COMPATIBILITY[] = TEXT("-notepadStyleCmdline"); const TCHAR FLAG_NOTEPAD_COMPATIBILITY[] = TEXT("-notepadStyleCmdline");
const TCHAR FLAG_OPEN_FOLDERS_AS_WORKSPACE[] = TEXT("-openFoldersAsWorkspace"); const TCHAR FLAG_OPEN_FOLDERS_AS_WORKSPACE[] = TEXT("-openFoldersAsWorkspace");
const TCHAR FLAG_SETTINGS_DIR[] = TEXT("-settingsDir="); const TCHAR FLAG_SETTINGS_DIR[] = TEXT("-settingsDir=");
const TCHAR FLAG_TITLEBAR_ADD[] = TEXT("-titleAdd=");
void doException(Notepad_plus_Window & notepad_plus_plus) void doException(Notepad_plus_Window & notepad_plus_plus)
{ {
@ -467,11 +468,22 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int)
nppParameters.setCmdSettingsDir(path); 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) if (showHelp)
::MessageBox(NULL, COMMAND_ARG_HELP, TEXT("Notepad++ Command Argument Help"), MB_OK); ::MessageBox(NULL, COMMAND_ARG_HELP, TEXT("Notepad++ Command Argument Help"), MB_OK);
if (cmdLineParams._localizationPath != TEXT("")) if (cmdLineParams._localizationPath != TEXT(""))
{ {
// setStartWithLocFileName() should be called before parameters are loaded // setStartWithLocFileName() should be called before parameters are loaded