Skip to content

Commit

Permalink
[AutoSave] Add option to directly overwrite current file, discussion #…
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Aug 4, 2024
1 parent 352a188 commit c79fff1
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 38 deletions.
9 changes: 5 additions & 4 deletions locale/de/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions locale/fr/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions locale/it/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions locale/ja/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions locale/ko/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions locale/pt-BR/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions locale/zh-Hans/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions locale/zh-Hant/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/Dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"";
Expand Down
13 changes: 12 additions & 1 deletion src/Notepad4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/Notepad4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
9 changes: 5 additions & 4 deletions src/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c79fff1

Please sign in to comment.