1 | unit UCore;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, UAcronym, Forms, Controls, LazFileUtils;
|
---|
9 |
|
---|
10 | type
|
---|
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 |
|
---|
33 | var
|
---|
34 | Core: TCore;
|
---|
35 |
|
---|
36 | implementation
|
---|
37 |
|
---|
38 | uses
|
---|
39 | UFormMain;
|
---|
40 |
|
---|
41 | const
|
---|
42 | ExampleFile = 'Example acronyms.adp';
|
---|
43 |
|
---|
44 |
|
---|
45 | {$R *.lfm}
|
---|
46 |
|
---|
47 | procedure TCore.DataModuleCreate(Sender: TObject);
|
---|
48 | begin
|
---|
49 | AcronymDb := TAcronymDb.Create;
|
---|
50 | InitializeStarted := False;
|
---|
51 | InitializeFinished := False;
|
---|
52 | end;
|
---|
53 |
|
---|
54 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
---|
55 | begin
|
---|
56 | FreeAndNil(AcronymDb);
|
---|
57 | end;
|
---|
58 |
|
---|
59 | procedure TCore.SetAlwaysOnTop(AValue: Boolean);
|
---|
60 | begin
|
---|
61 | if FAlwaysOnTop = AValue then Exit;
|
---|
62 | FAlwaysOnTop := AValue;
|
---|
63 | if FAlwaysOnTop then FormMain.FormStyle := fsSystemStayOnTop
|
---|
64 | else FormMain.FormStyle := fsNormal;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TCore.Initialize;
|
---|
68 | var
|
---|
69 | FileNameOption: string;
|
---|
70 | begin
|
---|
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;
|
---|
112 | end;
|
---|
113 |
|
---|
114 | procedure TCore.LoadConfig;
|
---|
115 | begin
|
---|
116 | FormMain.LoadConfig;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TCore.SaveConfig;
|
---|
120 | begin
|
---|
121 | FormMain.SaveConfig;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | function TCore.FindFirstNonOption: string;
|
---|
125 | var
|
---|
126 | S: string;
|
---|
127 | I: Integer;
|
---|
128 | begin
|
---|
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;
|
---|
136 | end;
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 | end.
|
---|
141 |
|
---|