replace okCancel dialogs by YesNo dialogs

This commit is contained in:
Basile Burg 2016-04-11 07:10:32 +02:00
parent 87bffb06fc
commit dfc479617c
5 changed files with 39 additions and 27 deletions

View File

@ -11,22 +11,27 @@ uses
(** (**
* Ok/Cancel modal dialog * Ok/Cancel modal dialog
*) *)
function dlgOkCancel(const aMsg: string): TModalResult; function dlgOkCancel(const message: string): TModalResult;
(**
* Yes/No modal dialog
*)
function dlgYesNo(const message: string): TModalResult;
(** (**
* Info message * Info message
*) *)
function dlgOkInfo(const aMsg: string): TModalResult; function dlgOkInfo(const message: string): TModalResult;
(** (**
* Error message * Error message
*) *)
function dlgOkError(const aMsg: string): TModalResult; function dlgOkError(const message: string): TModalResult;
(** (**
* close aFilename Ok/Cancel. * close aFilename Ok/Cancel.
*) *)
function dlgFileChangeClose(const aFilename: string): TModalResult; function dlgFileChangeClose(const fname: string): TModalResult;
const const
DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*'; DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*';
@ -34,32 +39,39 @@ const
implementation implementation
function dlgOkCancel(const aMsg: string): TModalResult; function dlgOkCancel(const message: string): TModalResult;
const const
Btns = [mbOK,mbCancel]; Btns = [mbOK,mbCancel];
begin begin
exit( MessageDlg('Coedit', aMsg, mtConfirmation, Btns, '')); exit( MessageDlg('Coedit', message, mtConfirmation, Btns, ''));
end; end;
function dlgOkInfo(const aMsg: string): TModalResult; function dlgYesNo(const message: string): TModalResult;
const
Btns = [mbYes,mbNo];
begin
exit( MessageDlg('Coedit', message, mtConfirmation, Btns, ''));
end;
function dlgOkInfo(const message: string): TModalResult;
const const
Btns = [mbOK]; Btns = [mbOK];
begin begin
exit( MessageDlg('Coedit', aMsg, mtInformation, Btns, '')); exit( MessageDlg('Coedit', message, mtInformation, Btns, ''));
end; end;
function dlgOkError(const aMsg: string): TModalResult; function dlgOkError(const message: string): TModalResult;
const const
Btns = [mbOK]; Btns = [mbOK];
begin begin
exit( MessageDlg('Coedit', aMsg, mtError, Btns, '')); exit( MessageDlg('Coedit', message, mtError, Btns, ''));
end; end;
function dlgFileChangeClose(const aFilename: string): TModalResult; function dlgFileChangeClose(const fname: string): TModalResult;
const const
fmt = '"%s" latest modifications are not saved.'#13#10#13#10'Close it without saving ?'; fmt = '"%s" latest modifications are not saved.'#13#10#13#10'Close it without saving ?';
begin begin
exit(dlgOkCancel(format(fmt, [aFilename]))); exit(dlgOkCancel(format(fmt, [fname])));
end; end;
end. end.

View File

@ -1471,7 +1471,7 @@ begin
if fRunProjAfterCompile and assigned(fProjectInterface) then if fRunProjAfterCompile and assigned(fProjectInterface) then
begin begin
if not success then if not success then
runprev := dlgOkCancel('last build failed, continue and run ?') = mrOK; runprev := dlgYesNo('last build failed, continue and run ?') = mrYes;
if runprev then if runprev then
begin begin
if fRunProjAfterCompArg and if fRunProjAfterCompArg and
@ -2205,7 +2205,7 @@ begin
end; end;
if (not exist) or (older) then if (not exist) or (older) then
begin begin
if dlgOkCancel(messg) = mrOK then if dlgYesNo(messg) = mrYes then
compileRunnable compileRunnable
else if not exist then else if not exist then
exit; exit;
@ -2247,7 +2247,7 @@ begin
exit; exit;
end; end;
if (not fProjectInterface.targetUpToDate) then if if (not fProjectInterface.targetUpToDate) then if
dlgOkCancel('The project output is not up-to-date, rebuild ?') = mrOK then dlgYesNo('The project output is not up-to-date, rebuild ?') = mrYes then
fProjectInterface.compile; fProjectInterface.compile;
if fProjectInterface.outputFilename.fileExists if fProjectInterface.outputFilename.fileExists
or (fProjectInterface.getFormat = pfDub) then or (fProjectInterface.getFormat = pfDub) then

View File

@ -497,9 +497,9 @@ var
if sourceAbsolute(i).fileExists then if sourceAbsolute(i).fileExists then
allMissing := false; allMissing := false;
if not allMissing then exit; if not allMissing then exit;
if dlgOkCancel( 'The project source(s) are all missing. ' + LineEnding + if dlgYesNo( 'The project source(s) are all missing. ' + LineEnding +
'This can be encountered if the project file has been moved from its original location.' + LineEnding + LineEnding + 'This can be encountered if the project file has been moved from its original location.' + LineEnding + LineEnding +
'Do you wish to select the new root folder ?') <> mrOk then exit; 'Do you wish to select the new root folder ?') <> mrYes then exit;
// TODO-cimprovement: use commonFolder() when it'll be compat. with the rel. paths. // TODO-cimprovement: use commonFolder() when it'll be compat. with the rel. paths.
// hint for the common dir // hint for the common dir
dirHint := fSrcs[i]; dirHint := fSrcs[i];
@ -529,10 +529,10 @@ var
begin begin
oldsrc := sourceAbsolute(i); oldsrc := sourceAbsolute(i);
if oldsrc.fileExists then continue; if oldsrc.fileExists then continue;
if dlgOkCancel(format('a particular project source file ("%s") is missing. ' if dlgYesNo(format('a particular project source file ("%s") is missing. '
+ LineEnding + 'This happends if a source file has been moved, renamed ' + + LineEnding + 'This happends if a source file has been moved, renamed ' +
'or deleted.' + LineEnding + LineEnding + 'or deleted.' + LineEnding + LineEnding +
'Do you wish to select its new location?', [fSrcs[i]])) <> mrOk then exit; 'Do you wish to select its new location?', [fSrcs[i]])) <> mrYes then exit;
// //
opendlg := TOpenDialog.Create(nil); opendlg := TOpenDialog.Create(nil);
try try
@ -541,14 +541,14 @@ var
if opendlg.execute then if opendlg.execute then
begin begin
if oldsrc.extractFileName <> opendlg.filename.extractFileName then if oldsrc.extractFileName <> opendlg.filename.extractFileName then
if dlgOkCancel('the filenames are different, replace the old file ?') <> mrOk then if dlgYesNo('the filenames are different, replace the old file ?') <> mrYes then
continue; continue;
fSrcs[i] := ExtractRelativepath(fBasePath, opendlg.Filename); fSrcs[i] := ExtractRelativepath(fBasePath, opendlg.Filename);
hasPatched := true; hasPatched := true;
end else end else
begin begin
if dlgOkCancel('You have choosen not to update the file, ' + if dlgYesNo('You have choosen not to update the file, ' +
'do you wish to remove it from the project ?') <> mrOk then 'do you wish to remove it from the project ?') <> mrYes then
continue; continue;
fSrcs.Delete(i); fSrcs.Delete(i);
hasPatched := true; hasPatched := true;

View File

@ -147,7 +147,7 @@ begin
begin begin
if fCatChanged then if fCatChanged then
begin begin
result := dlgOkCancel(msg_mod) = mrOk; result := dlgYesNo(msg_mod) = mrYes;
fCatChanged := not result; fCatChanged := not result;
if result then btnCancelClick(nil); if result then btnCancelClick(nil);
end; end;
@ -159,7 +159,7 @@ begin
if dt^.observer = nil then exit; if dt^.observer = nil then exit;
if dt^.observer.optionedOptionsModified() then if dt^.observer.optionedOptionsModified() then
begin begin
result := dlgOkCancel(msg_mod) = mrOk; result := dlgYesNo(msg_mod) = mrYes;
if result then btnCancelClick(nil); if result then btnCancelClick(nil);
end; end;
end; end;

View File

@ -1385,8 +1385,8 @@ begin
begin begin
// note: this could cause a bug during the DST switch. // note: this could cause a bug during the DST switch.
// e.g: save at 2h59, 3h00 reset to 2h00, set the focus on the doc: new version message. // e.g: save at 2h59, 3h00 reset to 2h00, set the focus on the doc: new version message.
if dlgOkCancel(format('"%s" has been modified by another program, load the new version ?', if dlgYesNo(format('"%s" has been modified by another program, load the new version ?',
[shortenPath(fFilename, 25)])) = mrOk then [shortenPath(fFilename, 25)])) = mrYes then
begin begin
str := TStringList.Create; str := TStringList.Create;
try try