/ideintf/idedialogs.pas

http://github.com/graemeg/lazarus · Pascal · 109 lines · 73 code · 13 blank · 23 comment · 6 complexity · fdb623ecdf54c15b08ad5e7ce1c59cd5 MD5 · raw file

  1. { Copyright (C) 2004
  2. *****************************************************************************
  3. * *
  4. * See the file COPYING.modifiedLGPL.txt, included in this distribution, *
  5. * for details about the copyright. *
  6. * *
  7. * This program is distributed in the hope that it will be useful, *
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
  10. * *
  11. *****************************************************************************
  12. Author: Mattias Gaertner
  13. Abstract:
  14. Common IDE dialogs.
  15. }
  16. unit IDEDialogs;
  17. {$mode objfpc}{$H+}
  18. interface
  19. uses
  20. Classes, SysUtils, Controls, Dialogs;
  21. type
  22. TIDESelectDirectory = function(const Title, InitialDir: string): string of object;
  23. TInitIDEFileDialog = procedure(AFileDialog: TFileDialog) of object;
  24. TStoreIDEFileDialog = procedure(AFileDialog: TFileDialog) of object;
  25. TIDEMessageDialog = function(const aCaption, aMsg: string;
  26. DlgType: TMsgDlgType; Buttons: TMsgDlgButtons;
  27. const HelpKeyword: string = ''): Integer of object;
  28. TIDEQuestionDialog = function(const aCaption, aMsg: string;
  29. DlgType: TMsgDlgType; Buttons: array of const;
  30. const HelpKeyword: string = ''): Integer of object;
  31. function LazSelectDirectory(const Title: string; const InitialDir: string = ''
  32. ): string;
  33. var
  34. LazIDESelectDirectory: TIDESelectDirectory = nil;// set by the IDE
  35. InitIDEFileDialog: TInitIDEFileDialog = nil;
  36. StoreIDEFileDialog: TStoreIDEFileDialog = nil ;
  37. IDEMessageDialog: TIDEMessageDialog = nil;
  38. IDEQuestionDialog: TIDEQuestionDialog = nil;
  39. function IDEMessageDialogAb(const aCaption, aMsg: string;
  40. DlgType: TMsgDlgType; Buttons: TMsgDlgButtons;
  41. ShowAbort: boolean; const HelpKeyword: string = ''): Integer;
  42. function IDEQuestionDialogAb(const aCaption, aMsg: string;
  43. DlgType: TMsgDlgType; Buttons: array of const;
  44. HideAbort: boolean; const HelpKeyword: string = ''): Integer;
  45. implementation
  46. function LazSelectDirectory(const Title: string; const InitialDir: string
  47. ): string;
  48. begin
  49. Result:=LazIDESelectDirectory(Title,InitialDir);
  50. end;
  51. function IDEMessageDialogAb(const aCaption, aMsg: string; DlgType: TMsgDlgType;
  52. Buttons: TMsgDlgButtons; ShowAbort: boolean; const HelpKeyword: string
  53. ): Integer;
  54. begin
  55. if ShowAbort then begin
  56. // add an abort button for 'Cancel all'
  57. // and replace a Cancel with Ignore
  58. Buttons:=Buttons+[mbAbort];
  59. if mbCancel in Buttons then
  60. Buttons:=Buttons-[mbCancel]+[mbIgnore];
  61. end;
  62. Result:=IDEMessageDialog(aCaption,aMsg,DlgType,Buttons,HelpKeyword);
  63. end;
  64. function IDEQuestionDialogAb(const aCaption, aMsg: string;
  65. DlgType: TMsgDlgType; Buttons: array of const;
  66. HideAbort: boolean; const HelpKeyword: string): Integer;
  67. var
  68. NewButtons: array of TVarRec;
  69. i: Integer;
  70. j: Integer;
  71. begin
  72. SetLength(NewButtons,High(Buttons)-Low(Buttons)+1);
  73. i:=low(Buttons);
  74. j:=0;
  75. while i<=High(Buttons) do begin
  76. if HideAbort
  77. and (Buttons[i].VType=vtInteger)
  78. and (Buttons[i].VInteger=mrAbort) then begin
  79. // skip abort button
  80. inc(i);
  81. // and skip abort caption
  82. if Buttons[i].VType<>vtInteger then
  83. inc(i);
  84. end else begin
  85. NewButtons[j]:=Buttons[i];
  86. inc(i);
  87. inc(j);
  88. end;
  89. end;
  90. SetLength(NewButtons,j);
  91. Result:=IDEQuestionDialog(aCaption,aMsg,DlgType,NewButtons,HelpKeyword);
  92. end;
  93. end.