source: trunk/Forms/FormMain.pas

Last change on this file was 177, checked in by chronos, 3 months ago
  • Added: Keyboard shortcuts form accessible from Help menu.
File size: 7.3 KB
Line 
1unit FormMain;
2
3interface
4
5uses
6 Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, Menus,
7 ComCtrls, FormContacts, FormEx;
8
9type
10
11 { TFormMain }
12
13 TFormMain = class(TFormEx)
14 CoolBar1: TCoolBar;
15 MainMenu1: TMainMenu;
16 MenuItem1: TMenuItem;
17 MenuItem10: TMenuItem;
18 MenuItem11: TMenuItem;
19 MenuItem12: TMenuItem;
20 MenuItem13: TMenuItem;
21 MenuItem14: TMenuItem;
22 MenuItem15: TMenuItem;
23 MenuItem16: TMenuItem;
24 MenuItem17: TMenuItem;
25 MenuItem18: TMenuItem;
26 MenuItemColumns: TMenuItem;
27 MenuItem3: TMenuItem;
28 MenuItem4: TMenuItem;
29 MenuItem5: TMenuItem;
30 MenuItem6: TMenuItem;
31 MenuItem7: TMenuItem;
32 MenuItem8: TMenuItem;
33 MenuItem9: TMenuItem;
34 MenuItemToolbar: TMenuItem;
35 MenuItemView: TMenuItem;
36 MenuItemExit: TMenuItem;
37 MenuItemHomePage: TMenuItem;
38 MenuItemAbout: TMenuItem;
39 MenuItem2: TMenuItem;
40 MenuItemFileNew: TMenuItem;
41 MenuItemFileOpen: TMenuItem;
42 MenuItemSettings: TMenuItem;
43 MenuItemTools: TMenuItem;
44 MenuItemFileOpenRecent: TMenuItem;
45 MenuItemFileSave: TMenuItem;
46 MenuItemFileSaveAs: TMenuItem;
47 MenuItemFileClose: TMenuItem;
48 MenuItemHelp: TMenuItem;
49 MenuItemFile: TMenuItem;
50 PopupMenuOpenRecent: TPopupMenu;
51 Separator1: TMenuItem;
52 Separator2: TMenuItem;
53 ToolBarOther: TToolBar;
54 ToolBarFile: TToolBar;
55 ToolButton1: TToolButton;
56 ToolButton2: TToolButton;
57 ToolButton3: TToolButton;
58 ToolButton4: TToolButton;
59 ToolButton5: TToolButton;
60 ToolButton6: TToolButton;
61 ToolButton7: TToolButton;
62 ToolButton8: TToolButton;
63 procedure FormActivate(Sender: TObject);
64 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
65 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
66 procedure FormCreate(Sender: TObject);
67 procedure FormDestroy(Sender: TObject);
68 procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
69 procedure FormResize(Sender: TObject);
70 procedure FormShow(Sender: TObject);
71 procedure MenuItemColumnsClick(Sender: TObject);
72 procedure MenuItemToolbarClick(Sender: TObject);
73 private
74 procedure SetToolbarHints;
75 procedure UpdateFormTitle;
76 procedure DataFileChangeExecute(Sender: TObject);
77 procedure LastOpenedFileChangeExecute(Sender: TObject);
78 procedure LoadConfig;
79 procedure SaveConfig;
80 public
81 FormContacts: TFormContacts;
82 procedure UpdateInterface;
83 procedure SettingsChanged;
84 procedure ToggleFullScreen;
85 end;
86
87
88implementation
89
90{$R *.lfm}
91
92uses
93 Core, VCard, VCardFile, RegistryEx;
94
95resourcestring
96 SModified = 'Modified';
97 SOnlyOneFileCanBeDropped = 'Only one file can be dropped at once.';
98
99{ TFormMain }
100
101procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
102begin
103 SaveConfig;
104 FormContacts.Close;
105 Application.Terminate;
106end;
107
108procedure TFormMain.FormActivate(Sender: TObject);
109begin
110 Core.Core.Initialize;
111end;
112
113procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
114begin
115 Core.Core.AFileClose.Execute;
116 CanClose := Core.Core.FileClosed;
117end;
118
119procedure TFormMain.FormCreate(Sender: TObject);
120begin
121 FormContacts := TFormContacts.Create(nil);
122 Core.Core.OnDataFileChange := DataFileChangeExecute;
123 Core.Core.OnLastOpenedListChange := LastOpenedFileChangeExecute;
124 LastOpenedFileChangeExecute(Self);
125 LoadConfig;
126end;
127
128procedure TFormMain.FormDestroy(Sender: TObject);
129begin
130 Core.Core.OnDataFileChange := nil;
131 Core.Core.OnLastOpenedListChange := nil;
132 FreeAndNil(FormContacts);
133end;
134
135procedure TFormMain.FormDropFiles(Sender: TObject;
136 const FileNames: array of string);
137begin
138 if Length(FileNames) <> 1 then ShowMessage(SOnlyOneFileCanBeDropped)
139 else begin
140 Core.Core.FileOpen(FileNames[0]);
141 Core.Core.UpdateFile;
142 end;
143end;
144
145procedure TFormMain.FormResize(Sender: TObject);
146begin
147 CoolBar1.AutosizeBands;
148end;
149
150procedure TFormMain.FormShow(Sender: TObject);
151begin
152 FormContacts.BeginUpdate;
153 try
154 SetToolbarHints;
155 ScaleDPI.ScaleControl(CoolBar1, Core.Core.ScaleDPI1.DesignDPI);
156 CoolBar1.AutosizeBands;
157
158 FormContacts.Context := TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
159 Core.Core.ApplicationInfo1.RegistryKey + '\ContactsColumns');
160 FormContacts.ManualDock(Self, nil, alClient);
161 FormContacts.Align := alClient;
162 FormContacts.Show;
163 finally
164 FormContacts.EndUpdate;
165 end;
166end;
167
168procedure TFormMain.MenuItemColumnsClick(Sender: TObject);
169begin
170 FormContacts.AColumns.Execute;
171end;
172
173procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
174begin
175 UpdateInterface;
176end;
177
178procedure TFormMain.SetToolbarHints;
179var
180 I: Integer;
181 J: Integer;
182 Control: TControl;
183begin
184 for J := 0 to CoolBar1.ControlCount - 1 do begin
185 Control := CoolBar1.Controls[J];
186 if Control is TToolBar then begin
187 for I := 0 to TToolBar(Control).ButtonCount - 1 do begin
188 TToolBar(Control).Buttons[I].ShowHint := True;
189 TToolBar(Control).Buttons[I].Hint := TToolBar(Control).Buttons[I].Caption;
190 end;
191 end;
192 end;
193end;
194
195procedure TFormMain.UpdateFormTitle;
196var
197 Title: string;
198begin
199 Title := '';
200 if Assigned(Core.Core.DataFile) and
201 (ExtractFileNameWithoutExt(ExtractFileName(Core.Core.DataFile.FileName)) <> '') then
202 Title := Title + ExtractFileNameWithoutExt(ExtractFileName(Core.Core.DataFile.FileName));
203 if Assigned(Core.Core.DataFile) and Core.Core.DataFile.Modified then
204 Title := Title + ' (' + SModified + ')';
205 if Title <> '' then Title := Title + ' - ';
206 Title := Title + Core.Core.ApplicationInfo1.AppName;
207 //Application.Title := Title;
208 Caption := Title;
209end;
210
211procedure TFormMain.DataFileChangeExecute(Sender: TObject);
212begin
213 if Assigned(FormContacts) then begin
214 if Assigned(Core.Core.DataFile) then
215 FormContacts.Contacts := TVCardFile(Core.Core.DataFile).VCard.Contacts
216 else FormContacts.Contacts := nil;
217 end;
218
219 FormContacts.ReloadList;
220 FormContacts.UpdateInterface;
221 UpdateInterface;
222end;
223
224procedure TFormMain.LastOpenedFileChangeExecute(Sender: TObject);
225begin
226 Core.Core.LastOpenedList1.LoadToMenuItem(MenuItemFileOpenRecent, Core.Core.AFileOpenRecentExecute);
227 Core.Core.LastOpenedList1.LoadToMenuItem(PopupMenuOpenRecent.Items, Core.Core.AFileOpenRecentExecute);
228end;
229
230procedure TFormMain.LoadConfig;
231begin
232 with TRegistryEx.Create do
233 try
234 CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
235 MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True);
236 finally
237 Free;
238 end;
239end;
240
241procedure TFormMain.SaveConfig;
242begin
243 with TRegistryEx.Create do
244 try
245 CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
246 WriteBool('ToolBarVisible', MenuItemToolbar.Checked);
247 finally
248 Free;
249 end;
250end;
251
252procedure TFormMain.UpdateInterface;
253begin
254 UpdateFormTitle;
255 CoolBar1.Visible := MenuItemToolbar.Checked;
256 Core.Core.AFullScreen.Checked := FullScreen;
257end;
258
259procedure TFormMain.SettingsChanged;
260begin
261 ThemeManager.UseTheme(Self);
262 Translator.TranslateComponentRecursive(Self);
263 FormContacts.ThemeManager.UseTheme(FormContacts);
264 FormContacts.Translator.TranslateComponentRecursive(FormContacts);
265end;
266
267procedure TFormMain.ToggleFullScreen;
268begin
269 FullScreen := not FullScreen;
270 Core.Core.AFullScreen.Checked := FullScreen;
271 TFormEx.PersistentForm.Save(Self);
272 TFormEx.PersistentForm.SetFullScreen(FullScreen);
273 UpdateInterface;
274end;
275
276end.
277
Note: See TracBrowser for help on using the repository browser.