source: branches/generator/Forms/UFormLookupTables.pas

Last change on this file was 192, checked in by chronos, 6 years ago
  • Modified: Apply interface language to all forms.
File size: 5.0 KB
Line 
1unit UFormLookupTables;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 ActnList, Menus, UListViewSort, UGrammer;
10
11type
12
13 { TFormLookupTables }
14
15 TFormLookupTables = class(TForm)
16 AAdd: TAction;
17 ActionList1: TActionList;
18 AModify: TAction;
19 ARemove: TAction;
20 CoolBar1: TCoolBar;
21 ListView1: TListView;
22 ListViewSort1: TListViewSort;
23 MenuItem1: TMenuItem;
24 MenuItem2: TMenuItem;
25 MenuItem3: TMenuItem;
26 PopupMenu1: TPopupMenu;
27 ToolBar1: TToolBar;
28 ToolButton1: TToolButton;
29 ToolButton2: TToolButton;
30 ToolButton3: TToolButton;
31 procedure AAddExecute(Sender: TObject);
32 procedure AModifyExecute(Sender: TObject);
33 procedure ARemoveExecute(Sender: TObject);
34 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
35 procedure FormCreate(Sender: TObject);
36 procedure FormShow(Sender: TObject);
37 procedure ListView1Data(Sender: TObject; Item: TListItem);
38 procedure ListView1DblClick(Sender: TObject);
39 procedure ListView1KeyPress(Sender: TObject; var Key: char);
40 procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
41 Selected: Boolean);
42 function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
43 procedure ListViewSort1Filter(ListViewSort: TListViewSort);
44 private
45
46 public
47 LookupTables: TLookupTables;
48 procedure ReloadList;
49 procedure UpdateInterface;
50 end;
51
52var
53 FormLookupTables: TFormLookupTables;
54
55
56implementation
57
58uses
59 UFormLookupTable, UCore;
60
61{$R *.lfm}
62
63{ TFormLookupTables }
64
65procedure TFormLookupTables.AAddExecute(Sender: TObject);
66var
67 NewItem: TLookupTable;
68begin
69 NewItem := TLookupTable.Create;
70 NewItem.Grammer := LookupTables.Grammer;
71 FormLookupTable := TFormLookupTable.Create(nil);
72 FormLookupTable.LoadData(NewItem);
73 if FormLookupTable.ShowModal = mrOk then begin
74 FormLookupTable.SaveData(NewItem);
75 LookupTables.Add(NewItem);
76 ReloadList;
77 end else FreeAndNil(NewItem);
78 FreeAndNil(FormLookupTable);
79end;
80
81procedure TFormLookupTables.AModifyExecute(Sender: TObject);
82var
83 Item: TLookupTable;
84 FormItem: TFormLookupTable;
85begin
86 if Assigned(ListView1.Selected) then begin
87 Item := TLookupTable(ListView1.Selected.Data);
88 FormItem := TFormLookupTable.Create(nil);
89 FormItem.LoadData(Item);
90 if FormItem.ShowModal = mrOk then begin
91 FormItem.SaveData(Item);
92 ReloadList;
93 end;
94 FreeAndNil(FormItem);
95 end;
96end;
97
98procedure TFormLookupTables.ARemoveExecute(Sender: TObject);
99var
100 I: Integer;
101begin
102 if MessageDlg('Remove item(s)', 'Do you want to remove selected item(s)?',
103 mtConfirmation, mbYesNo, 0) = mrYes then
104 for I := ListView1.Items.Count - 1 downto 0 do
105 if ListView1.Items[I].Selected then begin
106 LookupTables.Grammer.Modified := True;
107 LookupTables.Remove(TLookupTable(ListView1.Items[I].Data));
108 end;
109 ReloadList;
110end;
111
112procedure TFormLookupTables.FormClose(Sender: TObject;
113 var CloseAction: TCloseAction);
114begin
115 Core.PersistentForm1.Save(Self);
116end;
117
118procedure TFormLookupTables.FormCreate(Sender: TObject);
119begin
120 Core.CoolTranslator1.TranslateComponentRecursive(Self);
121 LookupTables := nil;
122end;
123
124procedure TFormLookupTables.FormShow(Sender: TObject);
125begin
126 Core.PersistentForm1.Load(Self);
127 ReloadList;
128 UpdateInterface;
129end;
130
131procedure TFormLookupTables.ListView1Data(Sender: TObject; Item: TListItem);
132begin
133 if (Item.Index >= 0) and (Item.Index < ListViewSort1.List.Count) then
134 with TLookupTable(ListViewSort1.List[Item.Index]) do begin
135 Item.Caption := Name;
136 Item.Data := ListViewSort1.List[Item.Index];
137 end;
138end;
139
140procedure TFormLookupTables.ListView1DblClick(Sender: TObject);
141begin
142 AModify.Execute;
143end;
144
145procedure TFormLookupTables.ListView1KeyPress(Sender: TObject; var Key: char);
146begin
147 if Key = #13 then AModify.Execute;
148end;
149
150procedure TFormLookupTables.ListView1SelectItem(Sender: TObject;
151 Item: TListItem; Selected: Boolean);
152begin
153 UpdateInterface;
154end;
155
156function TFormLookupTables.ListViewSort1CompareItem(Item1, Item2: TObject
157 ): Integer;
158begin
159 Result := 0;
160 if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
161 with ListViewSort1 do
162 case Column of
163 0: Result := CompareString(TLookupTable(Item1).Name, TLookupTable(Item2).Name);
164 end;
165 if ListViewSort1.Order = soDown then Result := -Result;
166 end else Result := 0;
167end;
168
169procedure TFormLookupTables.ListViewSort1Filter(ListViewSort: TListViewSort);
170var
171 I: Integer;
172begin
173 if Assigned(LookupTables) then begin
174 ListViewSort1.List.Count := LookupTables.Count;
175 for I := 0 to LookupTables.Count - 1 do
176 ListViewSort1.List[I] := LookupTables[I];
177 end else ListViewSort1.List.Count := 0;
178end;
179
180procedure TFormLookupTables.ReloadList;
181begin
182 ListViewSort1.Refresh;
183 ListView1.Refresh;
184end;
185
186procedure TFormLookupTables.UpdateInterface;
187begin
188 AAdd.Enabled := Assigned(LookupTables);
189 AModify.Enabled := Assigned(LookupTables) and Assigned(ListView1.Selected);
190 ARemove.Enabled := Assigned(LookupTables) and Assigned(ListView1.Selected);
191end;
192
193end.
194
Note: See TracBrowser for help on using the repository browser.