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