source: trunk/Forms/UFormMain.pas

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