source: trunk/Forms/FormImportFormat.pas

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