From c79fff1cabc8ab4190dee6583f8c1e37073666d6 Mon Sep 17 00:00:00 2001 From: zufuliu Date: Sun, 4 Aug 2024 09:17:32 +0800 Subject: [PATCH] [AutoSave] Add option to directly overwrite current file, discussion #800. --- locale/de/Notepad4.rc | 9 +++++---- locale/fr/Notepad4.rc | 9 +++++---- locale/it/Notepad4.rc | 9 +++++---- locale/ja/Notepad4.rc | 9 +++++---- locale/ko/Notepad4.rc | 9 +++++---- locale/pt-BR/Notepad4.rc | 9 +++++---- locale/zh-Hans/Notepad4.rc | 9 +++++---- locale/zh-Hant/Notepad4.rc | 9 +++++---- src/Dialogs.cpp | 6 ++++++ src/Notepad4.cpp | 13 ++++++++++++- src/Notepad4.h | 1 + src/Notepad4.rc | 9 +++++---- src/resource.h | 3 ++- 13 files changed, 66 insertions(+), 38 deletions(-) diff --git a/locale/de/Notepad4.rc b/locale/de/Notepad4.rc index 9096a35c2e..cb2193c081 100644 --- a/locale/de/Notepad4.rc +++ b/locale/de/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "AutoSave Settings" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "Save backup on system suspend.",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "Save backup on system shutdown.",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "Manually delete backups.",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "Open Folder",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "OK",IDOK,71,72,50,14 - PUSHBUTTON "Cancel",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "Directly overwrite current file.",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "Open Folder",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "OK",IDOK,71,84,50,14 + PUSHBUTTON "Cancel",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/locale/fr/Notepad4.rc b/locale/fr/Notepad4.rc index 782ca85f48..981de8a39b 100644 --- a/locale/fr/Notepad4.rc +++ b/locale/fr/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "Annuler",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Réglage de sauvegarde automatique" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "Déclencher une sauvegarde lors de la mise en veille du système.",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "Déclencher une sauvegarde lors de l'arrêt du système.",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "Effacement manuel des sauvegardes.",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "Ouvrir un répertoire",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "OK",IDOK,71,72,50,14 - PUSHBUTTON "Annuler",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "Directly overwrite current file.",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "Ouvrir un répertoire",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "OK",IDOK,71,84,50,14 + PUSHBUTTON "Annuler",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/locale/it/Notepad4.rc b/locale/it/Notepad4.rc index 45da1deed4..5bae77b204 100644 --- a/locale/it/Notepad4.rc +++ b/locale/it/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "Annulla",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Impostazioni Autosalvataggio" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "Salva backup in caso di sospensione del sistema.",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "Salva backup in caso di spegnimento del sistema.",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "Eliminare manualmente i backup.",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "Apri cartella",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "OK",IDOK,71,72,50,14 - PUSHBUTTON "Annulla",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "Directly overwrite current file.",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "Apri cartella",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "OK",IDOK,71,84,50,14 + PUSHBUTTON "Annulla",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/locale/ja/Notepad4.rc b/locale/ja/Notepad4.rc index be5fcaf64c..28157ede88 100644 --- a/locale/ja/Notepad4.rc +++ b/locale/ja/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "キャンセル",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "自動保存の設定" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "システム休止時にバックアップを保存",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "システムシャットダウン時にバックアップを保存",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "バックアップの削除は手動で行う",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "フォルダを開く",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "OK",IDOK,71,72,50,14 - PUSHBUTTON "キャンセル",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "Directly overwrite current file.",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "フォルダを開く",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "OK",IDOK,71,84,50,14 + PUSHBUTTON "キャンセル",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/locale/ko/Notepad4.rc b/locale/ko/Notepad4.rc index 4d88e3f12d..3dcc700b6e 100644 --- a/locale/ko/Notepad4.rc +++ b/locale/ko/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "취소",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "자동 저장 설정" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "시스템 일시 중단 시 백업 저장",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "시스템 종료 시 백업 저장",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "수동으로 백업 삭제",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "폴더 열기",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "확인",IDOK,71,72,50,14 - PUSHBUTTON "취소",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "Directly overwrite current file.",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "폴더 열기",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "확인",IDOK,71,84,50,14 + PUSHBUTTON "취소",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/locale/pt-BR/Notepad4.rc b/locale/pt-BR/Notepad4.rc index c9a0c08629..8063c76e71 100644 --- a/locale/pt-BR/Notepad4.rc +++ b/locale/pt-BR/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "AutoSave Settings" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "Save backup on system suspend.",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "Save backup on system shutdown.",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "Manually delete backups.",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "Open Folder",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "OK",IDOK,71,72,50,14 - PUSHBUTTON "Cancel",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "Directly overwrite current file.",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "Open Folder",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "OK",IDOK,71,84,50,14 + PUSHBUTTON "Cancel",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/locale/zh-Hans/Notepad4.rc b/locale/zh-Hans/Notepad4.rc index d36124054c..9c279acd4d 100644 --- a/locale/zh-Hans/Notepad4.rc +++ b/locale/zh-Hans/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "取消",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "自动保存设置" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "系统休眠的时候保存备份",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "系统关机的时候保存备份",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "手动删除备份",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "打开文件夹",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "确定",IDOK,71,72,50,14 - PUSHBUTTON "取消",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "直接覆盖当前文件",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "打开文件夹",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "确定",IDOK,71,84,50,14 + PUSHBUTTON "取消",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/locale/zh-Hant/Notepad4.rc b/locale/zh-Hant/Notepad4.rc index b87836558d..8694ad4833 100644 --- a/locale/zh-Hant/Notepad4.rc +++ b/locale/zh-Hant/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "取消",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "自動保存設置" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "系統休眠的時候保存備份",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "系統關機的時候保存備份",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "手動刪除備份",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "打開資料夾",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "確定",IDOK,71,72,50,14 - PUSHBUTTON "取消",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "直接覆蓋當前檔",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "打開資料夾",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "確定",IDOK,71,84,50,14 + PUSHBUTTON "取消",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/src/Dialogs.cpp b/src/Dialogs.cpp index 4dcc3af60e..2dd0164d75 100644 --- a/src/Dialogs.cpp +++ b/src/Dialogs.cpp @@ -2516,6 +2516,9 @@ static INT_PTR CALLBACK AutoSaveSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wPa if (iAutoSaveOption & AutoSaveOption_ManuallyDelete) { CheckDlgButton(hwnd, IDC_AUTOSAVE_MANUALLYDELETE, BST_CHECKED); } + if (iAutoSaveOption & AutoSaveOption_OverwriteCurrent) { + CheckDlgButton(hwnd, IDC_AUTOSAVE_OVERWRITECURRENT, BST_CHECKED); + } WCHAR tch[32]; const UINT seconds = dwAutoSavePeriod / 1000; @@ -2547,6 +2550,9 @@ static INT_PTR CALLBACK AutoSaveSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wPa if (IsButtonChecked(hwnd, IDC_AUTOSAVE_MANUALLYDELETE)) { option |= AutoSaveOption_ManuallyDelete; } + if (IsButtonChecked(hwnd, IDC_AUTOSAVE_OVERWRITECURRENT)) { + option |= AutoSaveOption_OverwriteCurrent; + } iAutoSaveOption = option; WCHAR tch[32] = L""; diff --git a/src/Notepad4.cpp b/src/Notepad4.cpp index a6cd2282d6..ac2aaed0dc 100644 --- a/src/Notepad4.cpp +++ b/src/Notepad4.cpp @@ -8672,8 +8672,19 @@ void AutoSave_DoWork(FileSaveFlag saveFlag) noexcept { return; } - WCHAR tchPath[MAX_PATH + 40]; const bool Untitled = StrIsEmpty(szCurFile); + if (!Untitled && saveFlag == FileSaveFlag_Default && (iAutoSaveOption & AutoSaveOption_OverwriteCurrent)) { + // overwrite current file + EditFileIOStatus status{}; + status.iEncoding = iCurrentEncoding; + status.iEOLMode = iCurrentEOLMode; + if (EditSaveFile(hwndEdit, szCurFile, FileSaveFlag_EndSession, status)) { + dwLastSavedDocReversion = dwCurrentDocReversion; + return; + } + } + + WCHAR tchPath[MAX_PATH + 40]; LPCWSTR extension = L"bak"; if (Untitled) { lstrcpy(tchPath, L"Untitled"); diff --git a/src/Notepad4.h b/src/Notepad4.h index 5589688d6f..ccb501da94 100644 --- a/src/Notepad4.h +++ b/src/Notepad4.h @@ -275,6 +275,7 @@ enum { AutoSaveOption_Suspend = 2, AutoSaveOption_Shutdown = 4, AutoSaveOption_ManuallyDelete = 8, + AutoSaveOption_OverwriteCurrent = 16, AutoSaveOption_Default = AutoSaveOption_Suspend | AutoSaveOption_Shutdown, AutoSaveDefaultPeriod = 5000, }; diff --git a/src/Notepad4.rc b/src/Notepad4.rc index e59d98d11e..6851fd6e79 100644 --- a/src/Notepad4.rc +++ b/src/Notepad4.rc @@ -1660,7 +1660,7 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,399,174,50,14 END -IDD_AUTOSAVE DIALOGEX 0, 0, 184, 93 +IDD_AUTOSAVE DIALOGEX 0, 0, 184, 105 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "AutoSave Settings" FONT 8, "MS Shell Dlg", 0, 0, 0x0 @@ -1671,9 +1671,10 @@ BEGIN AUTOCHECKBOX "Save backup on system suspend.",IDC_AUTOSAVE_SUSPEND,7,31,170,10,WS_GROUP | WS_TABSTOP AUTOCHECKBOX "Save backup on system shutdown.",IDC_AUTOSAVE_SHUTDOWN,7,43,170,10,WS_TABSTOP AUTOCHECKBOX "Manually delete backups.",IDC_AUTOSAVE_MANUALLYDELETE,7,55,170,10,WS_TABSTOP - PUSHBUTTON "Open Folder",IDC_AUTOSAVE_OPENFOLDER,7,72,60,14 - DEFPUSHBUTTON "OK",IDOK,71,72,50,14 - PUSHBUTTON "Cancel",IDCANCEL,127,72,50,14 + AUTOCHECKBOX "Directly overwrite current file.",IDC_AUTOSAVE_OVERWRITECURRENT,7,67,170,10,WS_TABSTOP + PUSHBUTTON "Open Folder",IDC_AUTOSAVE_OPENFOLDER,7,84,60,14 + DEFPUSHBUTTON "OK",IDOK,71,84,50,14 + PUSHBUTTON "Cancel",IDCANCEL,127,84,50,14 END IDD_CSV_OPTIONS DIALOGEX 0, 0, 220, 118 diff --git a/src/resource.h b/src/resource.h index fb956db443..ae851a5aef 100644 --- a/src/resource.h +++ b/src/resource.h @@ -353,7 +353,8 @@ #define IDC_AUTOSAVE_SUSPEND 102 #define IDC_AUTOSAVE_SHUTDOWN 103 #define IDC_AUTOSAVE_MANUALLYDELETE 104 -#define IDC_AUTOSAVE_OPENFOLDER 105 +#define IDC_AUTOSAVE_OVERWRITECURRENT 105 +#define IDC_AUTOSAVE_OPENFOLDER 106 // CSV Options #define IDD_CSV_OPTIONS 133 #define IDC_CSV_DELIMITER_COMMA 100