diff --git a/source/apphelpers.pas b/source/apphelpers.pas index 1b010033..2ad055ef 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -293,6 +293,7 @@ type function EncodeURLParam(const Value: String): String; procedure StreamWrite(S: TStream; Text: String = ''); function _GetFileSize(Filename: String): Int64; + function DeleteFileWithUndo(sFileName: String): Boolean; function MakeInt(Str: String) : Int64; function MakeFloat(Str: String): Extended; function CleanupNumber(Str: String): String; @@ -606,6 +607,18 @@ begin end; +function DeleteFileWithUndo(sFileName: string): Boolean; +var + fos: TSHFileOpStruct; +begin + FillChar(fos, SizeOf(fos), 0); + fos.wFunc := FO_DELETE; + fos.pFrom := PChar(sFileName); + fos.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_SILENT; + Result := (0 = ShFileOperation(fos)); +end; + + {*** Convert a string-number to an integer-number diff --git a/source/main.pas b/source/main.pas index 2e75cb46..b23eb9db 100644 --- a/source/main.pas +++ b/source/main.pas @@ -8317,7 +8317,7 @@ begin if MessageDialog(_('Delete snippet file?'), snippetfile, mtConfirmation, [mbOk, mbCancel]) = mrOk then begin Screen.Cursor := crHourGlass; - if DeleteFile(snippetfile) then begin + if DeleteFileWithUndo(snippetfile) then begin // Refresh list with snippets SetSnippetFilenames; end else begin @@ -12571,7 +12571,7 @@ begin end else begin // Delete backup file if tab is closed by user, intentionally if (not Tab.MemoBackupFilename.IsEmpty) and FileExists(Tab.MemoBackupFilename) then begin - if not DeleteFile(Tab.MemoBackupFilename) then begin + if not DeleteFileWithUndo(Tab.MemoBackupFilename) then begin ErrorDialog(f_('Backup file could not be deleted: %s', [Tab.MemoBackupFilename])); end; end; diff --git a/source/tabletools.pas b/source/tabletools.pas index eca88bd0..45e81d68 100644 --- a/source/tabletools.pas +++ b/source/tabletools.pas @@ -893,7 +893,7 @@ begin StartTime := GetTickCount; FileNameZip := FExportFileName; if FileExists(FileNameZip) then - DeleteFile(FileNameZip); + DeleteFileWithUndo(FileNameZip); Zip := TZipFile.Create; Zip.Open(FileNameZip, zmWrite); FileNameInZip := ExtractFileName(ChangeFileExt(FileNameZip, '.sql'));