Skip to content

Commit

Permalink
Merge file watching options.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jan 16, 2025
1 parent d9a007c commit 6e30346
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
24 changes: 15 additions & 9 deletions src/Dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,8 +1327,7 @@ bool FileMRUDlg(HWND hwnd, LPWSTR lpstrFile) noexcept {
//
//
extern FileWatchingMode iFileWatchingMode;
extern bool iFileWatchingMethod;
extern bool bFileWatchingKeepAtEnd;
extern int iFileWatchingOption;
extern bool bResetFileWatching;

static INT_PTR CALLBACK ChangeNotifyDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) noexcept {
Expand All @@ -1337,10 +1336,10 @@ static INT_PTR CALLBACK ChangeNotifyDlgProc(HWND hwnd, UINT umsg, WPARAM wParam,
switch (umsg) {
case WM_INITDIALOG:
CheckRadioButton(hwnd, IDC_CHANGENOTIFY_NONE, IDC_CHANGENOTIFY_AUTO_RELOAD, IDC_CHANGENOTIFY_NONE + static_cast<int>(iFileWatchingMode));
if (iFileWatchingMethod) {
if (iFileWatchingOption & FileWatchingOption_LogFile) {
CheckDlgButton(hwnd, IDC_CHANGENOTIFY_LOG_FILE, BST_CHECKED);
}
if (bFileWatchingKeepAtEnd) {
if (iFileWatchingOption & FileWatchingOption_KeepAtEnd) {
CheckDlgButton(hwnd, IDC_CHANGENOTIFY_KEEP_AT_END, BST_CHECKED);
}
if (bResetFileWatching) {
Expand All @@ -1351,13 +1350,20 @@ static INT_PTR CALLBACK ChangeNotifyDlgProc(HWND hwnd, UINT umsg, WPARAM wParam,

case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
iFileWatchingMode = static_cast<FileWatchingMode>(GetCheckedRadioButton(hwnd, IDC_CHANGENOTIFY_NONE, IDC_CHANGENOTIFY_AUTO_RELOAD) - IDC_CHANGENOTIFY_NONE);
iFileWatchingMethod = IsButtonChecked(hwnd, IDC_CHANGENOTIFY_LOG_FILE);
bFileWatchingKeepAtEnd = IsButtonChecked(hwnd, IDC_CHANGENOTIFY_KEEP_AT_END);
case IDOK: {
int value = GetCheckedRadioButton(hwnd, IDC_CHANGENOTIFY_NONE, IDC_CHANGENOTIFY_AUTO_RELOAD);
iFileWatchingMode = static_cast<FileWatchingMode>(value - IDC_CHANGENOTIFY_NONE);
value = FileWatchingOption_None;
if (IsButtonChecked(hwnd, IDC_CHANGENOTIFY_LOG_FILE)) {
value |= FileWatchingOption_LogFile;
}
if (IsButtonChecked(hwnd, IDC_CHANGENOTIFY_KEEP_AT_END)) {
value |= FileWatchingOption_KeepAtEnd;
}
iFileWatchingOption = value;
bResetFileWatching = IsButtonChecked(hwnd, IDC_CHANGENOTIFY_RESET_WATCH);
EndDialog(hwnd, IDOK);
break;
} break;

case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
Expand Down
13 changes: 5 additions & 8 deletions src/Notepad4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ RECT pageSetupMargin;
static bool bSaveBeforeRunningTools;
bool bOpenFolderWithMatepath;
FileWatchingMode iFileWatchingMode;
bool iFileWatchingMethod;
bool bFileWatchingKeepAtEnd;
int iFileWatchingOption;
bool bResetFileWatching;
static DWORD dwFileCheckInterval;
static DWORD dwAutoReloadTimeout;
Expand Down Expand Up @@ -1419,7 +1418,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
if ((iFileWatchingMode == FileWatchingMode_AutoReload && !IsDocumentModified())
|| MsgBoxWarn(MB_YESNO, IDS_FILECHANGENOTIFY) == IDYES) {
const bool bIsTail = (iFileWatchingMode == FileWatchingMode_AutoReload)
&& (bFileWatchingKeepAtEnd || (SciCall_LineFromPosition(SciCall_GetCurrentPos()) + 1 == SciCall_GetLineCount()));
&& ((iFileWatchingOption & FileWatchingOption_KeepAtEnd) || (SciCall_LineFromPosition(SciCall_GetCurrentPos()) + 1 == SciCall_GetLineCount()));

iWeakSrcEncoding = iCurrentEncoding;
if (FileLoad(static_cast<FileLoadFlag>(FileLoadFlag_DontSave | FileLoadFlag_Reload), szCurFile)) {
Expand Down Expand Up @@ -5312,8 +5311,7 @@ void LoadSettings() noexcept {

iValue = section.GetInt(L"FileWatchingMode", FileWatchingMode_AutoReload);
iFileWatchingMode = clamp(static_cast<FileWatchingMode>(iValue), FileWatchingMode_None, FileWatchingMode_AutoReload);
iFileWatchingMethod = section.GetBool(L"FileWatchingMethod", false);
bFileWatchingKeepAtEnd = section.GetBool(L"FileWatchingKeepAtEnd", false);
iFileWatchingOption = section.GetInt(L"FileWatchingOption", FileWatchingOption_None);
bResetFileWatching = section.GetBool(L"ResetFileWatching", false);

iAutoSaveOption = section.GetInt(L"AutoSaveOption", AutoSaveOption_Default);
Expand Down Expand Up @@ -5586,8 +5584,7 @@ void SaveSettings(bool bSaveSettingsNow) noexcept {
section.SetBoolEx(L"OpenFolderWithMatepath", bOpenFolderWithMatepath, true);

section.SetIntEx(L"FileWatchingMode", iFileWatchingMode, FileWatchingMode_AutoReload);
section.SetBoolEx(L"FileWatchingMethod", iFileWatchingMethod, false);
section.SetBoolEx(L"FileWatchingKeepAtEnd", bFileWatchingKeepAtEnd, false);
section.SetIntEx(L"FileWatchingOption", iFileWatchingOption, FileWatchingOption_None);
section.SetBoolEx(L"ResetFileWatching", bResetFileWatching, false);
section.SetIntEx(L"AutoSaveOption", iAutoSaveOption, AutoSaveOption_Default);
section.SetIntEx(L"AutoSavePeriod", dwAutoSavePeriod, AutoSaveDefaultPeriod);
Expand Down Expand Up @@ -8152,7 +8149,7 @@ void InstallFileWatching(bool terminate) noexcept {
memset(&fdCurFile, 0, sizeof(fdCurFile));
}

if (iFileWatchingMethod) {
if ((iFileWatchingOption & FileWatchingOption_LogFile) == FileWatchingOption_None) {
hChangeHandle = FindFirstChangeNotification(tchDirectory, FALSE,
FILE_NOTIFY_CHANGE_FILE_NAME | \
FILE_NOTIFY_CHANGE_DIR_NAME | \
Expand Down
6 changes: 6 additions & 0 deletions src/Notepad4.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ enum FileWatchingMode {
FileWatchingMode_AutoReload,
};

enum FileWatchingOption {
FileWatchingOption_None = 0,
FileWatchingOption_LogFile = 1,
FileWatchingOption_KeepAtEnd = 2,
};

enum MatchTextFlag {
MatchTextFlag_None = 0,
MatchTextFlag_Default = 1,
Expand Down

0 comments on commit 6e30346

Please sign in to comment.