source: trunk/Forms/UFormImportFormat.pas

Last change on this file was 207, checked in by chronos, 3 years ago
  • Modified: Updated Common package.
  • Modified: CoolTranslator package merged into Common package.
  • Fixed: Build with Lazarus 2.0.12
File size: 5.9 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.Translator.TranslateComponentRecursive(Self);
163 Core.ThemeManager.UseTheme(Self);
164 YesNoString[False] := SNo;
165 YesNoString[True] := SYes;
166end;
167
168procedure TFormImportFormat.FormShow(Sender: TObject);
169begin
170 Core.PersistentForm1.Load(Self);
171 ReloadList;
172end;
173
174procedure TFormImportFormat.ListViewItemRulesData(Sender: TObject;
175 Item: TListItem);
176begin
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;
186end;
187
188procedure TFormImportFormat.Load(ImportFormat: TImportFormat);
189begin
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;
196end;
197
198procedure TFormImportFormat.Save(ImportFormat: TImportFormat);
199begin
200 ImportFormat.Kind := TImportFormatKind(ComboBoxType.ItemIndex);
201 ImportFormat.Name := EditName.Text;
202 ImportFormat.Block.StartString := EditBlockStart.Text;
203 ImportFormat.Block.EndString := EditBlockEnd.Text;
204end;
205
206procedure TFormImportFormat.ReloadList;
207begin
208 ListViewItemRules.Items.Count := ImportFormat.ItemPatterns.Count;
209 ListViewItemRules.Refresh;
210end;
211
212end.
213
Note: See TracBrowser for help on using the repository browser.