PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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