source: tags/1.3.0/UCore.pas

Last change on this file was 89, checked in by chronos, 8 years ago
  • Added: Show from which imports acronym meanings comes from.

This would easy correcting wrong acronyms directly in source.

  • Modified: References to categories stored more efficiently in XML project file.
File size: 3.5 KB
Line 
1unit UCore;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, UAcronym, Forms, Controls, LazFileUtils;
9
10type
11
12 { TCore }
13
14 TCore = class(TDataModule)
15 procedure DataModuleCreate(Sender: TObject);
16 procedure DataModuleDestroy(Sender: TObject);
17 private
18 FAlwaysOnTop: Boolean;
19 procedure SetAlwaysOnTop(AValue: Boolean);
20 function FindFirstNonOption: string;
21 public
22 AcronymDb: TAcronymDb;
23 StartOnLogon: Boolean;
24 StartMinimizedToTray: Boolean;
25 InitializeStarted: Boolean;
26 InitializeFinished: Boolean;
27 procedure Initialize;
28 procedure LoadConfig;
29 procedure SaveConfig;
30 property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;
31 end;
32
33var
34 Core: TCore;
35
36implementation
37
38uses
39 UFormMain;
40
41const
42 ExampleFile = 'Example acronyms.adp';
43
44
45{$R *.lfm}
46
47procedure TCore.DataModuleCreate(Sender: TObject);
48begin
49 AcronymDb := TAcronymDb.Create;
50 InitializeStarted := False;
51 InitializeFinished := False;
52end;
53
54procedure TCore.DataModuleDestroy(Sender: TObject);
55begin
56 FreeAndNil(AcronymDb);
57end;
58
59procedure TCore.SetAlwaysOnTop(AValue: Boolean);
60begin
61 if FAlwaysOnTop = AValue then Exit;
62 FAlwaysOnTop := AValue;
63 if FAlwaysOnTop then FormMain.FormStyle := fsSystemStayOnTop
64 else FormMain.FormStyle := fsNormal;
65end;
66
67procedure TCore.Initialize;
68var
69 FileNameOption: string;
70begin
71 if not InitializeStarted then begin
72 InitializeStarted := True;
73 LoadConfig;
74
75 {$IFDEF 0}
76 if Application.HasOption('h', 'help') then begin
77 WriteLn('AcronymDecoder <project file>');
78 WriteLn(' -t --tray Start minimized in system tray');
79 WriteLn(' -h --help Show this help');
80 Application.Terminate;
81 Exit;
82 end;
83 {$ENDIF}
84
85 if Application.HasOption('t', 'tray') then begin
86 FormMain.Visible := False;
87 end;
88
89 FileNameOption := FindFirstNonOption;
90 if FileNameOption <> '' then begin
91 // Open file specified as command line parameter
92 AcronymDB.LoadFromFile(FileNameOption);
93 FormMain.LastOpenedList1.AddItem(FormMain.OpenDialog1.FileName);
94 end else
95 if (FormMain.LastOpenedList1.Items.Count > 0) and FileExists(FormMain.LastOpenedList1.Items[0]) then begin
96 // Open last opened file
97 AcronymDB.LoadFromFile(FormMain.LastOpenedList1.Items[0])
98 end else begin
99 // Open default database with examples if no item is in recent openned history
100 FileNameOption := ExtractFileDir(Application.ExeName) + DirectorySeparator + ExampleFile;
101 {$IFDEF Linux}
102 // If installed in Linux system then use installation directory for po files
103 if Application.ExeName = '/usr/bin/' + ExtractFileNameOnly(Application.ExeName) then
104 FileNameOption := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) + '/Examples/' + ExampleFile;
105 {$ENDIF}
106 FormMain.ProjectOpen(FileNameOption);
107 end;
108 FormMain.UpdateAcronymsList;
109 FormMain.ListViewFilter1.UpdateFromListView(FormMain.ListViewAcronyms);
110 InitializeFinished := True;
111 end;
112end;
113
114procedure TCore.LoadConfig;
115begin
116 FormMain.LoadConfig;
117end;
118
119procedure TCore.SaveConfig;
120begin
121 FormMain.SaveConfig;
122end;
123
124function TCore.FindFirstNonOption: string;
125var
126 S: string;
127 I: Integer;
128begin
129 Result := '';
130 for I := 1 to Application.ParamCount do begin
131 S := Application.Params[I];
132 if S[1] = Application.OptionChar then Continue;
133 Result := S;
134 Break;
135 end;
136end;
137
138
139
140end.
141
Note: See TracBrowser for help on using the repository browser.