diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 9b3581e9..968950f1 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -6848,3 +6848,17 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment) while(1); //do as long as stream-comments are within selection } +void Notepad_plus::monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting) +{ + if (pBuf) + { + if (isStarting) + pBuf->startMonitoring(); + else + pBuf->stopMonitoring(); + + checkMenuItem(IDM_VIEW_MONITORING, isStarting); + _toolBar.setCheck(IDM_VIEW_MONITORING, isStarting); + pBuf->setUserReadOnly(isStarting); + } +} diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 36bdbcb2..1661ebd8 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -618,6 +618,8 @@ private: Buffer *_buffer = nullptr; HWND _nppHandle = nullptr; }; + + void monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting); }; diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 9b949672..a703d4a7 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1564,6 +1564,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return TRUE; } + case NPPM_INTERNAL_STOPMONITORING: + { + Buffer *buf = reinterpret_cast(wParam); + monitoringStartOrStopAndUpdateUI(buf, false); + return TRUE; + } + case NPPM_INTERNAL_GETCHECKDOCOPT: { return (LRESULT)(pNppParam->getNppGUI())._fileAutoDetection; diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index c91d94ba..2b8c8fbb 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1994,10 +1994,7 @@ void Notepad_plus::command(int id) Buffer * curBuf = _pEditView->getCurrentBuffer(); if (curBuf->isMonitoringOn()) { - curBuf->stopMonitoring(); - checkMenuItem(IDM_VIEW_MONITORING, false); - _toolBar.setCheck(IDM_VIEW_MONITORING, false); - curBuf->setUserReadOnly(false); + monitoringStartOrStopAndUpdateUI(curBuf, false); } else { @@ -2014,14 +2011,12 @@ void Notepad_plus::command(int id) } else { - curBuf->startMonitoring(); // monitoring firstly for making monitoring icon - curBuf->setUserReadOnly(true); + // 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); - checkMenuItem(IDM_VIEW_MONITORING, true); - _toolBar.setCheck(IDM_VIEW_MONITORING, true); } } else diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 7d4f8957..e7b8d8ec 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -100,8 +100,7 @@ DWORD WINAPI Notepad_plus::monitorFileOnChange(void * params) else if ((dwAction == FILE_ACTION_REMOVED) || (dwAction == FILE_ACTION_RENAMED_OLD_NAME)) { // File is deleted or renamed - quit monitoring thread and close file - ::PostMessage(h, NPPM_MENUCOMMAND, 0, IDM_VIEW_MONITORING); - ::PostMessage(h, NPPM_INTERNAL_CHECKDOCSTATUS, 0, 0); + ::PostMessage(h, NPPM_INTERNAL_STOPMONITORING, reinterpret_cast(buf), 0); } } } @@ -662,11 +661,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup) if (buf->isMonitoringOn()) { // turn off monitoring - //command(IDM_VIEW_MONITORING); - buf->stopMonitoring(); - checkMenuItem(IDM_VIEW_MONITORING, false); - _toolBar.setCheck(IDM_VIEW_MONITORING, false); - buf->setUserReadOnly(false); + monitoringStartOrStopAndUpdateUI(buf, false); } //Do all the works diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 69c14d0d..0368b17f 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -432,6 +432,7 @@ #define NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT (NOTEPADPLUS_USER_INTERNAL + 46) #define NPPM_INTERNAL_PRNTANDQUIT (NOTEPADPLUS_USER_INTERNAL + 47) #define NPPM_INTERNAL_SAVEBACKUP (NOTEPADPLUS_USER_INTERNAL + 48) + #define NPPM_INTERNAL_STOPMONITORING (NOTEPADPLUS_USER_INTERNAL + 49) // Used by Monitoring feature //wParam: 0 //lParam: document new index