1 | unit FormMain;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
---|
7 | ComCtrls, StdCtrls, ExtCtrls, ActnList, Grids, Acronym, PersistentForm,
|
---|
8 | RegistryEx, LastOpenedList, ListViewSort, JobProgressView, FormAbout,
|
---|
9 | Registry, Generics.Collections, LazUTF8, LazFileUtils, FormEx,
|
---|
10 | FormKeyShortcuts;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TFormMain }
|
---|
15 |
|
---|
16 | TFormMain = class(TFormEx)
|
---|
17 | AFullScreen: TAction;
|
---|
18 | AShowKeyShortCuts: TAction;
|
---|
19 | AFilterShowItemsWithoutFilter: TAction;
|
---|
20 | ADocumentCheck: TAction;
|
---|
21 | AFilterEnabledCategories: TAction;
|
---|
22 | AManageAcronym: TAction;
|
---|
23 | AFilterSameLetterCase: TAction;
|
---|
24 | AFilterSameLength: TAction;
|
---|
25 | AHide: TAction;
|
---|
26 | AExport: TAction;
|
---|
27 | AProcessImports: TAction;
|
---|
28 | AShowImportFormats: TAction;
|
---|
29 | AShowAbout: TAction;
|
---|
30 | AShowImportSources: TAction;
|
---|
31 | AShowAcronyms: TAction;
|
---|
32 | AShowCategories: TAction;
|
---|
33 | ASettings: TAction;
|
---|
34 | AFileSaveAs: TAction;
|
---|
35 | AFileClose: TAction;
|
---|
36 | AFileSave: TAction;
|
---|
37 | AFileNew: TAction;
|
---|
38 | AFileOpen: TAction;
|
---|
39 | AImport: TAction;
|
---|
40 | AShow: TAction;
|
---|
41 | AExit: TAction;
|
---|
42 | ActionList1: TActionList;
|
---|
43 | CheckBoxEnabledCategories: TCheckBox;
|
---|
44 | CheckBoxShowItemsWithoutFilter: TCheckBox;
|
---|
45 | CheckBoxExactLength: TCheckBox;
|
---|
46 | CheckBoxCaseSensitive: TCheckBox;
|
---|
47 | CoolBar1: TCoolBar;
|
---|
48 | JobProgressView1: TJobProgressView;
|
---|
49 | LastOpenedList1: TLastOpenedList;
|
---|
50 | ListViewAcronyms: TListView;
|
---|
51 | ListViewFilter1: TListViewFilter;
|
---|
52 | ListViewSort1: TListViewSort;
|
---|
53 | MainMenu1: TMainMenu;
|
---|
54 | MenuItem1: TMenuItem;
|
---|
55 | MenuItem19: TMenuItem;
|
---|
56 | MenuItem2: TMenuItem;
|
---|
57 | MenuItem26: TMenuItem;
|
---|
58 | MenuItem27: TMenuItem;
|
---|
59 | MenuItem28: TMenuItem;
|
---|
60 | MenuItem29: TMenuItem;
|
---|
61 | N1: TMenuItem;
|
---|
62 | MenuItem3: TMenuItem;
|
---|
63 | MenuItemShowItemsWithoutFilter: TMenuItem;
|
---|
64 | MenuItemStatusBar: TMenuItem;
|
---|
65 | MenuItemParam: TMenuItem;
|
---|
66 | MenuItem10: TMenuItem;
|
---|
67 | MenuItem11: TMenuItem;
|
---|
68 | MenuItem12: TMenuItem;
|
---|
69 | MenuItem13: TMenuItem;
|
---|
70 | MenuItem14: TMenuItem;
|
---|
71 | MenuItem15: TMenuItem;
|
---|
72 | MenuItem16: TMenuItem;
|
---|
73 | MenuItem17: TMenuItem;
|
---|
74 | MenuItem18: TMenuItem;
|
---|
75 | MenuItem20: TMenuItem;
|
---|
76 | MenuItem21: TMenuItem;
|
---|
77 | MenuItem22: TMenuItem;
|
---|
78 | MenuItem23: TMenuItem;
|
---|
79 | MenuItem24: TMenuItem;
|
---|
80 | MenuItem25: TMenuItem;
|
---|
81 | MenuItemToolbar: TMenuItem;
|
---|
82 | MenuItem4: TMenuItem;
|
---|
83 | MenuItem5: TMenuItem;
|
---|
84 | MenuItem6: TMenuItem;
|
---|
85 | MenuItem7: TMenuItem;
|
---|
86 | MenuItemOpenRecent: TMenuItem;
|
---|
87 | MenuItem8: TMenuItem;
|
---|
88 | MenuItem9: TMenuItem;
|
---|
89 | OpenDialog1: TOpenDialog;
|
---|
90 | PanelParam: TPanel;
|
---|
91 | PanelMain: TPanel;
|
---|
92 | PopupMenuFilter: TPopupMenu;
|
---|
93 | PopupMenuOpenRecent: TPopupMenu;
|
---|
94 | SaveDialog1: TSaveDialog;
|
---|
95 | StatusBar1: TStatusBar;
|
---|
96 | ToolBarFile: TToolBar;
|
---|
97 | ToolBarManage: TToolBar;
|
---|
98 | ToolBarOther: TToolBar;
|
---|
99 | ToolBarFilter: TToolBar;
|
---|
100 | ToolButton1: TToolButton;
|
---|
101 | ToolButton11: TToolButton;
|
---|
102 | ToolButton12: TToolButton;
|
---|
103 | ToolButton13: TToolButton;
|
---|
104 | ToolButton16: TToolButton;
|
---|
105 | ToolButton2: TToolButton;
|
---|
106 | ToolButton3: TToolButton;
|
---|
107 | ToolButton4: TToolButton;
|
---|
108 | ToolButton5: TToolButton;
|
---|
109 | ToolButton6: TToolButton;
|
---|
110 | ToolButton7: TToolButton;
|
---|
111 | ToolButton8: TToolButton;
|
---|
112 | ToolButton9: TToolButton;
|
---|
113 | procedure ADocumentCheckExecute(Sender: TObject);
|
---|
114 | procedure AExitExecute(Sender: TObject);
|
---|
115 | procedure AExportExecute(Sender: TObject);
|
---|
116 | procedure AFileCloseExecute(Sender: TObject);
|
---|
117 | procedure AFileNewExecute(Sender: TObject);
|
---|
118 | procedure AFileOpenExecute(Sender: TObject);
|
---|
119 | procedure AFileSaveAsExecute(Sender: TObject);
|
---|
120 | procedure AFileSaveExecute(Sender: TObject);
|
---|
121 | procedure AFilterEnabledCategoriesExecute(Sender: TObject);
|
---|
122 | procedure AFilterSameLetterCaseExecute(Sender: TObject);
|
---|
123 | procedure AFilterSameLengthExecute(Sender: TObject);
|
---|
124 | procedure AFilterShowItemsWithoutFilterExecute(Sender: TObject);
|
---|
125 | procedure AFullScreenExecute(Sender: TObject);
|
---|
126 | procedure AHideExecute(Sender: TObject);
|
---|
127 | procedure AImportExecute(Sender: TObject);
|
---|
128 | procedure AManageAcronymExecute(Sender: TObject);
|
---|
129 | procedure AProcessImportsExecute(Sender: TObject);
|
---|
130 | procedure ASettingsExecute(Sender: TObject);
|
---|
131 | procedure AShowAboutExecute(Sender: TObject);
|
---|
132 | procedure AShowAcronymsExecute(Sender: TObject);
|
---|
133 | procedure AShowCategoriesExecute(Sender: TObject);
|
---|
134 | procedure AShowExecute(Sender: TObject);
|
---|
135 | procedure AShowImportFormatsExecute(Sender: TObject);
|
---|
136 | procedure AShowImportSourcesExecute(Sender: TObject);
|
---|
137 | procedure EditSearchChange(Sender: TObject);
|
---|
138 | procedure FormDestroy(Sender: TObject);
|
---|
139 | procedure FormHide(Sender: TObject);
|
---|
140 | procedure FormResize(Sender: TObject);
|
---|
141 | procedure FormShow(Sender: TObject);
|
---|
142 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
143 | procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
144 | procedure FormCreate(Sender: TObject);
|
---|
145 | procedure LastOpenedList1Change(Sender: TObject);
|
---|
146 | procedure ListViewAcronymsData(Sender: TObject; Item: TListItem);
|
---|
147 | procedure ListViewAcronymsResize(Sender: TObject);
|
---|
148 | procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem;
|
---|
149 | Selected: Boolean);
|
---|
150 | procedure ListViewFilter1Change(Sender: TObject);
|
---|
151 | procedure ListViewSort1ColumnWidthChanged(Sender: TObject);
|
---|
152 | function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
---|
153 | procedure ListViewSort1Filter(ListViewSort: TListViewSort);
|
---|
154 | procedure MenuItemParamClick(Sender: TObject);
|
---|
155 | procedure MenuItemStatusBarClick(Sender: TObject);
|
---|
156 | procedure MenuItemToolbarClick(Sender: TObject);
|
---|
157 | procedure AShowKeyShortcutsExecute(Sender: TObject);
|
---|
158 | private
|
---|
159 | RegistryContext: TRegistryContext;
|
---|
160 | ProjectClosed: Boolean;
|
---|
161 | ImportTotalItemCount: Integer;
|
---|
162 | FormKeyShortcuts: TFormKeyShortcuts;
|
---|
163 | procedure AcronymDbUpdate(Sender: TObject);
|
---|
164 | function FilterCell(Text1, Text2: string): Boolean;
|
---|
165 | procedure ProcessImportsJob(Job: TJob);
|
---|
166 | procedure FilterList(List: TObjectList<TObject>);
|
---|
167 | procedure OpenRecentClick(Sender: TObject);
|
---|
168 | procedure SetToolbarHints;
|
---|
169 | public
|
---|
170 | procedure LoadConfig;
|
---|
171 | procedure SaveConfig;
|
---|
172 | procedure UpdateAcronymsList;
|
---|
173 | procedure UpdateInterface;
|
---|
174 | procedure ProjectOpen(FileName: string);
|
---|
175 | end;
|
---|
176 |
|
---|
177 | const
|
---|
178 | ProjectExt = '.adp';
|
---|
179 |
|
---|
180 | resourcestring
|
---|
181 | SAddedCount = 'Imported %d acronyms. Added %d new.';
|
---|
182 | SProcessImportSources = 'Process import sources';
|
---|
183 | SAcronymsCount = 'Acronyms count: %d';
|
---|
184 | SMeaningsCount = 'Meanings count: %d';
|
---|
185 | SFileFilter = 'Acronym Decoder project (' + ProjectExt + ')|*' + ProjectExt + '|All files|*.*';
|
---|
186 |
|
---|
187 |
|
---|
188 | implementation
|
---|
189 |
|
---|
190 | {$R *.lfm}
|
---|
191 |
|
---|
192 | uses
|
---|
193 | FormImport, FormSettings, FormCategories, FormAcronyms, FormExport,
|
---|
194 | FormImportSources, FormImportFormats, Core, FormCheck;
|
---|
195 |
|
---|
196 | resourcestring
|
---|
197 | SModified = 'modified';
|
---|
198 | SAppExit = 'Application exit';
|
---|
199 | SAppExitQuery = 'Acronyms were modified. Do you want to save them to file before exit?';
|
---|
200 |
|
---|
201 | const
|
---|
202 | DefaultFileName = 'Acronyms' + ProjectExt;
|
---|
203 | RegistryRunKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
|
---|
204 |
|
---|
205 | { TFormMain }
|
---|
206 |
|
---|
207 | procedure TFormMain.SetToolbarHints;
|
---|
208 | var
|
---|
209 | I: Integer;
|
---|
210 | J: Integer;
|
---|
211 | Control: TControl;
|
---|
212 | begin
|
---|
213 | for J := 0 to CoolBar1.ControlCount - 1 do begin
|
---|
214 | Control := CoolBar1.Controls[J];
|
---|
215 | if Control is TToolBar then begin
|
---|
216 | for I := 0 to TToolBar(Control).ButtonCount - 1 do begin
|
---|
217 | TToolBar(Control).Buttons[I].ShowHint := True;
|
---|
218 | TToolBar(Control).Buttons[I].Hint := TToolBar(Control).Buttons[I].Caption;
|
---|
219 | end;
|
---|
220 | end;
|
---|
221 | end;
|
---|
222 | end;
|
---|
223 |
|
---|
224 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
225 | begin
|
---|
226 | SetToolbarHints;
|
---|
227 | PanelMain.ControlStyle := PanelMain.ControlStyle + [csOpaque];
|
---|
228 | PanelParam.ControlStyle := PanelParam.ControlStyle + [csOpaque];
|
---|
229 | end;
|
---|
230 |
|
---|
231 | procedure TFormMain.EditSearchChange(Sender: TObject);
|
---|
232 | begin
|
---|
233 | UpdateAcronymsList;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | procedure TFormMain.FormDestroy(Sender: TObject);
|
---|
237 | begin
|
---|
238 | if Assigned(FormKeyShortcuts) then FreeAndNil(FormKeyShortcuts);
|
---|
239 | end;
|
---|
240 |
|
---|
241 | procedure TFormMain.FormHide(Sender: TObject);
|
---|
242 | begin
|
---|
243 | if Core.Core.InitializeFinished then Core.Core.PersistentForm1.Save(Self);
|
---|
244 | UpdateInterface;
|
---|
245 | end;
|
---|
246 |
|
---|
247 | procedure TFormMain.FormResize(Sender: TObject);
|
---|
248 | begin
|
---|
249 | CoolBar1.AutosizeBands;
|
---|
250 | end;
|
---|
251 |
|
---|
252 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
253 | begin
|
---|
254 | Core.Core.SaveConfig;
|
---|
255 | end;
|
---|
256 |
|
---|
257 | procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
258 | begin
|
---|
259 | ProjectClosed := True;
|
---|
260 | AFileClose.Execute;
|
---|
261 | CanClose := ProjectClosed;
|
---|
262 | end;
|
---|
263 |
|
---|
264 | procedure TFormMain.AExitExecute(Sender: TObject);
|
---|
265 | begin
|
---|
266 | Close;
|
---|
267 | end;
|
---|
268 |
|
---|
269 | procedure TFormMain.ADocumentCheckExecute(Sender: TObject);
|
---|
270 | var
|
---|
271 | FormCheck: TFormCheck;
|
---|
272 | begin
|
---|
273 | FormCheck := TFormCheck.Create(Self);
|
---|
274 | try
|
---|
275 | FormCheck.LoadConfig(TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
|
---|
276 | Core.Core.ApplicationInfo1.RegistryKey));
|
---|
277 | FormCheck.ShowModal;
|
---|
278 | FormCheck.SaveConfig(TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
|
---|
279 | Core.Core.ApplicationInfo1.RegistryKey));
|
---|
280 | finally
|
---|
281 | FreeAndNil(FormCheck);
|
---|
282 | end;
|
---|
283 | end;
|
---|
284 |
|
---|
285 | procedure TFormMain.AExportExecute(Sender: TObject);
|
---|
286 | var
|
---|
287 | FormExport: TFormExport;
|
---|
288 | begin
|
---|
289 | FormExport := TFormExport.Create(Self);
|
---|
290 | try
|
---|
291 | FormExport.AcronymDb := Core.Core.AcronymDb;
|
---|
292 | FormExport.ShowModal;
|
---|
293 | finally
|
---|
294 | FreeAndNil(FormExport);
|
---|
295 | end;
|
---|
296 | end;
|
---|
297 |
|
---|
298 | procedure TFormMain.AFileCloseExecute(Sender: TObject);
|
---|
299 | var
|
---|
300 | ModalResult: TModalResult;
|
---|
301 | DoClose: Boolean;
|
---|
302 | begin
|
---|
303 | DoClose := False;
|
---|
304 | if Assigned(Core.Core.AcronymDb) then begin
|
---|
305 | if Core.Core.AcronymDb.Modified then begin
|
---|
306 | ModalResult := MessageDlg(SAppExit, SAppExitQuery,
|
---|
307 | mtConfirmation, [mbYes, mbNo, mbCancel], 0);
|
---|
308 | if ModalResult = mrYes then begin
|
---|
309 | AFileSave.Execute;
|
---|
310 | DoClose := True;
|
---|
311 | end
|
---|
312 | else if ModalResult = mrNo then begin
|
---|
313 | DoClose := True;
|
---|
314 | end else ProjectClosed := False;
|
---|
315 | end else DoClose := True;
|
---|
316 | end;
|
---|
317 | if DoClose then begin
|
---|
318 | FreeAndNil(Core.Core.AcronymDb);
|
---|
319 | UpdateAcronymsList;
|
---|
320 | UpdateInterface;
|
---|
321 | ProjectClosed := True;
|
---|
322 | end;
|
---|
323 | end;
|
---|
324 |
|
---|
325 | procedure TFormMain.AFileNewExecute(Sender: TObject);
|
---|
326 | begin
|
---|
327 | AFileClose.Execute;
|
---|
328 | if not Assigned(Core.Core.AcronymDb) then begin
|
---|
329 | Core.Core.AcronymDb := TAcronymDb.Create;
|
---|
330 | Core.Core.AcronymDb.FileName := DefaultFileName;
|
---|
331 | Core.Core.AcronymDb.Acronyms.Clear;
|
---|
332 | Core.Core.AcronymDb.OnUpdate.Add(AcronymDbUpdate);
|
---|
333 | UpdateAcronymsList;
|
---|
334 | UpdateInterface;
|
---|
335 | end;
|
---|
336 | end;
|
---|
337 |
|
---|
338 | procedure TFormMain.AFileOpenExecute(Sender: TObject);
|
---|
339 | begin
|
---|
340 | OpenDialog1.DefaultExt := ProjectExt;
|
---|
341 | if Assigned(Core.Core.AcronymDb) then begin
|
---|
342 | OpenDialog1.InitialDir := ExtractFileDir(Core.Core.AcronymDb.FileName);
|
---|
343 | OpenDialog1.Filter := SFileFilter;
|
---|
344 | OpenDialog1.FileName := ExtractFileName(Core.Core.AcronymDb.FileName);
|
---|
345 | end;
|
---|
346 | if OpenDialog1.Execute then begin
|
---|
347 | ProjectOpen(OpenDialog1.FileName);
|
---|
348 | end;
|
---|
349 | end;
|
---|
350 |
|
---|
351 | procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
|
---|
352 | begin
|
---|
353 | SaveDialog1.DefaultExt := ProjectExt;
|
---|
354 | SaveDialog1.InitialDir := ExtractFileDir(Core.Core.AcronymDb.FileName);
|
---|
355 | SaveDialog1.Filter := SFileFilter;
|
---|
356 | SaveDialog1.FileName := ExtractFileName(Core.Core.AcronymDb.FileName);
|
---|
357 | if SaveDialog1.Execute then begin
|
---|
358 | Core.Core.AcronymDb.SaveToFile(SaveDialog1.FileName);
|
---|
359 | LastOpenedList1.AddItem(SaveDialog1.FileName);
|
---|
360 | UpdateInterface;
|
---|
361 | end;
|
---|
362 | end;
|
---|
363 |
|
---|
364 | procedure TFormMain.AFileSaveExecute(Sender: TObject);
|
---|
365 | begin
|
---|
366 | if FileExists(Core.Core.AcronymDb.FileName) then begin
|
---|
367 | Core.Core.AcronymDb.SaveToFile(Core.Core.AcronymDb.FileName);
|
---|
368 | LastOpenedList1.AddItem(Core.Core.AcronymDb.FileName);
|
---|
369 | UpdateInterface;
|
---|
370 | end else AFileSaveAs.Execute;
|
---|
371 | end;
|
---|
372 |
|
---|
373 | procedure TFormMain.AFilterEnabledCategoriesExecute(Sender: TObject);
|
---|
374 | begin
|
---|
375 | UpdateAcronymsList;
|
---|
376 | end;
|
---|
377 |
|
---|
378 | procedure TFormMain.AFilterSameLetterCaseExecute(Sender: TObject);
|
---|
379 | begin
|
---|
380 | UpdateAcronymsList;
|
---|
381 | end;
|
---|
382 |
|
---|
383 | procedure TFormMain.AFilterSameLengthExecute(Sender: TObject);
|
---|
384 | begin
|
---|
385 | UpdateAcronymsList;
|
---|
386 | end;
|
---|
387 |
|
---|
388 | procedure TFormMain.AFilterShowItemsWithoutFilterExecute(Sender: TObject);
|
---|
389 | begin
|
---|
390 | UpdateAcronymsList;
|
---|
391 | end;
|
---|
392 |
|
---|
393 | procedure TFormMain.AFullScreenExecute(Sender: TObject);
|
---|
394 | begin
|
---|
395 | FullScreen := not FullScreen;
|
---|
396 | TFormEx.PersistentForm.Form := Self;
|
---|
397 | TFormEx.PersistentForm.SetFullScreen(FullScreen);
|
---|
398 | UpdateInterface;
|
---|
399 | end;
|
---|
400 |
|
---|
401 | procedure TFormMain.AHideExecute(Sender: TObject);
|
---|
402 | begin
|
---|
403 | Hide;
|
---|
404 | end;
|
---|
405 |
|
---|
406 | procedure TFormMain.AImportExecute(Sender: TObject);
|
---|
407 | var
|
---|
408 | FormImport: TFormImport;
|
---|
409 | begin
|
---|
410 | FormImport := TFormImport.Create(Self);
|
---|
411 | try
|
---|
412 | FormImport.AcronymDb := Core.Core.AcronymDb;
|
---|
413 | FormImport.ShowModal;
|
---|
414 | UpdateAcronymsList;
|
---|
415 | UpdateInterface;
|
---|
416 | finally
|
---|
417 | FreeAndNil(FormImport);
|
---|
418 | end;
|
---|
419 | end;
|
---|
420 |
|
---|
421 | procedure TFormMain.AManageAcronymExecute(Sender: TObject);
|
---|
422 | var
|
---|
423 | FormAcronyms: TFormAcronyms;
|
---|
424 | begin
|
---|
425 | FormAcronyms := TFormAcronyms.Create(Self);
|
---|
426 | try
|
---|
427 | if Assigned(ListViewAcronyms.Selected) then
|
---|
428 | FormAcronyms.FocusAcronym := ListViewAcronyms.Selected.Data;
|
---|
429 | FormAcronyms.AcronymDb := Core.Core.AcronymDb;
|
---|
430 | FormAcronyms.Acronyms := Core.Core.AcronymDb.Acronyms;
|
---|
431 | FormAcronyms.ShowModal;
|
---|
432 | UpdateAcronymsList;
|
---|
433 | UpdateInterface;
|
---|
434 | finally
|
---|
435 | FreeAndNil(FormAcronyms);
|
---|
436 | end;
|
---|
437 | end;
|
---|
438 |
|
---|
439 | procedure TFormMain.AProcessImportsExecute(Sender: TObject);
|
---|
440 | begin
|
---|
441 | ImportTotalItemCount := 0;
|
---|
442 | Core.Core.AcronymDb.AddedCount := 0;
|
---|
443 | JobProgressView1.AddJob(SProcessImportSources, ProcessImportsJob);
|
---|
444 | JobProgressView1.Start;
|
---|
445 | ShowMessage(Format(SAddedCount, [ImportTotalItemCount, Core.Core.AcronymDb.AddedCount]));
|
---|
446 | UpdateAcronymsList;
|
---|
447 | UpdateInterface;
|
---|
448 | end;
|
---|
449 |
|
---|
450 | procedure TFormMain.ProcessImportsJob(Job: TJob);
|
---|
451 | var
|
---|
452 | I: Integer;
|
---|
453 | begin
|
---|
454 | for I := 0 to Core.Core.AcronymDb.ImportSources.Count - 1 do
|
---|
455 | with Core.Core.AcronymDb.ImportSources[I] do
|
---|
456 | if Enabled then begin
|
---|
457 | Process;
|
---|
458 | ImportTotalItemCount := ImportTotalItemCount + ItemCount;
|
---|
459 | Job.Progress.Max := Core.Core.AcronymDb.ImportSources.Count;
|
---|
460 | Job.Progress.Value := I;
|
---|
461 | if Job.Terminate then Break;
|
---|
462 | end;
|
---|
463 | end;
|
---|
464 |
|
---|
465 | procedure TFormMain.ASettingsExecute(Sender: TObject);
|
---|
466 | var
|
---|
467 | FormSettings: TFormSettings;
|
---|
468 | begin
|
---|
469 | FormSettings := TFormSettings.Create(Self);
|
---|
470 | try
|
---|
471 | FormSettings.Load;
|
---|
472 | if FormSettings.ShowModal = mrOk then begin
|
---|
473 | FormSettings.Save;
|
---|
474 | Core.Core.SaveConfig;
|
---|
475 | Core.Core.ThemeManager.UseTheme(Self);
|
---|
476 | end;
|
---|
477 | finally
|
---|
478 | FreeAndNil(FormSettings);
|
---|
479 | end;
|
---|
480 | end;
|
---|
481 |
|
---|
482 | procedure TFormMain.AShowAboutExecute(Sender: TObject);
|
---|
483 | var
|
---|
484 | FormAbout: TFormAbout;
|
---|
485 | begin
|
---|
486 | FormAbout := TFormAbout.Create(nil);
|
---|
487 | try
|
---|
488 | FormAbout.ApplicationInfo := Core.Core.ApplicationInfo1;
|
---|
489 | FormAbout.ShowModal;
|
---|
490 | finally
|
---|
491 | FormAbout.Free;
|
---|
492 | end;
|
---|
493 | end;
|
---|
494 |
|
---|
495 | procedure TFormMain.AShowAcronymsExecute(Sender: TObject);
|
---|
496 | var
|
---|
497 | FormAcronyms: TFormAcronyms;
|
---|
498 | begin
|
---|
499 | FormAcronyms := TFormAcronyms.Create(Self);
|
---|
500 | try
|
---|
501 | FormAcronyms.AcronymDb := Core.Core.AcronymDb;
|
---|
502 | FormAcronyms.Acronyms := Core.Core.AcronymDb.Acronyms;
|
---|
503 | FormAcronyms.ShowModal;
|
---|
504 | UpdateAcronymsList;
|
---|
505 | UpdateInterface;
|
---|
506 | finally
|
---|
507 | FreeAndNil(FormAcronyms);
|
---|
508 | end;
|
---|
509 | end;
|
---|
510 |
|
---|
511 | procedure TFormMain.AShowCategoriesExecute(Sender: TObject);
|
---|
512 | var
|
---|
513 | FormCategories: TFormCategories;
|
---|
514 | begin
|
---|
515 | FormCategories := TFormCategories.Create(Self);
|
---|
516 | try
|
---|
517 | FormCategories.AcronymDb := Core.Core.AcronymDb;
|
---|
518 | FormCategories.Categories := Core.Core.AcronymDb.Categories;
|
---|
519 | FormCategories.ShowModal;
|
---|
520 | UpdateAcronymsList;
|
---|
521 | UpdateInterface;
|
---|
522 | finally
|
---|
523 | FreeAndNil(FormCategories);
|
---|
524 | end;
|
---|
525 | end;
|
---|
526 |
|
---|
527 | procedure TFormMain.AShowExecute(Sender: TObject);
|
---|
528 | begin
|
---|
529 | Show;
|
---|
530 | BringToFront;
|
---|
531 | end;
|
---|
532 |
|
---|
533 | procedure TFormMain.AShowImportFormatsExecute(Sender: TObject);
|
---|
534 | var
|
---|
535 | FormImportFormats: TFormImportFormats;
|
---|
536 | begin
|
---|
537 | FormImportFormats := TFormImportFormats.Create(Self);
|
---|
538 | try
|
---|
539 | FormImportFormats.AcronymDb := Core.Core.AcronymDb;
|
---|
540 | FormImportFormats.ImportFormats := Core.Core.AcronymDb.ImportFormats;
|
---|
541 | FormImportFormats.ShowModal;
|
---|
542 | UpdateInterface;
|
---|
543 | finally
|
---|
544 | FreeAndNil(FormImportFormats);
|
---|
545 | end;
|
---|
546 | end;
|
---|
547 |
|
---|
548 | procedure TFormMain.AShowImportSourcesExecute(Sender: TObject);
|
---|
549 | var
|
---|
550 | FormImportSources: TFormImportSources;
|
---|
551 | begin
|
---|
552 | FormImportSources := TFormImportSources.Create(Self);
|
---|
553 | try
|
---|
554 | FormImportSources.ImportSources := Core.Core.AcronymDb.ImportSources;
|
---|
555 | FormImportSources.AcronymDb := Core.Core.AcronymDb;
|
---|
556 | FormImportSources.ShowModal;
|
---|
557 | UpdateAcronymsList;
|
---|
558 | UpdateInterface;
|
---|
559 | finally
|
---|
560 | FreeAndNil(FormImportSources);
|
---|
561 | end;
|
---|
562 | end;
|
---|
563 |
|
---|
564 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
565 | begin
|
---|
566 | FullScreen := Core.Core.PersistentForm1.FormFullScreen;
|
---|
567 | Core.Core.Initialize;
|
---|
568 |
|
---|
569 | if Visible then begin
|
---|
570 | ListViewFilter1.UpdateFromListView(ListViewAcronyms);
|
---|
571 | UpdateInterface;
|
---|
572 | ListViewFilter1.StringGrid.Col := 1;
|
---|
573 | ListViewFilter1.StringGrid.Col := 0;
|
---|
574 | ListViewFilter1.StringGrid.Row := 0;
|
---|
575 | ListViewFilter1.StringGrid.SetFocus;
|
---|
576 | end;
|
---|
577 | Core.Core.ScaleDPI1.ScaleControl(CoolBar1, Core.Core.ScaleDPI1.DesignDPI);
|
---|
578 | CoolBar1.AutosizeBands;
|
---|
579 | end;
|
---|
580 |
|
---|
581 | procedure TFormMain.LastOpenedList1Change(Sender: TObject);
|
---|
582 | begin
|
---|
583 | LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
|
---|
584 | LastOpenedList1.LoadToMenuItem(PopupMenuOpenRecent.Items, OpenRecentClick);
|
---|
585 | end;
|
---|
586 |
|
---|
587 | procedure TFormMain.ListViewAcronymsData(Sender: TObject; Item: TListItem);
|
---|
588 | begin
|
---|
589 | if Item.Index < ListViewSort1.List.Count then
|
---|
590 | with TAcronymMeaning(ListViewSort1.List[Item.Index]) do begin
|
---|
591 | Item.Caption := Acronym.Name;
|
---|
592 | Item.Data := TAcronymMeaning(ListViewSort1.List[Item.Index]);
|
---|
593 | Item.SubItems.Add(Name);
|
---|
594 | Item.SubItems.Add(Categories.GetString);
|
---|
595 | end;
|
---|
596 | end;
|
---|
597 |
|
---|
598 | procedure TFormMain.ListViewAcronymsResize(Sender: TObject);
|
---|
599 | begin
|
---|
600 | ListViewFilter1.UpdateFromListView(ListViewAcronyms);
|
---|
601 | end;
|
---|
602 |
|
---|
603 | procedure TFormMain.ListViewAcronymsSelectItem(Sender: TObject;
|
---|
604 | Item: TListItem; Selected: Boolean);
|
---|
605 | begin
|
---|
606 | UpdateInterface;
|
---|
607 | end;
|
---|
608 |
|
---|
609 | procedure TFormMain.ListViewFilter1Change(Sender: TObject);
|
---|
610 | begin
|
---|
611 | UpdateAcronymsList;
|
---|
612 | end;
|
---|
613 |
|
---|
614 | procedure TFormMain.ListViewSort1ColumnWidthChanged(Sender: TObject);
|
---|
615 | begin
|
---|
616 | ListViewFilter1.UpdateFromListView(ListViewAcronyms);
|
---|
617 | end;
|
---|
618 |
|
---|
619 | function TFormMain.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
---|
620 | begin
|
---|
621 | Result := 0;
|
---|
622 | if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
|
---|
623 | with ListViewSort1 do
|
---|
624 | case Column of
|
---|
625 | 0: Result := CompareString(TAcronymMeaning(Item1).Acronym.Name, TAcronymMeaning(Item2).Acronym.Name);
|
---|
626 | 1: Result := CompareString(TAcronymMeaning(Item1).Name, TAcronymMeaning(Item2).Name);
|
---|
627 | 2: Result := CompareString(TAcronymMeaning(Item1).Categories.GetString, TAcronymMeaning(Item2).Categories.GetString);
|
---|
628 | end;
|
---|
629 | if ListViewSort1.Order = soDown then Result := -Result;
|
---|
630 | end else Result := 0;
|
---|
631 | end;
|
---|
632 |
|
---|
633 | procedure TFormMain.AShowKeyShortcutsExecute(Sender: TObject);
|
---|
634 | begin
|
---|
635 | if not Assigned(FormKeyShortcuts) then
|
---|
636 | FormKeyShortcuts := TFormKeyShortcuts.Create(nil);
|
---|
637 | with FormKeyShortcuts do begin
|
---|
638 | Images := Core.Core.ImageListSmall;
|
---|
639 | SourceComponents.Clear;
|
---|
640 | SourceComponents.Add(Self);
|
---|
641 | Show;
|
---|
642 | end;
|
---|
643 | end;
|
---|
644 |
|
---|
645 | procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort);
|
---|
646 | begin
|
---|
647 | Core.Core.AcronymDb.AssignToList(ListViewSort1.List, AFilterEnabledCategories.Checked);
|
---|
648 | FilterList(ListViewSort1.List);
|
---|
649 | end;
|
---|
650 |
|
---|
651 | procedure TFormMain.MenuItemParamClick(Sender: TObject);
|
---|
652 | begin
|
---|
653 | MenuItemParam.Checked := not MenuItemParam.Checked;
|
---|
654 | UpdateInterface;
|
---|
655 | end;
|
---|
656 |
|
---|
657 | procedure TFormMain.MenuItemStatusBarClick(Sender: TObject);
|
---|
658 | begin
|
---|
659 | MenuItemStatusBar.Checked := not MenuItemStatusBar.Checked;
|
---|
660 | UpdateInterface;
|
---|
661 | end;
|
---|
662 |
|
---|
663 | procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
|
---|
664 | begin
|
---|
665 | MenuItemToolbar.Checked := not MenuItemToolbar.Checked;
|
---|
666 | UpdateInterface;
|
---|
667 | end;
|
---|
668 |
|
---|
669 | procedure TFormMain.AcronymDbUpdate(Sender: TObject);
|
---|
670 | begin
|
---|
671 | UpdateAcronymsList;
|
---|
672 | end;
|
---|
673 |
|
---|
674 | function TFormMain.FilterCell(Text1, Text2: string): Boolean;
|
---|
675 | begin
|
---|
676 | if not AFilterSameLetterCase.Checked then begin
|
---|
677 | Text1 := UTF8LowerCase(Text1);
|
---|
678 | Text2 := UTF8LowerCase(Text2);
|
---|
679 | end;
|
---|
680 | if AFilterSameLength.Checked then
|
---|
681 | Result := Text1 = Text2
|
---|
682 | else Result := Pos(Text1, Text2) > 0;
|
---|
683 | end;
|
---|
684 |
|
---|
685 | procedure TFormMain.ProjectOpen(FileName: string);
|
---|
686 | begin
|
---|
687 | AFileClose.Execute;
|
---|
688 | if not Assigned(Core.Core.AcronymDb) then begin
|
---|
689 | try
|
---|
690 | AFileNew.Execute;
|
---|
691 | Core.Core.AcronymDb.LoadFromFile(FileName);
|
---|
692 | LastOpenedList1.AddItem(FileName);
|
---|
693 | finally
|
---|
694 | UpdateAcronymsList;
|
---|
695 | UpdateInterface;
|
---|
696 | end;
|
---|
697 | end;
|
---|
698 | end;
|
---|
699 |
|
---|
700 | procedure TFormMain.FilterList(List: TObjectList<TObject>);
|
---|
701 | var
|
---|
702 | I: Integer;
|
---|
703 | FoundCount: Integer;
|
---|
704 | EnteredCount: Integer;
|
---|
705 | begin
|
---|
706 | EnteredCount := ListViewFilter1.TextEnteredCount;
|
---|
707 | for I := List.Count - 1 downto 0 do begin
|
---|
708 | if List.Items[I] is TAcronymMeaning then begin
|
---|
709 | with TAcronymMeaning(List.Items[I]) do begin
|
---|
710 | with ListViewFilter1 do
|
---|
711 | if Visible and ((EnteredCount > 0) or ((EnteredCount = 0) and
|
---|
712 | (AFilterShowItemsWithoutFilter.Checked))) then begin
|
---|
713 | FoundCount := 0;
|
---|
714 | if TextEnteredColumn(0) and (FilterCell(StringGrid.Cells[0, 0],
|
---|
715 | TAcronymMeaning(List.Items[I]).Acronym.Name)) then Inc(FoundCount);
|
---|
716 | if TextEnteredColumn(1) and (FilterCell(StringGrid.Cells[1, 0],
|
---|
717 | TAcronymMeaning(List.Items[I]).Name)) then Inc(FoundCount);
|
---|
718 | if TextEnteredColumn(2) and (FilterCell(StringGrid.Cells[2, 0],
|
---|
719 | TAcronymMeaning(List.Items[I]).Categories.GetString)) then Inc(FoundCount);
|
---|
720 | if FoundCount <> EnteredCount then List.Delete(I);
|
---|
721 | end else List.Delete(I);
|
---|
722 | end;
|
---|
723 | end else
|
---|
724 | if TAcronymMeaning(List.Items[I]) is TAcronymMeaning then begin
|
---|
725 | List.Delete(I);
|
---|
726 | end;
|
---|
727 | end;
|
---|
728 | end;
|
---|
729 |
|
---|
730 | procedure TFormMain.OpenRecentClick(Sender: TObject);
|
---|
731 | begin
|
---|
732 | AFileClose.Execute;
|
---|
733 | if not Assigned(Core.Core.AcronymDb) then begin
|
---|
734 | AFileNew.Execute;
|
---|
735 | Core.Core.AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
|
---|
736 | LastOpenedList1.AddItem(TMenuItem(Sender).Caption);
|
---|
737 | UpdateAcronymsList;
|
---|
738 | UpdateInterface;
|
---|
739 | end;
|
---|
740 | end;
|
---|
741 |
|
---|
742 | procedure TFormMain.UpdateAcronymsList;
|
---|
743 | begin
|
---|
744 | if Assigned(Core.Core.AcronymDb) then begin
|
---|
745 | ListViewSort1.Refresh;
|
---|
746 | end else begin
|
---|
747 | ListViewSort1.List.Clear;
|
---|
748 | ListViewAcronyms.Items.Count := 0;
|
---|
749 | ListViewAcronyms.Refresh;
|
---|
750 | end;
|
---|
751 | end;
|
---|
752 |
|
---|
753 | procedure TFormMain.UpdateInterface;
|
---|
754 | var
|
---|
755 | Title: string;
|
---|
756 | begin
|
---|
757 | AFullscreen.Checked := FullScreen;
|
---|
758 | ListViewAcronyms.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
759 | AFileClose.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
760 | AFileSave.Enabled := Assigned(Core.Core.AcronymDb) and Core.Core.AcronymDb.Modified;
|
---|
761 | AFileSaveAs.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
762 | AImport.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
763 | AExport.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
764 | AProcessImports.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
765 | AShowCategories.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
766 | AShowAcronyms.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
767 | AShowCategories.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
768 | AShowImportSources.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
769 | AShowImportFormats.Enabled := Assigned(Core.Core.AcronymDb);
|
---|
770 | CoolBar1.Visible := MenuItemToolbar.Checked;
|
---|
771 | PanelParam.Visible := MenuItemParam.Checked;
|
---|
772 | AHide.Enabled := Visible;
|
---|
773 | AManageAcronym.Enabled := Assigned(ListViewAcronyms.Selected);
|
---|
774 | StatusBar1.Visible := MenuItemStatusBar.Checked;
|
---|
775 |
|
---|
776 | Title := '';
|
---|
777 | if Assigned(Core.Core.AcronymDb) and (ExtractFileNameWithoutExt(ExtractFileName(Core.Core.AcronymDb.FileName)) <> '') then begin
|
---|
778 | Title := ExtractFileNameWithoutExt(ExtractFileName(Core.Core.AcronymDb.FileName));
|
---|
779 | if Core.Core.AcronymDb.Modified then Title := Title + ' (' + SModified + ')';
|
---|
780 | end;
|
---|
781 | if Title <> '' then Title := Title + ' - ';
|
---|
782 | Title := Title + Core.Core.ApplicationInfo1.AppName;
|
---|
783 | {$IFDEF WINDOWS}
|
---|
784 | // Under Linux title would affect reg.xml path for storing registry settings
|
---|
785 | Application.Title := Title;
|
---|
786 | {$ENDIF}
|
---|
787 | Caption := Title;
|
---|
788 | if Assigned(Core.Core.AcronymDb) then begin
|
---|
789 | StatusBar1.Panels[0].Text := Format(SAcronymsCount, [
|
---|
790 | Core.Core.AcronymDb.Acronyms.Count]);
|
---|
791 | StatusBar1.Panels[1].Text := Format(SMeaningsCount, [
|
---|
792 | Core.Core.AcronymDb.GetMeaningsCount]);
|
---|
793 | end else begin
|
---|
794 | StatusBar1.Panels[0].Text := '';
|
---|
795 | StatusBar1.Panels[1].Text := '';
|
---|
796 | end;
|
---|
797 | end;
|
---|
798 |
|
---|
799 | procedure TFormMain.LoadConfig;
|
---|
800 | begin
|
---|
801 | Core.Core.PersistentForm1.RegistryContext := Core.Core.ApplicationInfo1.GetRegistryContext;
|
---|
802 | RegistryContext := TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
|
---|
803 | Core.Core.ApplicationInfo1.RegistryKey + '\RecentFiles');
|
---|
804 | LastOpenedList1.LoadFromRegistry(RegistryContext);
|
---|
805 |
|
---|
806 | with TRegistryEx.Create do
|
---|
807 | try
|
---|
808 | RootKey := RegistryRootHKEY[Core.Core.ApplicationInfo1.RegistryRoot];
|
---|
809 | OpenKey(Core.Core.ApplicationInfo1.RegistryKey, True);
|
---|
810 | AFilterSameLength.Checked := ReadBoolWithDefault('SameLength', False);
|
---|
811 | AFilterSameLetterCase.Checked := ReadBoolWithDefault('SameLetterCase', False);
|
---|
812 | AFilterEnabledCategories.Checked := ReadBoolWithDefault('EnabledCategories', False);
|
---|
813 | MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True);
|
---|
814 | MenuItemStatusBar.Checked := ReadBoolWithDefault('StatusBarVisible', True);
|
---|
815 | MenuItemParam.Checked := ReadBoolWithDefault('FilterParamVisible', True);
|
---|
816 | AFilterShowItemsWithoutFilter.Checked :=
|
---|
817 | ReadBoolWithDefault('ShowItemsWithoutFilter', True);
|
---|
818 | finally
|
---|
819 | Free;
|
---|
820 | end;
|
---|
821 |
|
---|
822 | with TRegistryEx.Create do
|
---|
823 | try
|
---|
824 | RootKey := HKEY_CURRENT_USER;
|
---|
825 | OpenKey(RegistryRunKey, True);
|
---|
826 | Core.Core.StartOnLogon := ValueExists('Acronym Decoder');
|
---|
827 | finally
|
---|
828 | Free;
|
---|
829 | end;
|
---|
830 | end;
|
---|
831 |
|
---|
832 | procedure TFormMain.SaveConfig;
|
---|
833 | begin
|
---|
834 | RegistryContext := TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
|
---|
835 | Core.Core.ApplicationInfo1.RegistryKey + '\RecentFiles');
|
---|
836 | LastOpenedList1.SaveToRegistry(RegistryContext);
|
---|
837 |
|
---|
838 | with TRegistryEx.Create do
|
---|
839 | try
|
---|
840 | RootKey := RegistryRootHKEY[Core.Core.ApplicationInfo1.RegistryRoot];
|
---|
841 | OpenKey(Core.Core.ApplicationInfo1.RegistryKey, True);
|
---|
842 | WriteBool('SameLength', AFilterSameLength.Checked);
|
---|
843 | WriteBool('SameLetterCase', AFilterSameLetterCase.Checked);
|
---|
844 | WriteBool('EnabledCategories', AFilterEnabledCategories.Checked);
|
---|
845 | WriteBool('ToolBarVisible', MenuItemToolbar.Checked);
|
---|
846 | WriteBool('StatusBarVisible', MenuItemStatusBar.Checked);
|
---|
847 | WriteBool('FilterParamVisible', MenuItemParam.Checked);
|
---|
848 | WriteBool('ShowItemsWithoutFilter', AFilterShowItemsWithoutFilter.Checked);
|
---|
849 | finally
|
---|
850 | Free;
|
---|
851 | end;
|
---|
852 |
|
---|
853 | with TRegistryEx.Create do
|
---|
854 | try
|
---|
855 | RootKey := HKEY_CURRENT_USER;
|
---|
856 | OpenKey(RegistryRunKey, True);
|
---|
857 | if Core.Core.StartOnLogon then begin
|
---|
858 | if Core.Core.StartMinimizedToTray then WriteString('Acronym Decoder', Application.ExeName + ' ' + Application.OptionChar + 't')
|
---|
859 | else WriteString('Acronym Decoder', Application.ExeName)
|
---|
860 | end else DeleteValue('Acronym Decoder');
|
---|
861 | finally
|
---|
862 | Free;
|
---|
863 | end;
|
---|
864 | end;
|
---|
865 |
|
---|
866 | end.
|
---|
867 |
|
---|