1 {
2  ***************************************************************************
3  *                                                                         *
4  *   This source is free software; you can redistribute it and/or modify   *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This code is distributed in the hope that it will be useful, but      *
10  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
12  *   General Public License for more details.                              *
13  *                                                                         *
14  *   A copy of the GNU General Public License is available on the World    *
15  *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
16  *   obtain it by writing to the Free Software Foundation,                 *
17  *   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.   *
18  *                                                                         *
19  ***************************************************************************
20 
21   Author: Mattias Gaertner
22 
23   Abstract:
24     Dialog to select a macro.
25 }
26 unit CodeMacroSelect;
27 
28 {$mode objfpc}{$H+}
29 
30 interface
31 
32 uses
33   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
34   Buttons, SrcEditorIntf, IDEWindowIntf,
35   InputHistory , LazarusIDEStrConsts, ButtonPanel;
36 
37 type
38 
39   { TCodeMacroSelectDlg }
40 
41   TCodeMacroSelectDlg = class(TForm)
42     ButtonPanel1: TButtonPanel;
43     ParameterEdit: TEdit;
44     ParameterGroupBox: TGroupBox;
45     MacrosListBox: TListBox;
46     DescriptionMemo: TMemo;
47     MacrosGroupBox: TGroupBox;
48     DescriptionGroupBox: TGroupBox;
49     procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
50     procedure FormCreate(Sender: TObject);
51     procedure MacrosListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
52   private
53     FSelected: TIDECodeMacro;
54     procedure FillMacrosListbox;
55   public
56     property Selected: TIDECodeMacro read FSelected;
57   end;
58 
59 
ShowCodeMacroSelectDialognull60 function ShowCodeMacroSelectDialog(out Parameter: string): TIDECodeMacro;
61 
62 implementation
63 
64 {$R *.lfm}
65 
ShowCodeMacroSelectDialognull66 function ShowCodeMacroSelectDialog(out Parameter: string): TIDECodeMacro;
67 var
68   CodeMacroSelectDlg: TCodeMacroSelectDlg;
69 begin
70   CodeMacroSelectDlg:=TCodeMacroSelectDlg.Create(nil);
71   if CodeMacroSelectDlg.ShowModal=mrOk then begin
72     Result:=CodeMacroSelectDlg.Selected;
73     Parameter:=CodeMacroSelectDlg.ParameterEdit.Text;
74   end else begin
75     Result:=nil;
76     Parameter:='';
77   end;
78   CodeMacroSelectDlg.Free;
79 end;
80 
81 { TCodeMacroSelectDlg }
82 
83 procedure TCodeMacroSelectDlg.FormCreate(Sender: TObject);
84 begin
85   IDEDialogLayoutList.ApplyLayout(Self,550,250);
86 
87   Caption:=lisCTSelectCodeMacro;
88   MacrosGroupBox.Caption:=lisEdtExtToolMacros;
89   DescriptionGroupBox.Caption:=lisCodeHelpDescrTag;
90   ButtonPanel1.OkButton.Caption:=lisInsertMacro;
91   ParameterGroupBox.Caption:=lisCMParameter;
92   ParameterEdit.Text:='';
93 
94   FillMacrosListbox;
95 
96   MacrosListBoxSelectionChange(self, False);
97 end;
98 
99 procedure TCodeMacroSelectDlg.FormClose(Sender: TObject;
100   var CloseAction: TCloseAction);
101 begin
102   IDEDialogLayoutList.SaveLayout(Self);
103 end;
104 
105 procedure TCodeMacroSelectDlg.MacrosListBoxSelectionChange(Sender: TObject;
106   User: boolean);
107 var
108   i: LongInt;
109   MacroName: string;
110 begin
111   i:=MacrosListBox.ItemIndex;
112   if (i>=0) then begin
113     MacroName:=MacrosListBox.Items[i];
114     FSelected:=IDECodeMacros.FindByName(MacroName);
115   end else begin
116     FSelected:=nil;
117   end;
118   if FSelected<>nil then begin
119     DescriptionMemo.Text:=FSelected.LongDescription;
120   end else begin
121     DescriptionMemo.Text:=lisCTPleaseSelectAMacro;
122   end;
123 end;
124 
125 procedure TCodeMacroSelectDlg.FillMacrosListbox;
126 var
127   i: Integer;
128 begin
129   with MacrosListBox.Items do begin
130     BeginUpdate;
131     Clear;
132     for i:=0 to IDECodeMacros.Count-1 do
133       Add(IDECodeMacros[i].Name);
134     EndUpdate;
135   end;
136 end;
137 
138 end.
139 
140