1 | unit UFormMain;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
---|
9 | ComCtrls, StdCtrls, ExtCtrls, ActnList, UAcronym, UPersistentForm, URegistry,
|
---|
10 | ULastOpenedList, UListViewSort, UJobProgressView, UCoolTranslator, Registry,
|
---|
11 | SpecializedList, LazUTF8;
|
---|
12 |
|
---|
13 | type
|
---|
14 |
|
---|
15 | { TFormMain }
|
---|
16 |
|
---|
17 | TFormMain = class(TForm)
|
---|
18 | AProcessImports: TAction;
|
---|
19 | AShowImportFormats: TAction;
|
---|
20 | AShowAbout: TAction;
|
---|
21 | AShowImportSources: TAction;
|
---|
22 | AShowAcronyms: TAction;
|
---|
23 | AShowCategories: TAction;
|
---|
24 | ASettings: TAction;
|
---|
25 | AFileSaveAs: TAction;
|
---|
26 | AFileClose: TAction;
|
---|
27 | AFileSave: TAction;
|
---|
28 | AFileNew: TAction;
|
---|
29 | AFileOpen: TAction;
|
---|
30 | AManualImport: TAction;
|
---|
31 | AShow: TAction;
|
---|
32 | AExit: TAction;
|
---|
33 | ActionList1: TActionList;
|
---|
34 | CheckBoxExactMath: TCheckBox;
|
---|
35 | CoolTranslator1: TCoolTranslator;
|
---|
36 | ImageList1: TImageList;
|
---|
37 | JobProgressView1: TJobProgressView;
|
---|
38 | LastOpenedList1: TLastOpenedList;
|
---|
39 | ListViewAcronyms: TListView;
|
---|
40 | ListViewFilter1: TListViewFilter;
|
---|
41 | ListViewSort1: TListViewSort;
|
---|
42 | MainMenu1: TMainMenu;
|
---|
43 | MenuItem1: TMenuItem;
|
---|
44 | MenuItem10: TMenuItem;
|
---|
45 | MenuItem11: TMenuItem;
|
---|
46 | MenuItem12: TMenuItem;
|
---|
47 | MenuItem13: TMenuItem;
|
---|
48 | MenuItem14: TMenuItem;
|
---|
49 | MenuItem15: TMenuItem;
|
---|
50 | MenuItem16: TMenuItem;
|
---|
51 | MenuItem17: TMenuItem;
|
---|
52 | MenuItem18: TMenuItem;
|
---|
53 | MenuItem19: TMenuItem;
|
---|
54 | MenuItem20: TMenuItem;
|
---|
55 | MenuItem21: TMenuItem;
|
---|
56 | MenuItem22: TMenuItem;
|
---|
57 | MenuItem23: TMenuItem;
|
---|
58 | MenuItem24: TMenuItem;
|
---|
59 | MenuItemToolbar: TMenuItem;
|
---|
60 | MenuItem4: TMenuItem;
|
---|
61 | MenuItem5: TMenuItem;
|
---|
62 | MenuItem6: TMenuItem;
|
---|
63 | MenuItem7: TMenuItem;
|
---|
64 | MenuItemOpenRecent: TMenuItem;
|
---|
65 | MenuItem2: TMenuItem;
|
---|
66 | MenuItem3: TMenuItem;
|
---|
67 | MenuItem8: TMenuItem;
|
---|
68 | MenuItem9: TMenuItem;
|
---|
69 | OpenDialog1: TOpenDialog;
|
---|
70 | Panel1: TPanel;
|
---|
71 | PersistentForm1: TPersistentForm;
|
---|
72 | PopupMenuTryIcon: TPopupMenu;
|
---|
73 | SaveDialog1: TSaveDialog;
|
---|
74 | ToolBar1: TToolBar;
|
---|
75 | ToolButton1: TToolButton;
|
---|
76 | ToolButton10: TToolButton;
|
---|
77 | ToolButton11: TToolButton;
|
---|
78 | ToolButton2: TToolButton;
|
---|
79 | ToolButton3: TToolButton;
|
---|
80 | ToolButton4: TToolButton;
|
---|
81 | ToolButton5: TToolButton;
|
---|
82 | ToolButton6: TToolButton;
|
---|
83 | ToolButton7: TToolButton;
|
---|
84 | ToolButton8: TToolButton;
|
---|
85 | ToolButton9: TToolButton;
|
---|
86 | TrayIcon1: TTrayIcon;
|
---|
87 | procedure AExitExecute(Sender: TObject);
|
---|
88 | procedure AFileCloseExecute(Sender: TObject);
|
---|
89 | procedure AFileNewExecute(Sender: TObject);
|
---|
90 | procedure AFileOpenExecute(Sender: TObject);
|
---|
91 | procedure AFileSaveAsExecute(Sender: TObject);
|
---|
92 | procedure AFileSaveExecute(Sender: TObject);
|
---|
93 | procedure AManualImportExecute(Sender: TObject);
|
---|
94 | procedure AProcessImportsExecute(Sender: TObject);
|
---|
95 | procedure ASettingsExecute(Sender: TObject);
|
---|
96 | procedure AShowAboutExecute(Sender: TObject);
|
---|
97 | procedure AShowAcronymsExecute(Sender: TObject);
|
---|
98 | procedure AShowCategoriesExecute(Sender: TObject);
|
---|
99 | procedure AShowExecute(Sender: TObject);
|
---|
100 | procedure AShowImportFormatsExecute(Sender: TObject);
|
---|
101 | procedure AShowImportSourcesExecute(Sender: TObject);
|
---|
102 | procedure CheckBoxExactMathChange(Sender: TObject);
|
---|
103 | procedure CoolTranslator1Translate(Sender: TObject);
|
---|
104 | procedure EditSearchChange(Sender: TObject);
|
---|
105 | procedure FormShow(Sender: TObject);
|
---|
106 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
107 | procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
108 | procedure FormCreate(Sender: TObject);
|
---|
109 | procedure FormDestroy(Sender: TObject);
|
---|
110 | procedure LastOpenedList1Change(Sender: TObject);
|
---|
111 | procedure ListViewAcronymsData(Sender: TObject; Item: TListItem);
|
---|
112 | procedure ListViewAcronymsResize(Sender: TObject);
|
---|
113 | procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem;
|
---|
114 | Selected: Boolean);
|
---|
115 | procedure ListViewFilter1Change(Sender: TObject);
|
---|
116 | function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
---|
117 | procedure ListViewSort1Filter(ListViewSort: TListViewSort);
|
---|
118 | procedure MenuItemToolbarClick(Sender: TObject);
|
---|
119 | procedure TrayIcon1Click(Sender: TObject);
|
---|
120 | private
|
---|
121 | FAlwaysOnTop: Boolean;
|
---|
122 | RegistryContext: TRegistryContext;
|
---|
123 | ProjectClosed: Boolean;
|
---|
124 | ImportTotalItemCount: Integer;
|
---|
125 | procedure ProcessImportsJob(Job: TJob);
|
---|
126 | procedure SetAlwaysOnTop(AValue: Boolean);
|
---|
127 | procedure FilterList(List: TListObject);
|
---|
128 | procedure OpenRecentClick(Sender: TObject);
|
---|
129 | procedure UpdateAcronymsList;
|
---|
130 | procedure UpdateInterface;
|
---|
131 | procedure LoadConfig;
|
---|
132 | procedure SaveConfig;
|
---|
133 | public
|
---|
134 | AcronymDb: TAcronymDb;
|
---|
135 | function CompareStrings(Strings1, Strings2: TStrings): Boolean;
|
---|
136 | property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;
|
---|
137 | end;
|
---|
138 |
|
---|
139 | var
|
---|
140 | FormMain: TFormMain;
|
---|
141 |
|
---|
142 | resourcestring
|
---|
143 | SAddedCount = 'Imported %d acronyms. Added %d new.';
|
---|
144 | SProcessImportSources = 'Process import sources';
|
---|
145 |
|
---|
146 |
|
---|
147 | implementation
|
---|
148 |
|
---|
149 | {$R *.lfm}
|
---|
150 |
|
---|
151 | uses
|
---|
152 | UFormImport, UFormSettings, UFormCategories, UFormAcronyms,
|
---|
153 | UFormImportSources, UFormAbout, UFormImportFormats;
|
---|
154 |
|
---|
155 | resourcestring
|
---|
156 | SModified = 'modified';
|
---|
157 | SAppExit = 'Application exit';
|
---|
158 | SAppExitQuery = 'Acronyms were modified. Do you want to save them to file before exit?';
|
---|
159 |
|
---|
160 | const
|
---|
161 | ProjectExt = '.adp';
|
---|
162 | DefaultFileName = 'Acronyms' + ProjectExt;
|
---|
163 | DefaultRegKey = '\Software\Acronym Decoder';
|
---|
164 |
|
---|
165 | { TFormMain }
|
---|
166 |
|
---|
167 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
168 | begin
|
---|
169 | AcronymDb := TAcronymDb.Create;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | procedure TFormMain.EditSearchChange(Sender: TObject);
|
---|
173 | begin
|
---|
174 | UpdateAcronymsList;
|
---|
175 | end;
|
---|
176 |
|
---|
177 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
178 | begin
|
---|
179 | PersistentForm1.Save(Self);
|
---|
180 | SaveConfig;
|
---|
181 | end;
|
---|
182 |
|
---|
183 | procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
184 | begin
|
---|
185 | AFileClose.Execute;
|
---|
186 | CanClose := ProjectClosed;
|
---|
187 | end;
|
---|
188 |
|
---|
189 | procedure TFormMain.AExitExecute(Sender: TObject);
|
---|
190 | begin
|
---|
191 | Close;
|
---|
192 | end;
|
---|
193 |
|
---|
194 | procedure TFormMain.AFileCloseExecute(Sender: TObject);
|
---|
195 | var
|
---|
196 | ModalResult: TModalResult;
|
---|
197 | DoClose: Boolean;
|
---|
198 | begin
|
---|
199 | DoClose := False;
|
---|
200 | if Assigned(AcronymDb) then begin
|
---|
201 | if AcronymDb.Modified then begin
|
---|
202 | ModalResult := MessageDlg(SAppExit, SAppExitQuery,
|
---|
203 | mtConfirmation, [mbYes, mbNo, mbCancel], 0);
|
---|
204 | if ModalResult = mrYes then begin
|
---|
205 | AFileSave.Execute;
|
---|
206 | DoClose := True;
|
---|
207 | end
|
---|
208 | else if ModalResult = mrNo then begin
|
---|
209 | DoClose := True;
|
---|
210 | end else ProjectClosed := False;
|
---|
211 | end else DoClose := True;
|
---|
212 | end;
|
---|
213 | if DoClose then begin
|
---|
214 | FreeAndNil(AcronymDb);
|
---|
215 | UpdateAcronymsList;
|
---|
216 | UpdateInterface;
|
---|
217 | ProjectClosed := True;
|
---|
218 | end;
|
---|
219 | end;
|
---|
220 |
|
---|
221 | procedure TFormMain.AFileNewExecute(Sender: TObject);
|
---|
222 | begin
|
---|
223 | AFileClose.Execute;
|
---|
224 | if ProjectClosed then begin
|
---|
225 | AcronymDb := TAcronymDb.Create;
|
---|
226 | AcronymDb.FileName := DefaultFileName;
|
---|
227 | AcronymDb.Acronyms.Clear;
|
---|
228 | UpdateAcronymsList;
|
---|
229 | UpdateInterface;
|
---|
230 | end;
|
---|
231 | end;
|
---|
232 |
|
---|
233 | procedure TFormMain.AFileOpenExecute(Sender: TObject);
|
---|
234 | begin
|
---|
235 | OpenDialog1.DefaultExt := ProjectExt;
|
---|
236 | if Assigned(AcronymDb) then
|
---|
237 | OpenDialog1.FileName := AcronymDb.FileName;
|
---|
238 | if OpenDialog1.Execute then begin
|
---|
239 | AFileClose.Execute;
|
---|
240 | if ProjectClosed then begin
|
---|
241 | AFileNew.Execute;
|
---|
242 | AcronymDb.LoadFromFile(OpenDialog1.FileName);
|
---|
243 | LastOpenedList1.AddItem(OpenDialog1.FileName);
|
---|
244 | UpdateAcronymsList;
|
---|
245 | UpdateInterface;
|
---|
246 | end;
|
---|
247 | end;
|
---|
248 | end;
|
---|
249 |
|
---|
250 | procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
|
---|
251 | begin
|
---|
252 | SaveDialog1.DefaultExt := ProjectExt;
|
---|
253 | SaveDialog1.FileName := AcronymDb.FileName;
|
---|
254 | if SaveDialog1.Execute then begin
|
---|
255 | AcronymDb.SaveToFile(SaveDialog1.FileName);
|
---|
256 | LastOpenedList1.AddItem(SaveDialog1.FileName);
|
---|
257 | UpdateInterface;
|
---|
258 | end;
|
---|
259 | end;
|
---|
260 |
|
---|
261 | procedure TFormMain.AFileSaveExecute(Sender: TObject);
|
---|
262 | begin
|
---|
263 | if FileExists(AcronymDb.FileName) then begin
|
---|
264 | AcronymDb.SaveToFile(AcronymDb.FileName);
|
---|
265 | LastOpenedList1.AddItem(AcronymDb.FileName);
|
---|
266 | UpdateInterface;
|
---|
267 | end else AFileSaveAs.Execute;
|
---|
268 | end;
|
---|
269 |
|
---|
270 | procedure TFormMain.AManualImportExecute(Sender: TObject);
|
---|
271 | begin
|
---|
272 | FormImport.ShowModal;
|
---|
273 | UpdateAcronymsList;
|
---|
274 | UpdateInterface;
|
---|
275 | end;
|
---|
276 |
|
---|
277 | procedure TFormMain.AProcessImportsExecute(Sender: TObject);
|
---|
278 | begin
|
---|
279 | ImportTotalItemCount := 0;
|
---|
280 | AcronymDb.AddedCount := 0;
|
---|
281 | JobProgressView1.AddJob(SProcessImportSources, ProcessImportsJob);
|
---|
282 | JobProgressView1.Start;
|
---|
283 | ShowMessage(Format(SAddedCount, [ImportTotalItemCount, AcronymDb.AddedCount]));
|
---|
284 | UpdateAcronymsList;
|
---|
285 | UpdateInterface;
|
---|
286 | end;
|
---|
287 |
|
---|
288 | procedure TFormMain.ProcessImportsJob(Job: TJob);
|
---|
289 | var
|
---|
290 | I: Integer;
|
---|
291 | begin
|
---|
292 | for I := 0 to AcronymDb.ImportSources.Count - 1 do
|
---|
293 | with TImportSource(AcronymDb.ImportSources[I]) do
|
---|
294 | if Enabled then begin
|
---|
295 | Process;
|
---|
296 | ImportTotalItemCount := ImportTotalItemCount + ItemCount;
|
---|
297 | Job.Progress.Max := AcronymDb.ImportSources.Count;
|
---|
298 | Job.Progress.Value := I;
|
---|
299 | if Job.Terminate then Break;
|
---|
300 | end;
|
---|
301 | end;
|
---|
302 |
|
---|
303 | procedure TFormMain.ASettingsExecute(Sender: TObject);
|
---|
304 | begin
|
---|
305 | FormSettings.Load;
|
---|
306 | if FormSettings.ShowModal = mrOk then
|
---|
307 | FormSettings.Save;
|
---|
308 | end;
|
---|
309 |
|
---|
310 | procedure TFormMain.AShowAboutExecute(Sender: TObject);
|
---|
311 | begin
|
---|
312 | FormAbout.ShowModal;
|
---|
313 | end;
|
---|
314 |
|
---|
315 | procedure TFormMain.AShowAcronymsExecute(Sender: TObject);
|
---|
316 | begin
|
---|
317 | FormAcronyms.ShowModal;
|
---|
318 | UpdateInterface;
|
---|
319 | end;
|
---|
320 |
|
---|
321 | procedure TFormMain.AShowCategoriesExecute(Sender: TObject);
|
---|
322 | begin
|
---|
323 | FormCategories.Categories := AcronymDb.Categories;
|
---|
324 | FormCategories.ShowModal;
|
---|
325 | UpdateAcronymsList;
|
---|
326 | UpdateInterface;
|
---|
327 | end;
|
---|
328 |
|
---|
329 | procedure TFormMain.AShowExecute(Sender: TObject);
|
---|
330 | begin
|
---|
331 | Show;
|
---|
332 | end;
|
---|
333 |
|
---|
334 | procedure TFormMain.AShowImportFormatsExecute(Sender: TObject);
|
---|
335 | begin
|
---|
336 | FormImportFormats.ImportFormats := AcronymDb.ImportFormats;
|
---|
337 | FormImportFormats.ShowModal;
|
---|
338 | UpdateInterface;
|
---|
339 | end;
|
---|
340 |
|
---|
341 | procedure TFormMain.AShowImportSourcesExecute(Sender: TObject);
|
---|
342 | begin
|
---|
343 | FormImportSources.ImportSources := AcronymDb.ImportSources;
|
---|
344 | FormImportSources.ShowModal;
|
---|
345 | UpdateInterface;
|
---|
346 | end;
|
---|
347 |
|
---|
348 | procedure TFormMain.CheckBoxExactMathChange(Sender: TObject);
|
---|
349 | begin
|
---|
350 | UpdateAcronymsList;
|
---|
351 | end;
|
---|
352 |
|
---|
353 | procedure TFormMain.CoolTranslator1Translate(Sender: TObject);
|
---|
354 | begin
|
---|
355 | UAcronym.Translate;
|
---|
356 | end;
|
---|
357 |
|
---|
358 | procedure TFormMain.FormDestroy(Sender: TObject);
|
---|
359 | begin
|
---|
360 | FreeAndNil(AcronymDb);
|
---|
361 | end;
|
---|
362 |
|
---|
363 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
364 | var
|
---|
365 | I: Integer;
|
---|
366 | begin
|
---|
367 | LoadConfig;
|
---|
368 | PersistentForm1.Load(Self);
|
---|
369 |
|
---|
370 | if ParamCount > 0 then begin
|
---|
371 | AcronymDB.LoadFromFile(ParamStr(1));
|
---|
372 | LastOpenedList1.AddItem(OpenDialog1.FileName);
|
---|
373 | end else
|
---|
374 | if (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then
|
---|
375 | AcronymDB.LoadFromFile(LastOpenedList1.Items[0]);
|
---|
376 | UpdateAcronymsList;
|
---|
377 | ListViewFilter1.UpdateFromListView(ListViewAcronyms);
|
---|
378 | UpdateInterface;
|
---|
379 | for I := 0 to ToolBar1.ButtonCount - 1 do
|
---|
380 | ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
|
---|
381 | end;
|
---|
382 |
|
---|
383 | procedure TFormMain.LastOpenedList1Change(Sender: TObject);
|
---|
384 | begin
|
---|
385 | LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
|
---|
386 | end;
|
---|
387 |
|
---|
388 | procedure TFormMain.ListViewAcronymsData(Sender: TObject; Item: TListItem);
|
---|
389 | begin
|
---|
390 | if Item.Index < ListViewSort1.List.Count then
|
---|
391 | with TAcronymMeaning(ListViewSort1.List[Item.Index]) do begin
|
---|
392 | Item.Caption := Acronym.Name;
|
---|
393 | Item.SubItems.Add(Name);
|
---|
394 | Item.Data := TAcronymMeaning(ListViewSort1.List[Item.Index]);
|
---|
395 | Item.SubItems.Add(Categories.GetString);
|
---|
396 | end;
|
---|
397 | end;
|
---|
398 |
|
---|
399 | procedure TFormMain.ListViewAcronymsResize(Sender: TObject);
|
---|
400 | begin
|
---|
401 | ListViewFilter1.UpdateFromListView(ListViewAcronyms);
|
---|
402 | end;
|
---|
403 |
|
---|
404 | procedure TFormMain.ListViewAcronymsSelectItem(Sender: TObject;
|
---|
405 | Item: TListItem; Selected: Boolean);
|
---|
406 | begin
|
---|
407 | UpdateInterface;
|
---|
408 | end;
|
---|
409 |
|
---|
410 | procedure TFormMain.ListViewFilter1Change(Sender: TObject);
|
---|
411 | begin
|
---|
412 | UpdateAcronymsList;
|
---|
413 | end;
|
---|
414 |
|
---|
415 | function TFormMain.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
---|
416 | begin
|
---|
417 | Result := 0;
|
---|
418 | if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
|
---|
419 | with ListViewSort1 do
|
---|
420 | case Column of
|
---|
421 | 0: Result := CompareString(TAcronymMeaning(Item1).Acronym.Name, TAcronymMeaning(Item2).Acronym.Name);
|
---|
422 | 1: Result := CompareString(TAcronymMeaning(Item1).Description, TAcronymMeaning(Item2).Description);
|
---|
423 | 2: Result := CompareString(TAcronymMeaning(Item1).Categories.GetString, TAcronymMeaning(Item2).Categories.GetString);
|
---|
424 | end;
|
---|
425 | if ListViewSort1.Order = soDown then Result := -Result;
|
---|
426 | end else Result := 0;
|
---|
427 | end;
|
---|
428 |
|
---|
429 | procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort);
|
---|
430 | begin
|
---|
431 | AcronymDb.Acronyms.Sort(AcronymComparer);
|
---|
432 | AcronymDb.AssignToList(ListViewSort1.List);
|
---|
433 | FilterList(ListViewSort1.List);
|
---|
434 | end;
|
---|
435 |
|
---|
436 | procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
|
---|
437 | begin
|
---|
438 | MenuItemToolbar.Checked := not MenuItemToolbar.Checked;
|
---|
439 | UpdateInterface;
|
---|
440 | end;
|
---|
441 |
|
---|
442 | procedure TFormMain.TrayIcon1Click(Sender: TObject);
|
---|
443 | begin
|
---|
444 | Visible := not Visible;
|
---|
445 | end;
|
---|
446 |
|
---|
447 | function TFormMain.CompareStrings(Strings1, Strings2: TStrings): Boolean;
|
---|
448 | var
|
---|
449 | I: Integer;
|
---|
450 | begin
|
---|
451 | Result := Strings1.Count = Strings2.Count;
|
---|
452 | if not Result then Exit;
|
---|
453 | for I := 0 to Strings1.Count - 1 do
|
---|
454 | if (Strings1[I] <> Strings2[I]) or (Strings1.Objects[I] <> Strings2.Objects[I]) then begin
|
---|
455 | Result := False;
|
---|
456 | Exit;
|
---|
457 | end;
|
---|
458 | end;
|
---|
459 |
|
---|
460 | procedure TFormMain.SetAlwaysOnTop(AValue: Boolean);
|
---|
461 | begin
|
---|
462 | if FAlwaysOnTop = AValue then Exit;
|
---|
463 | FAlwaysOnTop := AValue;
|
---|
464 | if FAlwaysOnTop then FormStyle := fsSystemStayOnTop
|
---|
465 | else FormStyle := fsNormal;
|
---|
466 | end;
|
---|
467 |
|
---|
468 | procedure TFormMain.FilterList(List: TListObject);
|
---|
469 | var
|
---|
470 | I: Integer;
|
---|
471 | FoundCount: Integer;
|
---|
472 | EnteredCount: Integer;
|
---|
473 | begin
|
---|
474 | EnteredCount := ListViewFilter1.TextEnteredCount;
|
---|
475 | for I := List.Count - 1 downto 0 do begin
|
---|
476 | if List.Items[I] is TAcronymMeaning then begin
|
---|
477 | with TAcronymMeaning(List.Items[I]) do begin
|
---|
478 | with ListViewFilter1 do
|
---|
479 | if Visible and (EnteredCount > 0) then begin
|
---|
480 | FoundCount := 0;
|
---|
481 | if CheckBoxExactMath.Checked then begin
|
---|
482 | if TextEnteredColumn(0) and (StringGrid.Cells[0, 0] =
|
---|
483 | TAcronymMeaning(List.Items[I]).Acronym.Name) then Inc(FoundCount);
|
---|
484 | if TextEnteredColumn(1) and (StringGrid.Cells[1, 0] =
|
---|
485 | TAcronymMeaning(List.Items[I]).Name) then Inc(FoundCount);
|
---|
486 | if TextEnteredColumn(2) and (StringGrid.Cells[2, 0] =
|
---|
487 | TAcronymMeaning(List.Items[I]).Categories.GetString) then Inc(FoundCount);
|
---|
488 | end else begin
|
---|
489 | if Pos(UTF8LowerCase(StringGrid.Cells[0, 0]),
|
---|
490 | UTF8LowerCase(TAcronymMeaning(List.Items[I]).Acronym.Name)) > 0 then Inc(FoundCount);
|
---|
491 | if Pos(UTF8LowerCase(StringGrid.Cells[1, 0]),
|
---|
492 | UTF8LowerCase(TAcronymMeaning(List.Items[I]).Name)) > 0 then Inc(FoundCount);
|
---|
493 | if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]),
|
---|
494 | UTF8LowerCase(TAcronymMeaning(List.Items[I]).Categories.GetString)) > 0 then Inc(FoundCount);
|
---|
495 | end;
|
---|
496 | if FoundCount <> EnteredCount then List.Delete(I);
|
---|
497 | end else List.Delete(I);
|
---|
498 | end;
|
---|
499 | end else
|
---|
500 | if TAcronymMeaning(List.Items[I]) is TAcronymMeaning then begin
|
---|
501 | List.Delete(I);
|
---|
502 | end;
|
---|
503 | end;
|
---|
504 | end;
|
---|
505 |
|
---|
506 | procedure TFormMain.OpenRecentClick(Sender: TObject);
|
---|
507 | begin
|
---|
508 | AFileClose.Execute;
|
---|
509 | if ProjectClosed then begin
|
---|
510 | AFileNew.Execute;
|
---|
511 | AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
|
---|
512 | LastOpenedList1.AddItem(TMenuItem(Sender).Caption);
|
---|
513 | UpdateAcronymsList;
|
---|
514 | UpdateInterface;
|
---|
515 | end;
|
---|
516 | end;
|
---|
517 |
|
---|
518 | procedure TFormMain.UpdateAcronymsList;
|
---|
519 | begin
|
---|
520 | if Assigned(AcronymDb) then begin
|
---|
521 | ListViewSort1.Refresh;
|
---|
522 | end else ListViewSort1.List.Clear;
|
---|
523 | end;
|
---|
524 |
|
---|
525 | procedure TFormMain.UpdateInterface;
|
---|
526 | var
|
---|
527 | Title: string;
|
---|
528 | begin
|
---|
529 | ListViewAcronyms.Enabled := Assigned(AcronymDb);
|
---|
530 | AFileClose.Enabled := Assigned(AcronymDb);
|
---|
531 | AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified;
|
---|
532 | AFileSaveAs.Enabled := Assigned(AcronymDb);
|
---|
533 | AManualImport.Enabled := Assigned(AcronymDb);
|
---|
534 | AProcessImports.Enabled := Assigned(AcronymDb);
|
---|
535 | AShowCategories.Enabled := Assigned(AcronymDb);
|
---|
536 | AShowAcronyms.Enabled := Assigned(AcronymDb);
|
---|
537 | AShowCategories.Enabled := Assigned(AcronymDb);
|
---|
538 | AShowImportSources.Enabled := Assigned(AcronymDb);
|
---|
539 | AShowImportFormats.Enabled := Assigned(AcronymDb);
|
---|
540 | ToolBar1.Visible := MenuItemToolbar.Checked;
|
---|
541 |
|
---|
542 | Title := Application.Title;
|
---|
543 | if Assigned(AcronymDb) and (ExtractFileName(AcronymDb.FileName) <> '') then
|
---|
544 | if Assigned(AcronymDb) then Title := Title + ' - ' + ExtractFileName(AcronymDb.FileName);
|
---|
545 | if Assigned(AcronymDb) and AcronymDb.Modified then Title := Title + ' (' + SModified + ')';
|
---|
546 | Caption := Title;
|
---|
547 | end;
|
---|
548 |
|
---|
549 | procedure TFormMain.LoadConfig;
|
---|
550 | begin
|
---|
551 | RegistryContext := RegContext(HKEY_CURRENT_USER, DefaultRegKey);
|
---|
552 | PersistentForm1.RegistryContext := RegistryContext;
|
---|
553 | LastOpenedList1.LoadFromRegistry(RegistryContext);
|
---|
554 |
|
---|
555 | with TRegistryEx.Create do
|
---|
556 | try
|
---|
557 | RootKey := HKEY_CURRENT_USER;
|
---|
558 | OpenKey(DefaultRegKey, True);
|
---|
559 | if ValueExists('LanguageCode') then
|
---|
560 | CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
|
---|
561 | else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
|
---|
562 | AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False);
|
---|
563 | CheckBoxExactMath.Checked := ReadBoolWithDefault('ExactMatch', False);
|
---|
564 | MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True);
|
---|
565 | finally
|
---|
566 | Free;
|
---|
567 | end;
|
---|
568 | end;
|
---|
569 |
|
---|
570 | procedure TFormMain.SaveConfig;
|
---|
571 | begin
|
---|
572 | LastOpenedList1.SaveToRegistry(RegistryContext);
|
---|
573 |
|
---|
574 | with TRegistryEx.Create do
|
---|
575 | try
|
---|
576 | RootKey := HKEY_CURRENT_USER;
|
---|
577 | OpenKey(DefaultRegKey, True);
|
---|
578 | if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
|
---|
579 | WriteString('LanguageCode', CoolTranslator1.Language.Code)
|
---|
580 | else DeleteValue('LanguageCode');
|
---|
581 | WriteBool('AlwaysOnTop', AlwaysOnTop);
|
---|
582 | WriteBool('ExactMatch', CheckBoxExactMath.Checked);
|
---|
583 | WriteBool('ToolBarVisible', MenuItemToolbar.Checked);
|
---|
584 | finally
|
---|
585 | Free;
|
---|
586 | end;
|
---|
587 | end;
|
---|
588 |
|
---|
589 | end.
|
---|
590 |
|
---|