source: tags/1.3.1/Forms/UFormImportFormat.pas

Last change on this file was 96, checked in by chronos, 8 years ago
  • Fixed: Dynamically created forms were not translated.
File size: 5.6 KB
Line 
1unit UFormImportFormat;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ComCtrls, Menus, ActnList, UAcronym;
10
11type
12
13 { TFormImportFormat }
14
15 TFormImportFormat = class(TForm)
16 AAdd: TAction;
17 AMoveUp: TAction;
18 AMoveDown: TAction;
19 AModify: TAction;
20 ARemove: TAction;
21 ActionList1: TActionList;
22 ButtonOk: TButton;
23 ButtonCancel: TButton;
24 ComboBoxType: TComboBox;
25 EditBlockEnd: TEdit;
26 EditBlockStart: TEdit;
27 EditName: TEdit;
28 Label1: TLabel;
29 Label2: TLabel;
30 Label3: TLabel;
31 Label8: TLabel;
32 Label9: TLabel;
33 ListViewItemRules: TListView;
34 MenuItem1: TMenuItem;
35 MenuItem2: TMenuItem;
36 MenuItem3: TMenuItem;
37 MenuItem4: TMenuItem;
38 MenuItem5: TMenuItem;
39 PopupMenu1: TPopupMenu;
40 procedure AAddExecute(Sender: TObject);
41 procedure AModifyExecute(Sender: TObject);
42 procedure AMoveDownExecute(Sender: TObject);
43 procedure AMoveUpExecute(Sender: TObject);
44 procedure ARemoveExecute(Sender: TObject);
45 procedure FormCreate(Sender: TObject);
46 procedure FormShow(Sender: TObject);
47 procedure ListViewItemRulesData(Sender: TObject; Item: TListItem);
48 private
49 { private declarations }
50 public
51 ImportFormat: TImportFormat;
52 procedure Load(ImportFormat: TImportFormat);
53 procedure Save(ImportFormat: TImportFormat);
54 procedure ReloadList;
55 end;
56
57var
58 FormImportFormat: TFormImportFormat;
59 YesNoString: array[Boolean] of string;
60
61
62implementation
63
64uses
65 UCore, UFormImportPattern;
66
67{$R *.lfm}
68
69resourcestring
70 SRemoveImportPattern = 'Remove import pattern';
71 SRemoveImportPatternQuery = 'Do you really want to remove selected import patterns?';
72 SYes = 'Yes';
73 SNo = 'No';
74
75
76{ TFormImportFormat }
77
78procedure TFormImportFormat.AAddExecute(Sender: TObject);
79var
80 NewImportPattern: TImportPattern;
81begin
82 FormImportPattern := TFormImportPattern.Create(Self);
83 try
84 NewImportPattern := TImportPattern.Create;
85 FormImportPattern.Load(NewImportPattern);
86 if FormImportPattern.ShowModal = mrOk then begin
87 FormImportPattern.Save(NewImportPattern);
88 ImportFormat.ItemPatterns.Add(NewImportPattern);
89 NewImportPattern := nil;
90 ReloadList;
91 end;
92 if Assigned(NewImportPattern) then NewImportPattern.Free;
93 finally
94 FreeAndNil(FormImportPattern);
95 end;
96end;
97
98procedure TFormImportFormat.AModifyExecute(Sender: TObject);
99var
100 NewImportPattern: TImportPattern;
101begin
102 FormImportPattern := TFormImportPattern.Create(Self);
103 try
104 if Assigned(ListViewItemRules.Selected) then begin
105 NewImportPattern := TImportPattern.Create;
106 NewImportPattern.Assign(ListViewItemRules.Selected.Data);
107 FormImportPattern.Load(NewImportPattern);
108 if FormImportPattern.ShowModal = mrOk then begin
109 FormImportPattern.Save(NewImportPattern);
110 TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
111 ReloadList;
112 end;
113 if Assigned(NewImportPattern) then NewImportPattern.Free;
114 end;
115 finally
116 FreeAndNil(FormImportPattern);
117 end;
118end;
119
120procedure TFormImportFormat.AMoveDownExecute(Sender: TObject);
121begin
122 if ListViewItemRules.Selected.Index < (ImportFormat.ItemPatterns.Count - 1) then
123 with ImportFormat do
124 ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
125 ListViewItemRules.Selected.Index + 1);
126 ReloadList;
127end;
128
129procedure TFormImportFormat.AMoveUpExecute(Sender: TObject);
130begin
131 if ListViewItemRules.Selected.Index > 0 then
132 with ImportFormat do
133 ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
134 ListViewItemRules.Selected.Index - 1);
135 ReloadList;
136end;
137
138procedure TFormImportFormat.ARemoveExecute(Sender: TObject);
139var
140 I: Integer;
141begin
142 if Assigned(ListViewItemRules.Selected) then begin
143 if MessageDlg(SRemoveImportPattern, SRemoveImportPatternQuery,
144 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
145 for I := ListViewItemRules.Items.Count - 1 downto 0 do
146 if ListViewItemRules.Items[I].Selected then
147 ImportFormat.ItemPatterns.Remove(ListViewItemRules.Items[I].Data);
148 ReloadList;
149 end;
150 end;
151end;
152
153procedure TFormImportFormat.FormCreate(Sender: TObject);
154begin
155 Core.CoolTranslator1.TranslateComponentRecursive(Self);
156 YesNoString[False] := SNo;
157 YesNoString[True] := SYes;
158end;
159
160procedure TFormImportFormat.FormShow(Sender: TObject);
161begin
162 ReloadList;
163end;
164
165procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
166 Item: TListItem);
167begin
168 if Item.Index < ImportFormat.ItemPatterns.Count then
169 with TImportPattern(ImportFormat.ItemPatterns[Item.Index]) do begin
170 Item.Caption := StartString;
171 Item.SubItems.Add(EndString);
172 Item.SubItems.Add(ImportPatternFlagString[Flag]);
173 Item.SubItems.Add(ImportVariableString[Variable]);
174 Item.SubItems.Add(YesNoString[Repetition]);
175 Item.Data := ImportFormat.ItemPatterns[Item.Index];
176 end;
177end;
178
179procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
180begin
181 ComboBoxType.ItemIndex := Integer(ImportFormat.Kind);
182 Self.ImportFormat := ImportFormat;
183 EditName.Text := ImportFormat.Name;
184 EditBlockStart.Text := ImportFormat.Block.StartString;
185 EditBlockEnd.Text := ImportFormat.Block.EndString;
186 ReloadList;
187end;
188
189procedure TFormImportFormat.Save(ImportFormat: TImportFormat);
190begin
191 ImportFormat.Kind := TImportFormatKind(ComboBoxType.ItemIndex);
192 ImportFormat.Name := EditName.Text;
193 ImportFormat.Block.StartString := EditBlockStart.Text;
194 ImportFormat.Block.EndString := EditBlockEnd.Text;
195end;
196
197procedure TFormImportFormat.ReloadList;
198begin
199 ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
200 ListViewItemRules.Refresh;
201end;
202
203end.
204
Note: See TracBrowser for help on using the repository browser.