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 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 |
|
---|
57 | var
|
---|
58 | FormImportFormat: TFormImportFormat;
|
---|
59 | YesNoString: array[Boolean] of string;
|
---|
60 |
|
---|
61 |
|
---|
62 | implementation
|
---|
63 |
|
---|
64 | uses
|
---|
65 | UFormImportPattern;
|
---|
66 |
|
---|
67 | {$R *.lfm}
|
---|
68 |
|
---|
69 | resourcestring
|
---|
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 |
|
---|
78 | procedure TFormImportFormat.AAddExecute(Sender: TObject);
|
---|
79 | var
|
---|
80 | NewImportPattern: TImportPattern;
|
---|
81 | begin
|
---|
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 | end;
|
---|
92 |
|
---|
93 | procedure TFormImportFormat.AModifyExecute(Sender: TObject);
|
---|
94 | var
|
---|
95 | NewImportPattern: TImportPattern;
|
---|
96 | begin
|
---|
97 | if Assigned(ListViewItemRules.Selected) then begin
|
---|
98 | NewImportPattern := TImportPattern.Create;
|
---|
99 | NewImportPattern.Assign(ListViewItemRules.Selected.Data);
|
---|
100 | FormImportPattern.Load(NewImportPattern);
|
---|
101 | if FormImportPattern.ShowModal = mrOk then begin
|
---|
102 | FormImportPattern.Save(NewImportPattern);
|
---|
103 | TImportPattern(ListViewItemRules.Selected.Data).Assign(NewImportPattern);
|
---|
104 | ReloadList;
|
---|
105 | end;
|
---|
106 | if Assigned(NewImportPattern) then NewImportPattern.Free;
|
---|
107 | end;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | procedure TFormImportFormat.AMoveDownExecute(Sender: TObject);
|
---|
111 | begin
|
---|
112 | if ListViewItemRules.Selected.Index < (ImportFormat.ItemPatterns.Count - 1) then
|
---|
113 | with ImportFormat do
|
---|
114 | ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
|
---|
115 | ListViewItemRules.Selected.Index + 1);
|
---|
116 | ReloadList;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TFormImportFormat.AMoveUpExecute(Sender: TObject);
|
---|
120 | begin
|
---|
121 | if ListViewItemRules.Selected.Index > 0 then
|
---|
122 | with ImportFormat do
|
---|
123 | ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
|
---|
124 | ListViewItemRules.Selected.Index - 1);
|
---|
125 | ReloadList;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TFormImportFormat.ARemoveExecute(Sender: TObject);
|
---|
129 | var
|
---|
130 | I: Integer;
|
---|
131 | begin
|
---|
132 | if Assigned(ListViewItemRules.Selected) then begin
|
---|
133 | if MessageDlg(SRemoveImportPattern, SRemoveImportPatternQuery,
|
---|
134 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
135 | for I := ListViewItemRules.Items.Count - 1 downto 0 do
|
---|
136 | if ListViewItemRules.Items[I].Selected then
|
---|
137 | ImportFormat.ItemPatterns.Remove(ListViewItemRules.Items[I].Data);
|
---|
138 | ReloadList;
|
---|
139 | end;
|
---|
140 | end;
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure TFormImportFormat.FormCreate(Sender: TObject);
|
---|
144 | begin
|
---|
145 | YesNoString[False] := SNo;
|
---|
146 | YesNoString[True] := SYes;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TFormImportFormat.FormShow(Sender: TObject);
|
---|
150 | begin
|
---|
151 | ReloadList;
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
|
---|
155 | Item: TListItem);
|
---|
156 | begin
|
---|
157 | if Item.Index < ImportFormat.ItemPatterns.Count then
|
---|
158 | with TImportPattern(ImportFormat.ItemPatterns[Item.Index]) do begin
|
---|
159 | Item.Caption := StartString;
|
---|
160 | Item.SubItems.Add(EndString);
|
---|
161 | Item.SubItems.Add(ImportPatternFlagString[Flag]);
|
---|
162 | Item.SubItems.Add(ImportVariableString[Variable]);
|
---|
163 | Item.SubItems.Add(YesNoString[Repetition]);
|
---|
164 | Item.Data := ImportFormat.ItemPatterns[Item.Index];
|
---|
165 | end;
|
---|
166 | end;
|
---|
167 |
|
---|
168 | procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
|
---|
169 | begin
|
---|
170 | ComboBoxType.ItemIndex := Integer(ImportFormat.Kind);
|
---|
171 | Self.ImportFormat := ImportFormat;
|
---|
172 | EditName.Text := ImportFormat.Name;
|
---|
173 | EditBlockStart.Text := ImportFormat.Block.StartString;
|
---|
174 | EditBlockEnd.Text := ImportFormat.Block.EndString;
|
---|
175 | ReloadList;
|
---|
176 | end;
|
---|
177 |
|
---|
178 | procedure TFormImportFormat.Save(ImportFormat: TImportFormat);
|
---|
179 | begin
|
---|
180 | ImportFormat.Kind := TImportFormatKind(ComboBoxType.ItemIndex);
|
---|
181 | ImportFormat.Name := EditName.Text;
|
---|
182 | ImportFormat.Block.StartString := EditBlockStart.Text;
|
---|
183 | ImportFormat.Block.EndString := EditBlockEnd.Text;
|
---|
184 | end;
|
---|
185 |
|
---|
186 | procedure TFormImportFormat.ReloadList;
|
---|
187 | begin
|
---|
188 | ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
|
---|
189 | ListViewItemRules.Refresh;
|
---|
190 | end;
|
---|
191 |
|
---|
192 | end.
|
---|
193 |
|
---|