From 1f89110b04d303ff2b22f580b2ebb61b02883b94 Mon Sep 17 00:00:00 2001 From: Don HO Date: Mon, 7 Aug 2017 00:01:12 +0200 Subject: [PATCH] Add "-quickPrint" command line argument "-quickPrint" allows user to launch Notepad++ via command to print a given document then quit Notepad++ immediately. Usage: notepad++.exe -quickPrint c:\funcListTests\EncodingMapper.cpp --- PowerEditor/src/Notepad_plus_Window.cpp | 3 +++ PowerEditor/src/Notepad_plus_Window.h | 3 ++- PowerEditor/src/NppBigSwitch.cpp | 7 +++++++ PowerEditor/src/Parameters.h | 8 ++++++++ PowerEditor/src/resource.h | 1 + PowerEditor/src/winmain.cpp | 10 +++++++--- 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 242961ca..2ba6a7cd 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -300,6 +300,9 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin if (pNppParams->doFunctionListExport()) ::SendMessage(_hSelf, NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT, 0, 0); + + if (pNppParams->doPrintAndExit()) + ::SendMessage(_hSelf, NPPM_INTERNAL_PRNTANDQUIT, 0, 0); } diff --git a/PowerEditor/src/Notepad_plus_Window.h b/PowerEditor/src/Notepad_plus_Window.h index 5aa47b0b..9866abc9 100644 --- a/PowerEditor/src/Notepad_plus_Window.h +++ b/PowerEditor/src/Notepad_plus_Window.h @@ -31,7 +31,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] [-qnEsterEggName | -qtText | -qfCntentFileName] [filePath]\r\ +notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-pPosition] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qnEsterEggName | -qtText | -qfCntentFileName] [-quickPrint] [filePath]\r\ \r\ --help : This help message\r\ -multiInst : Launch another Notepad++ instance\r\ @@ -55,6 +55,7 @@ notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNum -qn : Launch ghost typing to display easter egg via its name\r\ -qt : Launch ghost typing to display a text via the given text\r\ -qf : Launch ghost typing to display a file content via the file path\r\ + -qickPrint : Print the file given as argument then quit Notepad++\r\ filePath : file or folder name to open (absolute or relative path name)\r\ "); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 9e2ff00b..a69c397c 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -481,6 +481,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa } break; + case NPPM_INTERNAL_PRNTANDQUIT: + { + ::PostMessage(_pPublicInterface->getHSelf(), WM_COMMAND, IDM_FILE_PRINTNOW, 0); + ::PostMessage(_pPublicInterface->getHSelf(), WM_COMMAND, IDM_FILE_EXIT, 0); + } + break; + case NPPM_DISABLEAUTOUPDATE: { NppGUI & nppGUI = const_cast(pNppParam->getNppGUI()); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 7a224cbf..63dbd622 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1481,6 +1481,13 @@ public: return _doFunctionListExport; }; + void setPrintAndExitBoolean(bool doIt) { + _doPrintAndExit = doIt; + }; + bool doPrintAndExit() const { + return _doPrintAndExit; + }; + bool loadSession(Session & session, const TCHAR *sessionFileName); int langTypeToCommandID(LangType lt) const; WNDPROC getEnableThemeDlgTexture() const {return _enableThemeDialogTextureFuncAddr;}; @@ -1666,6 +1673,7 @@ private: LocalizationSwitcher _localizationSwitcher; generic_string _startWithLocFileName; bool _doFunctionListExport = false; + bool _doPrintAndExit = false; ThemeSwitcher _themeSwitcher; diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 231db02f..c9df1676 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -418,6 +418,7 @@ #define NPPM_INTERNAL_SCROLLBEYONDLASTLINE (NOTEPADPLUS_USER_INTERNAL + 44) #define NPPM_INTERNAL_SETWORDCHARS (NOTEPADPLUS_USER_INTERNAL + 45) #define NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT (NOTEPADPLUS_USER_INTERNAL + 46) + #define NPPM_INTERNAL_PRNTANDQUIT (NOTEPADPLUS_USER_INTERNAL + 47) //wParam: 0 //lParam: document new index diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index e9a60552..cd02bb63 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -307,7 +307,7 @@ const TCHAR FLAG_ALWAYS_ON_TOP[] = TEXT("-alwaysOnTop"); const TCHAR FLAG_OPENSESSIONFILE[] = TEXT("-openSession"); const TCHAR FLAG_RECURSIVE[] = TEXT("-r"); const TCHAR FLAG_FUNCLSTEXPORT[] = TEXT("-export=functionList"); - +const TCHAR FLAG_PRINTANDQUIT[] = TEXT("-quickPrint"); void doException(Notepad_plus_Window & notepad_plus_plus) @@ -355,6 +355,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) bool showHelp = isInList(FLAG_HELP, params); bool isMultiInst = isInList(FLAG_MULTI_INSTANCE, params); bool doFunctionListExport = isInList(FLAG_FUNCLSTEXPORT, params); + bool doPrintAndQuit = isInList(FLAG_PRINTANDQUIT, params); CmdLineParams cmdLineParams; cmdLineParams._isNoTab = isInList(FLAG_NOTABBAR, params); @@ -368,12 +369,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) cmdLineParams._isRecursive = isInList(FLAG_RECURSIVE, params); cmdLineParams._langType = getLangTypeFromParam(params); cmdLineParams._localizationPath = getLocalizationPathFromParam(params); + cmdLineParams._easterEggName = getEasterEggNameFromParam(params, cmdLineParams._quoteType); + + // getNumberFromParam should be run at the end, to not consuming the other params cmdLineParams._line2go = getNumberFromParam('n', params, isParamePresent); cmdLineParams._column2go = getNumberFromParam('c', params, isParamePresent); cmdLineParams._pos2go = getNumberFromParam('p', params, isParamePresent); cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid); cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid); - cmdLineParams._easterEggName = getEasterEggNameFromParam(params, cmdLineParams._quoteType); if (showHelp) @@ -383,7 +386,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) NppGUI & nppGui = const_cast(pNppParameters->getNppGUI()); bool doUpdate = nppGui._autoUpdateOpt._doAutoUpdate; - if (doFunctionListExport) // export functionlist feature will serialize fuctionlist on the disk, then exit Notepad++. So it's important to not launch into existing instance, and keep it silent. + if (doFunctionListExport || doPrintAndQuit) // export functionlist feature will serialize fuctionlist on the disk, then exit Notepad++. So it's important to not launch into existing instance, and keep it silent. { isMultiInst = true; doUpdate = false; @@ -397,6 +400,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) pNppParameters->load(); pNppParameters->setFunctionListExportBoolean(doFunctionListExport); + pNppParameters->setPrintAndExitBoolean(doPrintAndQuit); // override the settings if notepad style is present if (pNppParameters->asNotepadStyle())