source: tags/1.4.0/Forms/UFormMain.pas

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