source: tags/1.4.0/Forms/UFormMain.pas

Last change on this file was 138, checked in by chronos, 3 years ago
  • Added: Allow to configure visible columns in contacts table.
File size: 4.8 KB
Line 
1unit UFormMain;
2
3interface
4
5uses
6 Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, Menus,
7 ComCtrls;
8
9type
10
11 { TFormMain }
12
13 TFormMain = class(TForm)
14 CoolBar1: TCoolBar;
15 MainMenu1: TMainMenu;
16 MenuItem1: TMenuItem;
17 MenuItem10: TMenuItem;
18 MenuItem11: TMenuItem;
19 MenuItem12: TMenuItem;
20 MenuItem13: TMenuItem;
21 MenuItemColumns: TMenuItem;
22 MenuItem3: TMenuItem;
23 MenuItem4: TMenuItem;
24 MenuItem5: TMenuItem;
25 MenuItem6: TMenuItem;
26 MenuItem7: TMenuItem;
27 MenuItem8: TMenuItem;
28 MenuItem9: TMenuItem;
29 MenuItemToolbar: TMenuItem;
30 MenuItemView: TMenuItem;
31 MenuItemExit: TMenuItem;
32 MenuItemHomePage: TMenuItem;
33 MenuItemAbout: TMenuItem;
34 MenuItem2: TMenuItem;
35 MenuItemFileNew: TMenuItem;
36 MenuItemFileOpen: TMenuItem;
37 MenuItemSettings: TMenuItem;
38 MenuItemTools: TMenuItem;
39 MenuItemFileOpenRecent: TMenuItem;
40 MenuItemFileSave: TMenuItem;
41 MenuItemFileSaveAs: TMenuItem;
42 MenuItemFileClose: TMenuItem;
43 MenuItemHelp: TMenuItem;
44 MenuItemFile: TMenuItem;
45 PopupMenuOpenRecent: TPopupMenu;
46 ToolBarOther: TToolBar;
47 ToolBarFile: TToolBar;
48 ToolButton1: TToolButton;
49 ToolButton2: TToolButton;
50 ToolButton3: TToolButton;
51 ToolButton4: TToolButton;
52 ToolButton5: TToolButton;
53 ToolButton6: TToolButton;
54 ToolButton7: TToolButton;
55 ToolButton8: TToolButton;
56 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
57 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
58 procedure FormCreate(Sender: TObject);
59 procedure FormDestroy(Sender: TObject);
60 procedure FormResize(Sender: TObject);
61 procedure FormShow(Sender: TObject);
62 procedure MenuItemColumnsClick(Sender: TObject);
63 procedure MenuItemToolbarClick(Sender: TObject);
64 private
65 procedure SetToolbarHints;
66 procedure UpdateFormTitle;
67 public
68 procedure UpdateInterface;
69 end;
70
71var
72 FormMain: TFormMain;
73
74
75implementation
76
77{$R *.lfm}
78
79uses
80 UCore, UFormContacts, UVCard, UVCardFile, URegistry;
81
82resourcestring
83 SModified = 'Modified';
84
85{ TFormMain }
86
87procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
88begin
89 FormContacts.Close;
90 Core.PersistentForm1.Save(Self);
91end;
92
93procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
94begin
95 Core.AFileClose.Execute;
96 CanClose := Core.FileClosed;
97end;
98
99procedure TFormMain.FormCreate(Sender: TObject);
100begin
101 FormContacts := TFormContacts.Create(nil);
102end;
103
104procedure TFormMain.FormDestroy(Sender: TObject);
105begin
106 FreeAndNil(FormContacts);
107end;
108
109procedure TFormMain.FormResize(Sender: TObject);
110begin
111 CoolBar1.AutosizeBands;
112end;
113
114procedure TFormMain.FormShow(Sender: TObject);
115begin
116 FormContacts.BeginUpdate;
117 try
118 SetToolbarHints;
119 Core.Initialize;
120 Core.ThemeManager1.UseTheme(Self);
121 Core.PersistentForm1.Load(Self);
122 Core.ScaleDPI1.ScaleControl(CoolBar1, Core.ScaleDPI1.DesignDPI);
123 CoolBar1.AutosizeBands;
124
125 FormContacts.Context := TRegistryContext.Create(Core.ApplicationInfo1.RegistryRoot,
126 Core.ApplicationInfo1.RegistryKey + '\ContactsColumns');
127 FormContacts.Contacts := TVCardFile(Core.DataFile).VCard.Contacts;
128 FormContacts.ManualDock(Self, nil, alClient);
129 FormContacts.Align := alClient;
130 FormContacts.Show;
131 finally
132 FormContacts.EndUpdate;
133 end;
134end;
135
136procedure TFormMain.MenuItemColumnsClick(Sender: TObject);
137begin
138 FormContacts.AColumns.Execute;
139end;
140
141procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
142begin
143 UpdateInterface;
144end;
145
146procedure TFormMain.SetToolbarHints;
147var
148 I: Integer;
149 J: Integer;
150 Control: TControl;
151begin
152 for J := 0 to CoolBar1.ControlCount - 1 do begin
153 Control := CoolBar1.Controls[J];
154 if Control is TToolBar then begin
155 for I := 0 to TToolBar(Control).ButtonCount - 1 do begin
156 TToolBar(Control).Buttons[I].ShowHint := True;
157 TToolBar(Control).Buttons[I].Hint := TToolBar(Control).Buttons[I].Caption;
158 end;
159 end;
160 end;
161end;
162
163procedure TFormMain.UpdateFormTitle;
164var
165 Title: string;
166begin
167 Title := '';
168 if Assigned(Core.DataFile) and
169 (ExtractFileNameWithoutExt(ExtractFileName(Core.DataFile.FileName)) <> '') then
170 Title := Title + ExtractFileNameWithoutExt(ExtractFileName(Core.DataFile.FileName));
171 if Assigned(Core.DataFile) and Core.DataFile.Modified then
172 Title := Title + ' (' + SModified + ')';
173 if Title <> '' then Title := Title + ' - ';
174 Title := Title + Core.ApplicationInfo1.AppName;
175 //Application.Title := Title;
176 Caption := Title;
177end;
178
179procedure TFormMain.UpdateInterface;
180begin
181 UpdateFormTitle;
182 CoolBar1.Visible := MenuItemToolbar.Checked;
183end;
184
185end.
186
Note: See TracBrowser for help on using the repository browser.