source: trunk/Forms/UFormMain.pas@ 131

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