source: tags/1.2.0/Forms/UFormMain.pas

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