source: trunk/Forms/FormMain.pas

Last change on this file was 227, checked in by chronos, 44 hours ago
  • Modified: Do not reference global Core object if possible.
File size: 26.0 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 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
177const
178 ProjectExt = '.adp';
179
180resourcestring
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
188implementation
189
190{$R *.lfm}
191
192uses
193 FormImport, FormSettings, FormCategories, FormAcronyms, FormExport,
194 FormImportSources, FormImportFormats, Core, FormCheck;
195
196resourcestring
197 SModified = 'modified';
198 SAppExit = 'Application exit';
199 SAppExitQuery = 'Acronyms were modified. Do you want to save them to file before exit?';
200
201const
202 DefaultFileName = 'Acronyms' + ProjectExt;
203 RegistryRunKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
204
205{ TFormMain }
206
207procedure TFormMain.SetToolbarHints;
208var
209 I: Integer;
210 J: Integer;
211 Control: TControl;
212begin
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;
222end;
223
224procedure TFormMain.FormCreate(Sender: TObject);
225begin
226 SetToolbarHints;
227 PanelMain.ControlStyle := PanelMain.ControlStyle + [csOpaque];
228 PanelParam.ControlStyle := PanelParam.ControlStyle + [csOpaque];
229end;
230
231procedure TFormMain.EditSearchChange(Sender: TObject);
232begin
233 UpdateAcronymsList;
234end;
235
236procedure TFormMain.FormDestroy(Sender: TObject);
237begin
238 if Assigned(FormKeyShortcuts) then FreeAndNil(FormKeyShortcuts);
239end;
240
241procedure TFormMain.FormHide(Sender: TObject);
242begin
243 if Core.Core.InitializeFinished then Core.Core.PersistentForm1.Save(Self);
244 UpdateInterface;
245end;
246
247procedure TFormMain.FormResize(Sender: TObject);
248begin
249 CoolBar1.AutosizeBands;
250end;
251
252procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
253begin
254 Core.Core.SaveConfig;
255end;
256
257procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
258begin
259 ProjectClosed := True;
260 AFileClose.Execute;
261 CanClose := ProjectClosed;
262end;
263
264procedure TFormMain.AExitExecute(Sender: TObject);
265begin
266 Close;
267end;
268
269procedure TFormMain.ADocumentCheckExecute(Sender: TObject);
270var
271 FormCheck: TFormCheck;
272begin
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;
283end;
284
285procedure TFormMain.AExportExecute(Sender: TObject);
286var
287 FormExport: TFormExport;
288begin
289 FormExport := TFormExport.Create(Self);
290 try
291 FormExport.AcronymDb := Core.Core.AcronymDb;
292 FormExport.ShowModal;
293 finally
294 FreeAndNil(FormExport);
295 end;
296end;
297
298procedure TFormMain.AFileCloseExecute(Sender: TObject);
299var
300 ModalResult: TModalResult;
301 DoClose: Boolean;
302begin
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;
323end;
324
325procedure TFormMain.AFileNewExecute(Sender: TObject);
326begin
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;
336end;
337
338procedure TFormMain.AFileOpenExecute(Sender: TObject);
339begin
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;
349end;
350
351procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
352begin
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;
362end;
363
364procedure TFormMain.AFileSaveExecute(Sender: TObject);
365begin
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;
371end;
372
373procedure TFormMain.AFilterEnabledCategoriesExecute(Sender: TObject);
374begin
375 UpdateAcronymsList;
376end;
377
378procedure TFormMain.AFilterSameLetterCaseExecute(Sender: TObject);
379begin
380 UpdateAcronymsList;
381end;
382
383procedure TFormMain.AFilterSameLengthExecute(Sender: TObject);
384begin
385 UpdateAcronymsList;
386end;
387
388procedure TFormMain.AFilterShowItemsWithoutFilterExecute(Sender: TObject);
389begin
390 UpdateAcronymsList;
391end;
392
393procedure TFormMain.AFullScreenExecute(Sender: TObject);
394begin
395 FullScreen := not FullScreen;
396 TFormEx.PersistentForm.Form := Self;
397 TFormEx.PersistentForm.SetFullScreen(FullScreen);
398 UpdateInterface;
399end;
400
401procedure TFormMain.AHideExecute(Sender: TObject);
402begin
403 Hide;
404end;
405
406procedure TFormMain.AImportExecute(Sender: TObject);
407var
408 FormImport: TFormImport;
409begin
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;
419end;
420
421procedure TFormMain.AManageAcronymExecute(Sender: TObject);
422var
423 FormAcronyms: TFormAcronyms;
424begin
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;
437end;
438
439procedure TFormMain.AProcessImportsExecute(Sender: TObject);
440begin
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;
448end;
449
450procedure TFormMain.ProcessImportsJob(Job: TJob);
451var
452 I: Integer;
453begin
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;
463end;
464
465procedure TFormMain.ASettingsExecute(Sender: TObject);
466var
467 FormSettings: TFormSettings;
468begin
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;
480end;
481
482procedure TFormMain.AShowAboutExecute(Sender: TObject);
483var
484 FormAbout: TFormAbout;
485begin
486 FormAbout := TFormAbout.Create(nil);
487 try
488 FormAbout.ApplicationInfo := Core.Core.ApplicationInfo1;
489 FormAbout.ShowModal;
490 finally
491 FormAbout.Free;
492 end;
493end;
494
495procedure TFormMain.AShowAcronymsExecute(Sender: TObject);
496var
497 FormAcronyms: TFormAcronyms;
498begin
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;
509end;
510
511procedure TFormMain.AShowCategoriesExecute(Sender: TObject);
512var
513 FormCategories: TFormCategories;
514begin
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;
525end;
526
527procedure TFormMain.AShowExecute(Sender: TObject);
528begin
529 Show;
530 BringToFront;
531end;
532
533procedure TFormMain.AShowImportFormatsExecute(Sender: TObject);
534var
535 FormImportFormats: TFormImportFormats;
536begin
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;
546end;
547
548procedure TFormMain.AShowImportSourcesExecute(Sender: TObject);
549var
550 FormImportSources: TFormImportSources;
551begin
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;
562end;
563
564procedure TFormMain.FormShow(Sender: TObject);
565begin
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;
579end;
580
581procedure TFormMain.LastOpenedList1Change(Sender: TObject);
582begin
583 LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
584 LastOpenedList1.LoadToMenuItem(PopupMenuOpenRecent.Items, OpenRecentClick);
585end;
586
587procedure TFormMain.ListViewAcronymsData(Sender: TObject; Item: TListItem);
588begin
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;
596end;
597
598procedure TFormMain.ListViewAcronymsResize(Sender: TObject);
599begin
600 ListViewFilter1.UpdateFromListView(ListViewAcronyms);
601end;
602
603procedure TFormMain.ListViewAcronymsSelectItem(Sender: TObject;
604 Item: TListItem; Selected: Boolean);
605begin
606 UpdateInterface;
607end;
608
609procedure TFormMain.ListViewFilter1Change(Sender: TObject);
610begin
611 UpdateAcronymsList;
612end;
613
614procedure TFormMain.ListViewSort1ColumnWidthChanged(Sender: TObject);
615begin
616 ListViewFilter1.UpdateFromListView(ListViewAcronyms);
617end;
618
619function TFormMain.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
620begin
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;
631end;
632
633procedure TFormMain.AShowKeyShortcutsExecute(Sender: TObject);
634begin
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;
643end;
644
645procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort);
646begin
647 Core.Core.AcronymDb.AssignToList(ListViewSort1.List, AFilterEnabledCategories.Checked);
648 FilterList(ListViewSort1.List);
649end;
650
651procedure TFormMain.MenuItemParamClick(Sender: TObject);
652begin
653 MenuItemParam.Checked := not MenuItemParam.Checked;
654 UpdateInterface;
655end;
656
657procedure TFormMain.MenuItemStatusBarClick(Sender: TObject);
658begin
659 MenuItemStatusBar.Checked := not MenuItemStatusBar.Checked;
660 UpdateInterface;
661end;
662
663procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
664begin
665 MenuItemToolbar.Checked := not MenuItemToolbar.Checked;
666 UpdateInterface;
667end;
668
669procedure TFormMain.AcronymDbUpdate(Sender: TObject);
670begin
671 UpdateAcronymsList;
672end;
673
674function TFormMain.FilterCell(Text1, Text2: string): Boolean;
675begin
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;
683end;
684
685procedure TFormMain.ProjectOpen(FileName: string);
686begin
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;
698end;
699
700procedure TFormMain.FilterList(List: TObjectList<TObject>);
701var
702 I: Integer;
703 FoundCount: Integer;
704 EnteredCount: Integer;
705begin
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;
728end;
729
730procedure TFormMain.OpenRecentClick(Sender: TObject);
731begin
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;
740end;
741
742procedure TFormMain.UpdateAcronymsList;
743begin
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;
751end;
752
753procedure TFormMain.UpdateInterface;
754var
755 Title: string;
756begin
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;
797end;
798
799procedure TFormMain.LoadConfig;
800begin
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;
830end;
831
832procedure TFormMain.SaveConfig;
833begin
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;
864end;
865
866end.
867
Note: See TracBrowser for help on using the repository browser.