Skip to content

Commit

Permalink
Minor code refactoring for file watching.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jan 16, 2025
1 parent 5ee2d9a commit d9a007c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6461,7 +6461,7 @@ static INT_PTR CALLBACK EditInsertTagDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
if (*pwCur == L'>' && pwCur[-1] != L'/') {
wchIns[cchIns] = L' ';
wchIns[cchIns + 1] = L'\0';
if (cchIns > 3 && cchIns < 16 && (pLexCurrent->iLexer != SCLEX_XML)) {
if (cchIns > 3 && cchIns < 15 && (pLexCurrent->iLexer != SCLEX_XML)) {
char tag[16]; // HTML void tag except <p>
#if NP2_USE_SSE2
const __m128i *mm = reinterpret_cast<const __m128i *>(wchIns);
Expand Down
27 changes: 17 additions & 10 deletions src/Notepad4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8134,9 +8134,9 @@ void InstallFileWatching(bool terminate) noexcept {
}
}

bRunningWatch = !terminate;
dwChangeNotifyTime = 0;
if (!terminate) {
bRunningWatch = !terminate;
if (bRunningWatch) {
// Install
SetTimer(nullptr, ID_WATCHTIMER, dwFileCheckInterval, WatchTimerProc);

Expand All @@ -8152,12 +8152,17 @@ void InstallFileWatching(bool terminate) noexcept {
memset(&fdCurFile, 0, sizeof(fdCurFile));
}

hChangeHandle = iFileWatchingMethod ? nullptr : FindFirstChangeNotification(tchDirectory, FALSE,
if (iFileWatchingMethod) {
hChangeHandle = FindFirstChangeNotification(tchDirectory, FALSE,
FILE_NOTIFY_CHANGE_FILE_NAME | \
FILE_NOTIFY_CHANGE_DIR_NAME | \
FILE_NOTIFY_CHANGE_ATTRIBUTES | \
FILE_NOTIFY_CHANGE_SIZE | \
FILE_NOTIFY_CHANGE_LAST_WRITE);
if (hChangeHandle == INVALID_HANDLE_VALUE) {
hChangeHandle = nullptr;
}
}
}
}

Expand Down Expand Up @@ -8190,7 +8195,7 @@ static void CheckCurrentFileChangedOutsideApp() noexcept {
dwChangeNotifyTime = 0;
SendMessage(hwndMain, APPM_CHANGENOTIFY, 0, 0);
}
} else if (!iFileWatchingMethod) {
} else if (hChangeHandle) {
FindNextChangeNotification(hChangeHandle);
}
}
Expand All @@ -8217,17 +8222,19 @@ void CALLBACK WatchTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTim
dwChangeNotifyTime = 0;
SendMessage(hwndMain, APPM_CHANGENOTIFY, 0, 0);
}
// Check Change Notification Handle
// TODO: notification not fired for continuously updated file
else if (hChangeHandle) {
if (WAIT_OBJECT_0 == WaitForSingleObject(hChangeHandle, 0)) {
CheckCurrentFileChangedOutsideApp();
}
}
// polling, not very efficient but useful for watching continuously updated file
else if (iFileWatchingMethod) {
else {
if (dwChangeNotifyTime == 0) {
CheckCurrentFileChangedOutsideApp();
}
}
// Check Change Notification Handle
// TODO: notification not fired for continuously updated file
else if (WAIT_OBJECT_0 == WaitForSingleObject(hChangeHandle, 0)) {
CheckCurrentFileChangedOutsideApp();
}
}
}

Expand Down

0 comments on commit d9a007c

Please sign in to comment.