source: tags/1.4.0/Forms/UFormImportFormat.pas

Last change on this file was 123, checked in by chronos, 7 years ago
  • Added: Remember width of list view columns after closing the application.
File size: 5.8 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 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
58var
59 FormImportFormat: TFormImportFormat;
60 YesNoString: array[Boolean] of string;
61
62
63implementation
64
65uses
66 UCore, UFormImportPattern;
67
68{$R *.lfm}
69
70resourcestring
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
79procedure TFormImportFormat.AAddExecute(Sender: TObject);
80var
81 NewImportPattern: TImportPattern;
82begin
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;
97end;
98
99procedure TFormImportFormat.AModifyExecute(Sender: TObject);
100var
101 NewImportPattern: TImportPattern;
102begin
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;
119end;
120
121procedure TFormImportFormat.AMoveDownExecute(Sender: TObject);
122begin
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;
128end;
129
130procedure TFormImportFormat.AMoveUpExecute(Sender: TObject);
131begin
132 if ListViewItemRules.Selected.Index > 0 then
133 with ImportFormat do
134 ItemPatterns.Exchange(ListViewItemRules.Selected.Index,
135 ListViewItemRules.Selected.Index - 1);
136 ReloadList;
137end;
138
139procedure TFormImportFormat.ARemoveExecute(Sender: TObject);
140var
141 I: Integer;
142begin
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;
152end;
153
154procedure TFormImportFormat.FormClose(Sender: TObject;
155 var CloseAction: TCloseAction);
156begin
157 Core.PersistentForm1.Save(Self);
158end;
159
160procedure TFormImportFormat.FormCreate(Sender: TObject);
161begin
162 Core.CoolTranslator1.TranslateComponentRecursive(Self);
163 YesNoString[False] := SNo;
164 YesNoString[True] := SYes;
165end;
166
167procedure TFormImportFormat.FormShow(Sender: TObject);
168begin
169 Core.PersistentForm1.Load(Self);
170 ReloadList;
171end;
172
173procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
174 Item: TListItem);
175begin
176 if Item.Index < ImportFormat.ItemPatterns.Count then
177 with TImportPattern(ImportFormat.ItemPatterns[Item.Index]) do begin
178 Item.Caption := StartString;
179 Item.SubItems.Add(EndString);
180 Item.SubItems.Add(ImportPatternFlagString[Flag]);
181 Item.SubItems.Add(ImportVariableString[Variable]);
182 Item.SubItems.Add(YesNoString[Repetition]);
183 Item.Data := ImportFormat.ItemPatterns[Item.Index];
184 end;
185end;
186
187procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
188begin
189 ComboBoxType.ItemIndex := Integer(ImportFormat.Kind);
190 Self.ImportFormat := ImportFormat;
191 EditName.Text := ImportFormat.Name;
192 EditBlockStart.Text := ImportFormat.Block.StartString;
193 EditBlockEnd.Text := ImportFormat.Block.EndString;
194 ReloadList;
195end;
196
197procedure TFormImportFormat.Save(ImportFormat: TImportFormat);
198begin
199 ImportFormat.Kind := TImportFormatKind(ComboBoxType.ItemIndex);
200 ImportFormat.Name := EditName.Text;
201 ImportFormat.Block.StartString := EditBlockStart.Text;
202 ImportFormat.Block.EndString := EditBlockEnd.Text;
203end;
204
205procedure TFormImportFormat.ReloadList;
206begin
207 ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
208 ListViewItemRules.Refresh;
209end;
210
211end.
212
Note: See TracBrowser for help on using the repository browser.