1 | unit UFormImportFormat;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
9 | ComCtrls, Menus, ActnList, UAcronym;
|
---|
10 |
|
---|
11 | type
|
---|
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 FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
46 | procedure FormCreate(Sender: TObject);
|
---|
47 | procedure FormShow(Sender: TObject);
|
---|
48 | procedure ListViewItemRulesData(Sender: TObject; Item: TListItem);
|
---|
49 | private
|
---|
50 | { private declarations }
|
---|
51 | public
|
---|
52 | ImportFormat: TImportFormat;
|
---|
53 | procedure Load(ImportFormat: TImportFormat);
|
---|
54 | procedure Save(ImportFormat: TImportFormat);
|
---|
55 | procedure ReloadList;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | var
|
---|
59 | FormImportFormat: TFormImportFormat;
|
---|
60 | YesNoString: array[Boolean] of string;
|
---|
61 |
|
---|
62 |
|
---|
63 | implementation
|
---|
64 |
|
---|
65 | uses
|
---|
66 | UCore, UFormImportPattern;
|
---|
67 |
|
---|
68 | {$R *.lfm}
|
---|
69 |
|
---|
70 | resourcestring
|
---|
71 | SRemoveImportPattern = 'Remove import pattern';
|
---|
72 | SRemoveImportPatternQuery = 'Do you really want to remove selected import patterns?';
|
---|
73 | SYes = 'Yes';
|
---|
74 | SNo = 'No';
|
---|
75 |
|
---|
76 |
|
---|
77 | { TFormImportFormat }
|
---|
78 |
|
---|
79 | procedure TFormImportFormat.AAddExecute(Sender: TObject);
|
---|
80 | var
|
---|
81 | NewImportPattern: TImportPattern;
|
---|
82 | begin
|
---|
83 | FormImportPattern := TFormImportPattern.Create(Self);
|
---|
84 | try
|
---|
85 | NewImportPattern := TImportPattern.Create;
|
---|
86 | FormImportPattern.Load(NewImportPattern);
|
---|
87 | if FormImportPattern.ShowModal = mrOk then begin
|
---|
88 | FormImportPattern.Save(NewImportPattern);
|
---|
89 | ImportFormat.ItemPatterns.Add(NewImportPattern);
|
---|
90 | NewImportPattern := nil;
|
---|
91 | ReloadList;
|
---|
92 | end;
|
---|
93 | if Assigned(NewImportPattern) then NewImportPattern.Free;
|
---|
94 | finally
|
---|
95 | FreeAndNil(FormImportPattern);
|
---|
96 | end;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TFormImportFormat.AModifyExecute(Sender: TObject);
|
---|
100 | var
|
---|
101 | NewImportPattern: TImportPattern;
|
---|
102 | begin
|
---|
103 | FormImportPattern := TFormImportPattern.Create(Self);
|
---|
104 | try
|
---|
105 | if Assigned(ListViewItemRules.Selected) then begin
|
---|
106 | NewImportPattern := TImportPattern.Create;
|
---|
107 | NewImportPattern.Assign(ListViewItemRules.Selected.Data);
|
---|
108 | FormImportPattern.Load(NewImportPattern);
|
---|
109 | if FormImportPattern.ShowModal = mrOk then begin
|
---|
110 | FormImportPattern.Save(NewImportPattern);
|
---|
111 | TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
|
---|
112 | ReloadList;
|
---|
113 | end;
|
---|
114 | if Assigned(NewImportPattern) then NewImportPattern.Free;
|
---|
115 | end;
|
---|
116 | finally
|
---|
117 | FreeAndNil(FormImportPattern);
|
---|
118 | end;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TFormImportFormat.AMoveDownExecute(Sender: TObject);
|
---|
122 | begin
|
---|
123 | if ListViewItemRules.Selected.Index < (ImportFormat.ItemPatterns.Count - 1) then
|
---|
124 | with ImportFormat do
|
---|
125 | ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
|
---|
126 | ListViewItemRules.Selected.Index + 1);
|
---|
127 | ReloadList;
|
---|
128 | end;
|
---|
129 |
|
---|
130 | procedure TFormImportFormat.AMoveUpExecute(Sender: TObject);
|
---|
131 | begin
|
---|
132 | if ListViewItemRules.Selected.Index > 0 then
|
---|
133 | with ImportFormat do
|
---|
134 | ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
|
---|
135 | ListViewItemRules.Selected.Index - 1);
|
---|
136 | ReloadList;
|
---|
137 | end;
|
---|
138 |
|
---|
139 | procedure TFormImportFormat.ARemoveExecute(Sender: TObject);
|
---|
140 | var
|
---|
141 | I: Integer;
|
---|
142 | begin
|
---|
143 | if Assigned(ListViewItemRules.Selected) then begin
|
---|
144 | if MessageDlg(SRemoveImportPattern, SRemoveImportPatternQuery,
|
---|
145 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
146 | for I := ListViewItemRules.Items.Count - 1 downto 0 do
|
---|
147 | if ListViewItemRules.Items[I].Selected then
|
---|
148 | ImportFormat.ItemPatterns.Remove(ListViewItemRules.Items[I].Data);
|
---|
149 | ReloadList;
|
---|
150 | end;
|
---|
151 | end;
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TFormImportFormat.FormClose(Sender: TObject;
|
---|
155 | var CloseAction: TCloseAction);
|
---|
156 | begin
|
---|
157 | Core.PersistentForm1.Save(Self);
|
---|
158 | end;
|
---|
159 |
|
---|
160 | procedure TFormImportFormat.FormCreate(Sender: TObject);
|
---|
161 | begin
|
---|
162 | Core.CoolTranslator1.TranslateComponentRecursive(Self);
|
---|
163 | Core.ThemeManager.UseTheme(Self);
|
---|
164 | YesNoString[False] := SNo;
|
---|
165 | YesNoString[True] := SYes;
|
---|
166 | end;
|
---|
167 |
|
---|
168 | procedure TFormImportFormat.FormShow(Sender: TObject);
|
---|
169 | begin
|
---|
170 | Core.PersistentForm1.Load(Self);
|
---|
171 | ReloadList;
|
---|
172 | end;
|
---|
173 |
|
---|
174 | procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
|
---|
175 | Item: TListItem);
|
---|
176 | begin
|
---|
177 | if Item.Index < ImportFormat.ItemPatterns.Count then
|
---|
178 | with TImportPattern(ImportFormat.ItemPatterns[Item.Index]) do begin
|
---|
179 | Item.Caption := StartString;
|
---|
180 | Item.SubItems.Add(EndString);
|
---|
181 | Item.SubItems.Add(ImportPatternFlagString[Flag]);
|
---|
182 | Item.SubItems.Add(ImportVariableString[Variable]);
|
---|
183 | Item.SubItems.Add(YesNoString[Repetition]);
|
---|
184 | Item.Data := ImportFormat.ItemPatterns[Item.Index];
|
---|
185 | end;
|
---|
186 | end;
|
---|
187 |
|
---|
188 | procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
|
---|
189 | begin
|
---|
190 | ComboBoxType.ItemIndex := Integer(ImportFormat.Kind);
|
---|
191 | Self.ImportFormat := ImportFormat;
|
---|
192 | EditName.Text := ImportFormat.Name;
|
---|
193 | EditBlockStart.Text := ImportFormat.Block.StartString;
|
---|
194 | EditBlockEnd.Text := ImportFormat.Block.EndString;
|
---|
195 | ReloadList;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | procedure TFormImportFormat.Save(ImportFormat: TImportFormat);
|
---|
199 | begin
|
---|
200 | ImportFormat.Kind := TImportFormatKind(ComboBoxType.ItemIndex);
|
---|
201 | ImportFormat.Name := EditName.Text;
|
---|
202 | ImportFormat.Block.StartString := EditBlockStart.Text;
|
---|
203 | ImportFormat.Block.EndString := EditBlockEnd.Text;
|
---|
204 | end;
|
---|
205 |
|
---|
206 | procedure TFormImportFormat.ReloadList;
|
---|
207 | begin
|
---|
208 | ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
|
---|
209 | ListViewItemRules.Refresh;
|
---|
210 | end;
|
---|
211 |
|
---|
212 | end.
|
---|
213 |
|
---|