From 1dffb05e0ade47646add4e745ad93cd392f5a726 Mon Sep 17 00:00:00 2001 From: Ibrahim Kosgi Date: Fri, 15 Apr 2022 23:51:58 -0400 Subject: [PATCH] Add file monitoring command line argument [-monitor] Fix #10562, close #11539 --- PowerEditor/src/Notepad_plus.cpp | 14 ++++++++++++++ PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/Notepad_plus_Window.h | 3 ++- PowerEditor/src/NppCommands.cpp | 5 +---- PowerEditor/src/Parameters.h | 3 +++ PowerEditor/src/winmain.cpp | 2 ++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index b5cbd261d..19623328c 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -6177,6 +6177,7 @@ std::vector Notepad_plus::loadCommandlineParams(const TCHAR * co bool recursive = pCmdParams->_isRecursive; bool readOnly = pCmdParams->_isReadOnly; bool openFoldersAsWorkspace = pCmdParams->_openFoldersAsWorkspace; + bool monitorFiles = pCmdParams->_monitorFiles; if (openFoldersAsWorkspace) { @@ -6238,6 +6239,12 @@ std::vector Notepad_plus::loadCommandlineParams(const TCHAR * co switchEditViewTo(iView); //restore view } + + if (monitorFiles) + { + monitoringStartOrStopAndUpdateUI(pBuf, true); + createMonitoringThread(pBuf); + } } if (lastOpened != BUFFER_INVALID) { @@ -8109,6 +8116,13 @@ void Notepad_plus::monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStartin } } +void Notepad_plus::createMonitoringThread(Buffer* pBuf) +{ + MonitorInfo *monitorInfo = new Notepad_plus::MonitorInfo(pBuf, _pPublicInterface->getHSelf()); + HANDLE hThread = ::CreateThread(NULL, 0, monitorFileOnChange, (void *)monitorInfo, 0, NULL); // will be deallocated while quitting thread + ::CloseHandle(hThread); +} + // Fill names into the shortcut list. // Each command shortcut has two names: // - The menu name, to be displayed in the menu diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index df5aa4f17..aec694daf 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -636,5 +636,6 @@ private: }; void monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting); + void createMonitoringThread(Buffer* pBuf); void updateCommandShortcuts(); }; diff --git a/PowerEditor/src/Notepad_plus_Window.h b/PowerEditor/src/Notepad_plus_Window.h index 7f4e3d214..c1eb5ed18 100644 --- a/PowerEditor/src/Notepad_plus_Window.h +++ b/PowerEditor/src/Notepad_plus_Window.h @@ -20,7 +20,7 @@ const int splitterSize = 8; const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\ \r\ -notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-udl=\"My UDL Name\"] [-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\ +notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-udl=\"My UDL Name\"] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-pPosition] [-xLeftPos] [-yTopPos] [-monitor] [-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\ @@ -33,6 +33,7 @@ notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-udl=\"My UDL Name\"] -p : Scroll to indicated position on filePath\r\ -x : Move Notepad++ to indicated left side position on the screen\r\ -y : Move Notepad++ to indicated top position on the screen\r\ +-monitor: Open file with file monitoring enabled\r\ -nosession : Launch Notepad++ without previous session\r\ -notabbar : Launch Notepad++ without tabbar\r\ -ro : Make the filePath read only\r\ diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index c4dc88d15..89e13dc69 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -2517,10 +2517,7 @@ void Notepad_plus::command(int id) { // Monitoring firstly for making monitoring icon monitoringStartOrStopAndUpdateUI(curBuf, true); - - MonitorInfo *monitorInfo = new MonitorInfo(curBuf, _pPublicInterface->getHSelf()); - HANDLE hThread = ::CreateThread(NULL, 0, monitorFileOnChange, (void *)monitorInfo, 0, NULL); // will be deallocated while quitting thread - ::CloseHandle(hThread); + createMonitoringThread(curBuf); } } else diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 7b4e412b3..18064d369 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -242,6 +242,7 @@ struct CmdLineParams bool _isSessionFile = false; bool _isRecursive = false; bool _openFoldersAsWorkspace = false; + bool _monitorFiles = false; LangType _langType = L_EXTERNAL; generic_string _localizationPath; @@ -271,6 +272,7 @@ struct CmdLineParamsDTO bool _isSessionFile = false; bool _isRecursive = false; bool _openFoldersAsWorkspace = false; + bool _monitorFiles = false; intptr_t _line2go = 0; intptr_t _column2go = 0; @@ -287,6 +289,7 @@ struct CmdLineParamsDTO dto._isSessionFile = params._isSessionFile; dto._isRecursive = params._isRecursive; dto._openFoldersAsWorkspace = params._openFoldersAsWorkspace; + dto._monitorFiles = params._monitorFiles; dto._line2go = params._line2go; dto._column2go = params._column2go; diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 74a476794..0d52a3e93 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -312,6 +312,7 @@ const TCHAR FLAG_OPEN_FOLDERS_AS_WORKSPACE[] = TEXT("-openFoldersAsWorkspace"); const TCHAR FLAG_SETTINGS_DIR[] = TEXT("-settingsDir="); const TCHAR FLAG_TITLEBAR_ADD[] = TEXT("-titleAdd="); const TCHAR FLAG_APPLY_UDL[] = TEXT("-udl="); +const TCHAR FLAG_MONITOR_FILES[] = TEXT("-monitor"); void doException(Notepad_plus_Window & notepad_plus_plus) { @@ -443,6 +444,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int) cmdLineParams._isSessionFile = isInList(FLAG_OPENSESSIONFILE, params); cmdLineParams._isRecursive = isInList(FLAG_RECURSIVE, params); cmdLineParams._openFoldersAsWorkspace = isInList(FLAG_OPEN_FOLDERS_AS_WORKSPACE, params); + cmdLineParams._monitorFiles = isInList(FLAG_MONITOR_FILES, params); cmdLineParams._langType = getLangTypeFromParam(params); cmdLineParams._localizationPath = getLocalizationPathFromParam(params);