Skip to content

Commit fe95e5e

Browse files
committed
Add option to cancel/stop file watching after current file been deleted.
1 parent 12cccc5 commit fe95e5e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Notepad4.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,11 +1412,12 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
14121412
}
14131413
return DefWindowProc(hwnd, umsg, wParam, lParam);
14141414

1415-
case APPM_CHANGENOTIFY:
1415+
case APPM_CHANGENOTIFY: {
14161416
if (iFileWatchingMode == FileWatchingMode_ShowMessage || IsDocumentModified()) {
14171417
SetForegroundWindow(hwnd);
14181418
}
14191419

1420+
bool terminate = false;
14201421
if (PathIsFile(szCurFile)) {
14211422
if ((iFileWatchingMode == FileWatchingMode_AutoReload && !IsDocumentModified())
14221423
|| MsgBoxWarn(MB_YESNO, IDS_FILECHANGENOTIFY) == IDYES) {
@@ -1431,15 +1432,17 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
14311432
}
14321433
}
14331434
} else {
1434-
if (MsgBoxWarn(MB_YESNO, IDS_FILECHANGENOTIFY2) == IDYES) {
1435+
const int result = MsgBoxWarn(MB_YESNOCANCEL, IDS_FILECHANGENOTIFY2);
1436+
terminate = result == IDCANCEL;
1437+
if (result == IDYES) {
14351438
FileSave(FileSaveFlag_SaveAlways);
14361439
}
14371440
}
14381441

1439-
if (!bRunningWatch) {
1440-
InstallFileWatching(false);
1442+
if (!bRunningWatch || terminate) {
1443+
InstallFileWatching(terminate);
14411444
}
1442-
break;
1445+
} break;
14431446

14441447
//// This message is posted before Notepad4 reactivates itself
14451448
//case APPM_CHANGENOTIFYCLEAR:

0 commit comments

Comments
 (0)