source: tags/1.5.0/Forms/UFormMain.pas

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