source: trunk/Forms/UMainForm.pas

Last change on this file was 2, checked in by george, 15 years ago
  • Modified: CodeEdit window is now dockable rather than MDI child.
  • Modified: Main menu changed to ActionMainMenuBar with XP style.
File size: 7.3 KB
Line 
1unit UMainForm;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, Menus, ExtCtrls, StdCtrls, ComCtrls, DockPanel, URegistry,
8 UApplicationInfo, UDockManagement, ActnList, XPStyleActnCtrls, ActnMan,
9 UProject, XPMan, ImgList, DockManagerPro, StdStyleActnCtrls, ToolWin,
10 ActnCtrls, ActnMenus;
11
12type
13 TMainForm = class(TForm)
14 DockPanel1: TDockPanel;
15 DockPanel2: TDockPanel;
16 DockPanel3: TDockPanel;
17 ActionManager1: TActionManager;
18 ActionExit: TAction;
19 ActionProjectOpen: TAction;
20 ActionProjectSaveAs: TAction;
21 ActionFileOpen: TAction;
22 ActionFileSave: TAction;
23 ActionFileClose: TAction;
24 ActionFileCloseAll: TAction;
25 ActionUnitTest: TAction;
26 ActionPrint: TAction;
27 ActionFileSaveAs: TAction;
28 ImageList1: TImageList;
29 ActionMainMenuBar1: TActionMainMenuBar;
30 ActionFile: TAction;
31 ActionFileNew: TAction;
32 ActionFileReopen: TAction;
33 ActionFileSaveAll: TAction;
34 ActionEdit: TAction;
35 OpenDialog1: TOpenDialog;
36 SaveDialog1: TSaveDialog;
37 FindDialog1: TFindDialog;
38 ReplaceDialog1: TReplaceDialog;
39 ActionEditUndo: TAction;
40 ActionEditRedo: TAction;
41 ActionEditCut: TAction;
42 ActionEditCopy: TAction;
43 ActionEditPaste: TAction;
44 ActionEditDelete: TAction;
45 ActionEditSelectAll: TAction;
46 ActionEditAlignToGrid: TAction;
47 ActionEditBringToFront: TAction;
48 ActionEditSendToBack: TAction;
49 ActionEditAlign: TAction;
50 ActionEditSize: TAction;
51 ActionEditScale: TAction;
52 ActionEditTabOrder: TAction;
53 ActionEditCreationOrder: TAction;
54 ActionEditFlipChildren: TAction;
55 ActionEditLockControls: TAction;
56 ActionSearch: TAction;
57 ActionView: TAction;
58 ActionProject: TAction;
59 ActionRun: TAction;
60 ActionComponent: TAction;
61 ActionTools: TAction;
62 ActionWindow: TAction;
63 ActionHelp: TAction;
64 procedure FormShow(Sender: TObject);
65 procedure ObjectInspector1Click(Sender: TObject);
66 procedure oolPalete1Click(Sender: TObject);
67 procedure Structure1Click(Sender: TObject);
68 procedure ProjectManager1Click(Sender: TObject);
69 procedure FormClose(Sender: TObject; var Action: TCloseAction);
70 procedure FormCreate(Sender: TObject);
71 procedure FormDestroy(Sender: TObject);
72 procedure ActionExitExecute(Sender: TObject);
73 procedure ActionFileUpdate(Sender: TObject);
74 procedure ActionEditExecute(Sender: TObject);
75 procedure ActionProjectOpenExecute(Sender: TObject);
76 procedure ActionFileOpenExecute(Sender: TObject);
77 procedure ActionProjectSaveAsExecute(Sender: TObject);
78 private
79 CustomDockManager: TDDockManager;
80 BaseDockPanel: TDBaseDockPanel;
81 RegistryRootKey: HKEY;
82 RegistryKey: string;
83 procedure LoadFormPosition(Form: TForm);
84 procedure SaveFormPosition(Form: TForm);
85 { Private declarations }
86 public
87
88 end;
89
90var
91 MainForm: TMainForm;
92
93implementation
94
95uses UObjectInspector, UCodeEdit, UComponentPalette, UStructureView,
96 UProjectManager;
97
98{$R *.dfm}
99
100procedure TMainForm.ActionEditExecute(Sender: TObject);
101begin
102 //
103end;
104
105procedure TMainForm.ActionExitExecute(Sender: TObject);
106begin
107 Close;
108end;
109
110procedure TMainForm.ActionFileOpenExecute(Sender: TObject);
111begin
112 if OpenDialog1.Execute then begin
113 end;
114end;
115
116procedure TMainForm.ActionFileUpdate(Sender: TObject);
117begin
118 //
119end;
120
121procedure TMainForm.ActionProjectOpenExecute(Sender: TObject);
122begin
123 if OpenDialog1.Execute then begin
124 end;
125end;
126
127procedure TMainForm.ActionProjectSaveAsExecute(Sender: TObject);
128begin
129 if SaveDialog1.Execute then begin
130 end;
131end;
132
133procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
134begin
135 SaveFormPosition(Self);
136 CustomDockManager.SaveToRegistry;
137end;
138
139procedure TMainForm.FormCreate(Sender: TObject);
140begin
141 RegistryRootKey := HKEY_CURRENT_USER;
142 RegistryKey := ApplicationInfo.CompanyName + '\' + ApplicationInfo.Name;
143 //LoadFromRegistry;
144
145 CustomDockManager := TDDockManager.Create(Self);
146 CustomDockManager.RegistryKey := RegistryKey;
147 BaseDockPanel := TDBaseDockPanel.Create(Self);
148 with BaseDockPanel do begin
149 Parent := Self;
150 Align := alClient;
151 Visible := True;
152 BevelOuter := bvNone;
153 end;
154 CustomDockManager.BaseDockPanel := BaseDockPanel;
155end;
156
157procedure TMainForm.FormDestroy(Sender: TObject);
158begin
159 CustomDockManager.Free;
160end;
161
162procedure TMainForm.FormShow(Sender: TObject);
163begin
164 // Init dock init list
165 with CustomDockManager do begin
166 RegisterDockForm(ComponentPalette, 100, 400, 'PanelLeft', True);
167 RegisterDockForm(ProjectManager, 100, 400, 'PanelLeft', True);
168 RegisterDockForm(ObjectInspector, 100, 400, 'PanelRight', True);
169 RegisterDockForm(StructureView, 100, 400, 'PanelRight', True);
170 RegisterDockForm(CodeEdit, 500, 400, 'PanelCenter', True);
171 with BaseDockPanel do begin
172 PanelLeft.Tag := 300;
173 PanelTop.Tag := 150;
174 PanelRight.Tag := 150;
175 PanelBottom.Tag := 150;
176 end;
177 end;
178 CustomDockManager.LoadFromRegistry;
179
180 LoadFormPosition(Self);
181 CodeEdit.Show;
182 ActionManager1.Style := XPStyle;
183end;
184
185procedure TMainForm.ObjectInspector1Click(Sender: TObject);
186begin
187 with ObjectInspector do Visible := not Visible;
188end;
189
190procedure TMainForm.oolPalete1Click(Sender: TObject);
191begin
192 with ComponentPalette do Visible := not Visible;
193end;
194
195procedure TMainForm.ProjectManager1Click(Sender: TObject);
196begin
197 with ProjectManager do Visible := not Visible;
198end;
199
200procedure TMainForm.Structure1Click(Sender: TObject);
201begin
202 with StructureView do Visible := not Visible;
203end;
204
205procedure TMainForm.LoadFormPosition(Form: TForm);
206begin
207 with Form, TRegistryEx.Create do
208 try
209 RootKey := RegistryRootKey;
210 OpenKey(RegistryKey + '\Forms\' + Form.Name, True);
211 Width := ReadIntegerWithDefault('Width', Width);
212 Height := ReadIntegerWithDefault('Height', Height);
213 Top := ReadIntegerWithDefault('Top', (Screen.Height - Height) div 2);
214 Left := ReadIntegerWithDefault('Left', (Screen.Width - Width) div 2);
215 if Left < 0 then Left := 0;
216 if Left > (Screen.Width - 50) then Left := Screen.Width - 50;
217 if Top < 0 then Top := 0;
218 if Top > (Screen.Height - 50) then Top := Screen.Height - 50;
219 if ReadBoolWithDefault('Maximized', False) then begin
220 WindowState := wsMaximized;
221 end;
222 finally
223 Free;
224 end;
225end;
226
227procedure TMainForm.SaveFormPosition(Form: TForm);
228var
229 Pl : TWindowPlacement; // used for API call
230 R: TRect; // used for wdw pos
231begin
232 {Calculate window's normal size and position using
233 Windows API call - the form's Width, Height, Top and
234 Left properties will give maximized window size if
235 form is maximised, which is not what we want here}
236 Pl.Length := SizeOf(TWindowPlacement);
237 GetWindowPlacement(Form.Handle, @Pl);
238 R := Pl.rcNormalPosition;
239
240 with Form, TRegistryEx.Create do
241 try
242 RootKey := RegistryRootKey;
243 OpenKey(RegistryKey + '\Forms\' + Form.Name, True);
244 WriteInteger('Width', R.Right - R.Left);
245 WriteInteger('Height', R.Bottom - R.Top);
246 WriteInteger('Top', R.Top);
247 WriteInteger('Left', R.Left);
248 WriteBool('Maximized', WindowState = wsMaximized);
249 finally
250 Free;
251 end;
252end;
253
254end.
Note: See TracBrowser for help on using the repository browser.