Skip to content

Commit 91de2fc

Browse files
committed
fix: prompt to overwrite only if file exists
Refs #2268
1 parent d5d34ad commit 91de2fc

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

source/extfiledialog.pas

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,19 @@ procedure TfrmExtFileDialog.FormCloseQuery(Sender: TObject;
178178
var CanClose: Boolean);
179179
begin
180180
CanClose := True;
181-
if ModalResult = mrOK then begin
182181

183-
if FileName.IsEmpty then begin
184-
CanClose := False;
185-
end;
182+
if ModalResult = mrCancel then
183+
Exit;
186184

187-
if (not FileName.IsEmpty) and (Self is TExtFileSaveDialog) and (ofOverwritePrompt in FOptions) then begin
188-
case MessageDialog(f_('File already exists: %s'+sLineBreak+sLineBreak+'Overwrite it?', [FileName]), mtConfirmation, [mbYes, mbNo]) of
189-
mrNo: begin
190-
CanClose := False;
191-
end;
192-
end;
193-
end;
185+
// Do nothing when user clicks OK without a selected file. Imitates Windows behaviour.
186+
if FileName.IsEmpty then begin
187+
CanClose := False;
188+
Exit;
189+
end;
194190

191+
// Ask user whether to overwrite the selected file
192+
if (Self is TExtFileSaveDialog) and (ofOverwritePrompt in FOptions) and (FileExists(FileName)) then begin
193+
CanClose := MessageDialog(f_('File already exists: %s'+sLineBreak+sLineBreak+'Overwrite it?', [FileName]), mtConfirmation, [mbYes, mbNo]) = mrYes;
195194
end;
196195
end;
197196

0 commit comments

Comments
 (0)