source: trunk/Forms/FormMain.pas

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