source: tags/1.2.0/Forms/UFormMain.pas

Last change on this file was 75, checked in by chronos, 8 years ago
  • Fixed: Use option start minimized in system tray only in case of user logon.
File size: 20.5 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, UAcronym, UPersistentForm, URegistry,
10 ULastOpenedList, UListViewSort, UJobProgressView, UCoolTranslator, Registry,
11 SpecializedList, LazUTF8;
12
13type
14
15 { TFormMain }
16
17 TFormMain = class(TForm)
18 AProcessImports: TAction;
19 AShowImportFormats: TAction;
20 AShowAbout: TAction;
21 AShowImportSources: TAction;
22 AShowAcronyms: TAction;
23 AShowCategories: TAction;
24 ASettings: TAction;
25 AFileSaveAs: TAction;
26 AFileClose: TAction;
27 AFileSave: TAction;
28 AFileNew: TAction;
29 AFileOpen: TAction;
30 AManualImport: TAction;
31 AShow: TAction;
32 AExit: TAction;
33 ActionList1: TActionList;
34 CheckBoxExactMath: TCheckBox;
35 CoolTranslator1: TCoolTranslator;
36 ImageList1: TImageList;
37 JobProgressView1: TJobProgressView;
38 LastOpenedList1: TLastOpenedList;
39 ListViewAcronyms: TListView;
40 ListViewFilter1: TListViewFilter;
41 ListViewSort1: TListViewSort;
42 MainMenu1: TMainMenu;
43 MenuItem1: TMenuItem;
44 MenuItem10: TMenuItem;
45 MenuItem11: TMenuItem;
46 MenuItem12: TMenuItem;
47 MenuItem13: TMenuItem;
48 MenuItem14: TMenuItem;
49 MenuItem15: TMenuItem;
50 MenuItem16: TMenuItem;
51 MenuItem17: TMenuItem;
52 MenuItem18: TMenuItem;
53 MenuItem19: TMenuItem;
54 MenuItem20: TMenuItem;
55 MenuItem21: TMenuItem;
56 MenuItem22: TMenuItem;
57 MenuItem23: TMenuItem;
58 MenuItem24: TMenuItem;
59 MenuItemToolbar: TMenuItem;
60 MenuItem4: TMenuItem;
61 MenuItem5: TMenuItem;
62 MenuItem6: TMenuItem;
63 MenuItem7: TMenuItem;
64 MenuItemOpenRecent: TMenuItem;
65 MenuItem2: TMenuItem;
66 MenuItem3: TMenuItem;
67 MenuItem8: TMenuItem;
68 MenuItem9: TMenuItem;
69 OpenDialog1: TOpenDialog;
70 Panel1: TPanel;
71 PersistentForm1: TPersistentForm;
72 PopupMenuTryIcon: TPopupMenu;
73 SaveDialog1: TSaveDialog;
74 ToolBar1: TToolBar;
75 ToolButton1: TToolButton;
76 ToolButton10: TToolButton;
77 ToolButton11: TToolButton;
78 ToolButton2: TToolButton;
79 ToolButton3: TToolButton;
80 ToolButton4: TToolButton;
81 ToolButton5: TToolButton;
82 ToolButton6: TToolButton;
83 ToolButton7: TToolButton;
84 ToolButton8: TToolButton;
85 ToolButton9: TToolButton;
86 TrayIcon1: TTrayIcon;
87 procedure AExitExecute(Sender: TObject);
88 procedure AFileCloseExecute(Sender: TObject);
89 procedure AFileNewExecute(Sender: TObject);
90 procedure AFileOpenExecute(Sender: TObject);
91 procedure AFileSaveAsExecute(Sender: TObject);
92 procedure AFileSaveExecute(Sender: TObject);
93 procedure AManualImportExecute(Sender: TObject);
94 procedure AProcessImportsExecute(Sender: TObject);
95 procedure ASettingsExecute(Sender: TObject);
96 procedure AShowAboutExecute(Sender: TObject);
97 procedure AShowAcronymsExecute(Sender: TObject);
98 procedure AShowCategoriesExecute(Sender: TObject);
99 procedure AShowExecute(Sender: TObject);
100 procedure AShowImportFormatsExecute(Sender: TObject);
101 procedure AShowImportSourcesExecute(Sender: TObject);
102 procedure CheckBoxExactMathChange(Sender: TObject);
103 procedure CoolTranslator1Translate(Sender: TObject);
104 procedure EditSearchChange(Sender: TObject);
105 procedure FormShow(Sender: TObject);
106 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
107 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
108 procedure FormCreate(Sender: TObject);
109 procedure FormDestroy(Sender: TObject);
110 procedure LastOpenedList1Change(Sender: TObject);
111 procedure ListViewAcronymsData(Sender: TObject; Item: TListItem);
112 procedure ListViewAcronymsResize(Sender: TObject);
113 procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem;
114 Selected: Boolean);
115 procedure ListViewFilter1Change(Sender: TObject);
116 function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
117 procedure ListViewSort1Filter(ListViewSort: TListViewSort);
118 procedure MenuItemToolbarClick(Sender: TObject);
119 procedure TrayIcon1Click(Sender: TObject);
120 private
121 Initialized: Boolean;
122 FAlwaysOnTop: Boolean;
123 RegistryContext: TRegistryContext;
124 ProjectClosed: Boolean;
125 ImportTotalItemCount: Integer;
126 function FindFirstNonOption: string;
127 procedure ProjectOpen(FileName: string);
128 procedure Initialize;
129 procedure ProcessImportsJob(Job: TJob);
130 procedure SetAlwaysOnTop(AValue: Boolean);
131 procedure FilterList(List: TListObject);
132 procedure OpenRecentClick(Sender: TObject);
133 procedure UpdateAcronymsList;
134 procedure UpdateInterface;
135 procedure LoadConfig;
136 procedure SaveConfig;
137 public
138 AcronymDb: TAcronymDb;
139 StartOnLogon: Boolean;
140 StartMinimizedToTray: Boolean;
141 function CompareStrings(Strings1, Strings2: TStrings): Boolean;
142 property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;
143 end;
144
145var
146 FormMain: TFormMain;
147
148resourcestring
149 SAddedCount = 'Imported %d acronyms. Added %d new.';
150 SProcessImportSources = 'Process import sources';
151
152
153implementation
154
155{$R *.lfm}
156
157uses
158 UFormImport, UFormSettings, UFormCategories, UFormAcronyms,
159 UFormImportSources, UFormAbout, UFormImportFormats;
160
161resourcestring
162 SModified = 'modified';
163 SAppExit = 'Application exit';
164 SAppExitQuery = 'Acronyms were modified. Do you want to save them to file before exit?';
165
166const
167 ProjectExt = '.adp';
168 DefaultFileName = 'Acronyms' + ProjectExt;
169 DefaultRegKey = '\Software\Acronym Decoder';
170 RegistryRunKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
171 ExampleFile = 'Example acronyms.adp';
172
173{ TFormMain }
174
175procedure TFormMain.FormCreate(Sender: TObject);
176var
177 I: Integer;
178begin
179 AcronymDb := TAcronymDb.Create;
180 Initialized := False;
181 for I := 0 to ToolBar1.ButtonCount - 1 do
182 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
183end;
184
185procedure TFormMain.EditSearchChange(Sender: TObject);
186begin
187 UpdateAcronymsList;
188end;
189
190procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
191begin
192 PersistentForm1.Save(Self);
193 SaveConfig;
194end;
195
196procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
197begin
198 AFileClose.Execute;
199 CanClose := ProjectClosed;
200end;
201
202procedure TFormMain.AExitExecute(Sender: TObject);
203begin
204 Close;
205end;
206
207procedure TFormMain.AFileCloseExecute(Sender: TObject);
208var
209 ModalResult: TModalResult;
210 DoClose: Boolean;
211begin
212 DoClose := False;
213 if Assigned(AcronymDb) then begin
214 if AcronymDb.Modified then begin
215 ModalResult := MessageDlg(SAppExit, SAppExitQuery,
216 mtConfirmation, [mbYes, mbNo, mbCancel], 0);
217 if ModalResult = mrYes then begin
218 AFileSave.Execute;
219 DoClose := True;
220 end
221 else if ModalResult = mrNo then begin
222 DoClose := True;
223 end else ProjectClosed := False;
224 end else DoClose := True;
225 end;
226 if DoClose then begin
227 FreeAndNil(AcronymDb);
228 UpdateAcronymsList;
229 UpdateInterface;
230 ProjectClosed := True;
231 end;
232end;
233
234procedure TFormMain.AFileNewExecute(Sender: TObject);
235begin
236 AFileClose.Execute;
237 if ProjectClosed then begin
238 AcronymDb := TAcronymDb.Create;
239 AcronymDb.FileName := DefaultFileName;
240 AcronymDb.Acronyms.Clear;
241 UpdateAcronymsList;
242 UpdateInterface;
243 end;
244end;
245
246procedure TFormMain.AFileOpenExecute(Sender: TObject);
247begin
248 OpenDialog1.DefaultExt := ProjectExt;
249 if Assigned(AcronymDb) then
250 OpenDialog1.FileName := AcronymDb.FileName;
251 if OpenDialog1.Execute then begin
252 ProjectOpen(OpenDialog1.FileName);
253 end;
254end;
255
256procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
257begin
258 SaveDialog1.DefaultExt := ProjectExt;
259 SaveDialog1.FileName := AcronymDb.FileName;
260 if SaveDialog1.Execute then begin
261 AcronymDb.SaveToFile(SaveDialog1.FileName);
262 LastOpenedList1.AddItem(SaveDialog1.FileName);
263 UpdateInterface;
264 end;
265end;
266
267procedure TFormMain.AFileSaveExecute(Sender: TObject);
268begin
269 if FileExists(AcronymDb.FileName) then begin
270 AcronymDb.SaveToFile(AcronymDb.FileName);
271 LastOpenedList1.AddItem(AcronymDb.FileName);
272 UpdateInterface;
273 end else AFileSaveAs.Execute;
274end;
275
276procedure TFormMain.AManualImportExecute(Sender: TObject);
277begin
278 FormImport.ShowModal;
279 UpdateAcronymsList;
280 UpdateInterface;
281end;
282
283procedure TFormMain.AProcessImportsExecute(Sender: TObject);
284begin
285 ImportTotalItemCount := 0;
286 AcronymDb.AddedCount := 0;
287 JobProgressView1.AddJob(SProcessImportSources, ProcessImportsJob);
288 JobProgressView1.Start;
289 ShowMessage(Format(SAddedCount, [ImportTotalItemCount, AcronymDb.AddedCount]));
290 UpdateAcronymsList;
291 UpdateInterface;
292end;
293
294procedure TFormMain.ProcessImportsJob(Job: TJob);
295var
296 I: Integer;
297begin
298 for I := 0 to AcronymDb.ImportSources.Count - 1 do
299 with TImportSource(AcronymDb.ImportSources[I]) do
300 if Enabled then begin
301 Process;
302 ImportTotalItemCount := ImportTotalItemCount + ItemCount;
303 Job.Progress.Max := AcronymDb.ImportSources.Count;
304 Job.Progress.Value := I;
305 if Job.Terminate then Break;
306 end;
307end;
308
309procedure TFormMain.ASettingsExecute(Sender: TObject);
310begin
311 FormSettings.Load;
312 if FormSettings.ShowModal = mrOk then begin
313 FormSettings.Save;
314 SaveConfig;
315 end;
316end;
317
318procedure TFormMain.AShowAboutExecute(Sender: TObject);
319begin
320 FormAbout.ShowModal;
321end;
322
323procedure TFormMain.AShowAcronymsExecute(Sender: TObject);
324begin
325 FormAcronyms.ShowModal;
326 UpdateAcronymsList;
327 UpdateInterface;
328end;
329
330procedure TFormMain.AShowCategoriesExecute(Sender: TObject);
331begin
332 FormCategories.Categories := AcronymDb.Categories;
333 FormCategories.ShowModal;
334 UpdateAcronymsList;
335 UpdateInterface;
336end;
337
338procedure TFormMain.AShowExecute(Sender: TObject);
339begin
340 Show;
341end;
342
343procedure TFormMain.AShowImportFormatsExecute(Sender: TObject);
344begin
345 FormImportFormats.ImportFormats := AcronymDb.ImportFormats;
346 FormImportFormats.ShowModal;
347 UpdateInterface;
348end;
349
350procedure TFormMain.AShowImportSourcesExecute(Sender: TObject);
351begin
352 FormImportSources.ImportSources := AcronymDb.ImportSources;
353 FormImportSources.ShowModal;
354 UpdateAcronymsList;
355 UpdateInterface;
356end;
357
358procedure TFormMain.CheckBoxExactMathChange(Sender: TObject);
359begin
360 UpdateAcronymsList;
361end;
362
363procedure TFormMain.CoolTranslator1Translate(Sender: TObject);
364begin
365 UAcronym.Translate;
366end;
367
368procedure TFormMain.FormDestroy(Sender: TObject);
369begin
370 FreeAndNil(AcronymDb);
371end;
372
373procedure TFormMain.FormShow(Sender: TObject);
374begin
375 Initialize;
376
377 PersistentForm1.Load(Self);
378 UpdateInterface;
379end;
380
381procedure TFormMain.LastOpenedList1Change(Sender: TObject);
382begin
383 LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
384end;
385
386procedure TFormMain.ListViewAcronymsData(Sender: TObject; Item: TListItem);
387begin
388 if Item.Index < ListViewSort1.List.Count then
389 with TAcronymMeaning(ListViewSort1.List[Item.Index]) do begin
390 Item.Caption := Acronym.Name;
391 Item.Data := TAcronymMeaning(ListViewSort1.List[Item.Index]);
392 Item.SubItems.Add(Name);
393 Item.SubItems.Add(Categories.GetString);
394 end;
395end;
396
397procedure TFormMain.ListViewAcronymsResize(Sender: TObject);
398begin
399 ListViewFilter1.UpdateFromListView(ListViewAcronyms);
400end;
401
402procedure TFormMain.ListViewAcronymsSelectItem(Sender: TObject;
403 Item: TListItem; Selected: Boolean);
404begin
405 UpdateInterface;
406end;
407
408procedure TFormMain.ListViewFilter1Change(Sender: TObject);
409begin
410 UpdateAcronymsList;
411end;
412
413function TFormMain.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
414begin
415 Result := 0;
416 if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
417 with ListViewSort1 do
418 case Column of
419 0: Result := CompareString(TAcronymMeaning(Item1).Acronym.Name, TAcronymMeaning(Item2).Acronym.Name);
420 1: Result := CompareString(TAcronymMeaning(Item1).Description, TAcronymMeaning(Item2).Description);
421 2: Result := CompareString(TAcronymMeaning(Item1).Categories.GetString, TAcronymMeaning(Item2).Categories.GetString);
422 end;
423 if ListViewSort1.Order = soDown then Result := -Result;
424 end else Result := 0;
425end;
426
427procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort);
428begin
429 AcronymDb.AssignToList(ListViewSort1.List);
430 FilterList(ListViewSort1.List);
431end;
432
433procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
434begin
435 MenuItemToolbar.Checked := not MenuItemToolbar.Checked;
436 UpdateInterface;
437end;
438
439procedure TFormMain.TrayIcon1Click(Sender: TObject);
440begin
441 Visible := not Visible;
442 if Visible then BringToFront;
443end;
444
445function TFormMain.FindFirstNonOption: string;
446var
447 S: string;
448 I: Integer;
449begin
450 Result := '';
451 for I := 1 to Application.ParamCount do begin
452 S := Application.Params[I];
453 if S[1] = Application.OptionChar then Continue;
454 Result := S;
455 Break;
456 end;
457end;
458
459procedure TFormMain.ProjectOpen(FileName: string);
460begin
461 AFileClose.Execute;
462 if ProjectClosed then begin
463 try
464 AFileNew.Execute;
465 AcronymDb.LoadFromFile(FileName);
466 LastOpenedList1.AddItem(FileName);
467 finally
468 UpdateAcronymsList;
469 UpdateInterface;
470 end;
471 end;
472end;
473
474procedure TFormMain.Initialize;
475var
476 FileNameOption: string;
477begin
478 if not Initialized then begin
479 Initialized := True;
480 LoadConfig;
481
482{$IFDEF 0}
483 if Application.HasOption('h', 'help') then begin
484 WriteLn('AcronymDecoder <project file>');
485 WriteLn(' -t --tray Start minimized in system tray');
486 WriteLn(' -h --help Show this help');
487 Application.Terminate;
488 Exit;
489 end;
490{$ENDIF}
491 if Application.HasOption('t', 'tray') then begin
492 Visible := False;
493 end;
494
495 FileNameOption := FindFirstNonOption;
496 if FileNameOption <> '' then begin
497 // Open file specified as command line parameter
498 AcronymDB.LoadFromFile(FileNameOption);
499 LastOpenedList1.AddItem(OpenDialog1.FileName);
500 end else
501 if (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then begin
502 // Open last opened file
503 AcronymDB.LoadFromFile(LastOpenedList1.Items[0])
504 end else begin
505 // Open default database with examples if no item is in recent openned history
506 ProjectOpen(ExtractFileDir(Application.ExeName) + DirectorySeparator + ExampleFile);
507 end;
508 UpdateAcronymsList;
509 ListViewFilter1.UpdateFromListView(ListViewAcronyms);
510 end;
511end;
512
513function TFormMain.CompareStrings(Strings1, Strings2: TStrings): Boolean;
514var
515 I: Integer;
516begin
517 Result := Strings1.Count = Strings2.Count;
518 if not Result then Exit;
519 for I := 0 to Strings1.Count - 1 do
520 if (Strings1[I] <> Strings2[I]) or (Strings1.Objects[I] <> Strings2.Objects[I]) then begin
521 Result := False;
522 Exit;
523 end;
524end;
525
526procedure TFormMain.SetAlwaysOnTop(AValue: Boolean);
527begin
528 if FAlwaysOnTop = AValue then Exit;
529 FAlwaysOnTop := AValue;
530 if FAlwaysOnTop then FormStyle := fsSystemStayOnTop
531 else FormStyle := fsNormal;
532end;
533
534procedure TFormMain.FilterList(List: TListObject);
535var
536 I: Integer;
537 FoundCount: Integer;
538 EnteredCount: Integer;
539begin
540 EnteredCount := ListViewFilter1.TextEnteredCount;
541 for I := List.Count - 1 downto 0 do begin
542 if List.Items[I] is TAcronymMeaning then begin
543 with TAcronymMeaning(List.Items[I]) do begin
544 with ListViewFilter1 do
545 if Visible and (EnteredCount > 0) then begin
546 FoundCount := 0;
547 if CheckBoxExactMath.Checked then begin
548 if TextEnteredColumn(0) and (StringGrid.Cells[0, 0] =
549 TAcronymMeaning(List.Items[I]).Acronym.Name) then Inc(FoundCount);
550 if TextEnteredColumn(1) and (StringGrid.Cells[1, 0] =
551 TAcronymMeaning(List.Items[I]).Name) then Inc(FoundCount);
552 if TextEnteredColumn(2) and (StringGrid.Cells[2, 0] =
553 TAcronymMeaning(List.Items[I]).Categories.GetString) then Inc(FoundCount);
554 end else begin
555 if Pos(UTF8LowerCase(StringGrid.Cells[0, 0]),
556 UTF8LowerCase(TAcronymMeaning(List.Items[I]).Acronym.Name)) > 0 then Inc(FoundCount);
557 if Pos(UTF8LowerCase(StringGrid.Cells[1, 0]),
558 UTF8LowerCase(TAcronymMeaning(List.Items[I]).Name)) > 0 then Inc(FoundCount);
559 if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]),
560 UTF8LowerCase(TAcronymMeaning(List.Items[I]).Categories.GetString)) > 0 then Inc(FoundCount);
561 end;
562 if FoundCount <> EnteredCount then List.Delete(I);
563 end else List.Delete(I);
564 end;
565 end else
566 if TAcronymMeaning(List.Items[I]) is TAcronymMeaning then begin
567 List.Delete(I);
568 end;
569 end;
570end;
571
572procedure TFormMain.OpenRecentClick(Sender: TObject);
573begin
574 AFileClose.Execute;
575 if ProjectClosed then begin
576 AFileNew.Execute;
577 AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
578 LastOpenedList1.AddItem(TMenuItem(Sender).Caption);
579 UpdateAcronymsList;
580 UpdateInterface;
581 end;
582end;
583
584procedure TFormMain.UpdateAcronymsList;
585begin
586 if Assigned(AcronymDb) then begin
587 ListViewSort1.Refresh;
588 end else ListViewSort1.List.Clear;
589end;
590
591procedure TFormMain.UpdateInterface;
592var
593 Title: string;
594begin
595 ListViewAcronyms.Enabled := Assigned(AcronymDb);
596 AFileClose.Enabled := Assigned(AcronymDb);
597 AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified;
598 AFileSaveAs.Enabled := Assigned(AcronymDb);
599 AManualImport.Enabled := Assigned(AcronymDb);
600 AProcessImports.Enabled := Assigned(AcronymDb);
601 AShowCategories.Enabled := Assigned(AcronymDb);
602 AShowAcronyms.Enabled := Assigned(AcronymDb);
603 AShowCategories.Enabled := Assigned(AcronymDb);
604 AShowImportSources.Enabled := Assigned(AcronymDb);
605 AShowImportFormats.Enabled := Assigned(AcronymDb);
606 ToolBar1.Visible := MenuItemToolbar.Checked;
607
608 Title := Application.Title;
609 if Assigned(AcronymDb) and (ExtractFileName(AcronymDb.FileName) <> '') then
610 if Assigned(AcronymDb) then Title := Title + ' - ' + ExtractFileName(AcronymDb.FileName);
611 if Assigned(AcronymDb) and AcronymDb.Modified then Title := Title + ' (' + SModified + ')';
612 Caption := Title;
613end;
614
615procedure TFormMain.LoadConfig;
616begin
617 RegistryContext := RegContext(HKEY_CURRENT_USER, DefaultRegKey);
618 PersistentForm1.RegistryContext := RegistryContext;
619 RegistryContext := RegContext(HKEY_CURRENT_USER, DefaultRegKey + '\RecentFiles');
620 LastOpenedList1.LoadFromRegistry(RegistryContext);
621
622 with TRegistryEx.Create do
623 try
624 RootKey := HKEY_CURRENT_USER;
625 OpenKey(DefaultRegKey, True);
626 if ValueExists('LanguageCode') then
627 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
628 else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
629 AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False);
630 StartMinimizedToTray := ReadBoolWithDefault('StartMinimizedToTray', False);
631 CheckBoxExactMath.Checked := ReadBoolWithDefault('ExactMatch', False);
632 MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True);
633 finally
634 Free;
635 end;
636
637 with TRegistryEx.Create do
638 try
639 RootKey := HKEY_CURRENT_USER;
640 OpenKey(RegistryRunKey, True);
641 StartOnLogon := ValueExists('Acronym Decoder');
642 finally
643 Free;
644 end;
645end;
646
647procedure TFormMain.SaveConfig;
648begin
649 RegistryContext := RegContext(HKEY_CURRENT_USER, DefaultRegKey + '\RecentFiles');
650 LastOpenedList1.SaveToRegistry(RegistryContext);
651
652 with TRegistryEx.Create do
653 try
654 RootKey := HKEY_CURRENT_USER;
655 OpenKey(DefaultRegKey, True);
656 if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
657 WriteString('LanguageCode', CoolTranslator1.Language.Code)
658 else DeleteValue('LanguageCode');
659 WriteBool('AlwaysOnTop', AlwaysOnTop);
660 WriteBool('StartMinimizedToTray', StartMinimizedToTray);
661 WriteBool('ExactMatch', CheckBoxExactMath.Checked);
662 WriteBool('ToolBarVisible', MenuItemToolbar.Checked);
663 finally
664 Free;
665 end;
666
667 with TRegistryEx.Create do
668 try
669 RootKey := HKEY_CURRENT_USER;
670 OpenKey(RegistryRunKey, True);
671 if StartOnLogon then begin
672 if StartMinimizedToTray then WriteString('Acronym Decoder', Application.ExeName + ' /t')
673 else WriteString('Acronym Decoder', Application.ExeName)
674 end else DeleteValue('Acronym Decoder');
675 finally
676 Free;
677 end;
678end;
679
680end.
681
Note: See TracBrowser for help on using the repository browser.