Fix Tail moniotoring incoherent status after deleting a monitored file

Steps to Reproduce the Issue:

1. Open two files a.txt (first tab) and b.txt (second tab)
2. Start tail monitoring for a.txt (first tab) and activate b.txt (second tab)
3. Now delete a.txt from the explorer
4. Come back to notepad++
5. Observe the behavior now

Unexpected Behavior:

At step 4, if user choose to keep the file, a.txt is still marked as monitoring. As soon as del action occurs, b.txt automatically comes under "tail monitoring".
If user choose to remove file, a.txt should be removed from the notepad. This is absolutely fine.

Fix #4750, close #4751
This commit is contained in:
Rajendra Singh 2018-10-03 19:23:30 +05:30 committed by Don HO
parent 17190009bf
commit efbc3b2160
6 changed files with 29 additions and 15 deletions

View File

@ -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);
}
}

View File

@ -618,6 +618,8 @@ private:
Buffer *_buffer = nullptr;
HWND _nppHandle = nullptr;
};
void monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting);
};

View File

@ -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<Buffer *>(wParam);
monitoringStartOrStopAndUpdateUI(buf, false);
return TRUE;
}
case NPPM_INTERNAL_GETCHECKDOCOPT:
{
return (LRESULT)(pNppParam->getNppGUI())._fileAutoDetection;

View File

@ -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

View File

@ -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<WPARAM>(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

View File

@ -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