source: trunk/Packages/ChronisPlatform/Forms/UFormMain.pas

Last change on this file was 5, checked in by chronos, 12 years ago
  • Added: Required packages.
File size: 6.3 KB
Line 
1unit UFormMain;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 Menus, ActnList, UFormList, SpecializedList, UFormEdit, UFormModuleList,
10 URegistry;
11
12type
13
14 { TFormMain }
15
16 TFormMain = class(TForm)
17 AConnect: TAction;
18 ADisconnect: TAction;
19 AShowToolBar: TAction;
20 AModuleList: TAction;
21 ASettings: TAction;
22 AExit: TAction;
23 ActionList1: TActionList;
24 ImageList1: TImageList;
25 MainMenu1: TMainMenu;
26 MenuItem1: TMenuItem;
27 MenuItem3: TMenuItem;
28 MenuItem4: TMenuItem;
29 MenuItem5: TMenuItem;
30 MenuItem6: TMenuItem;
31 MenuItem7: TMenuItem;
32 MenuItem8: TMenuItem;
33 MenuItem9: TMenuItem;
34 MenuItemSystem: TMenuItem;
35 MenuItem2: TMenuItem;
36 PageControl1: TPageControl;
37 StatusBar1: TStatusBar;
38 ToolBar1: TToolBar;
39 ToolButton1: TToolButton;
40 ToolButton2: TToolButton;
41 ToolButton3: TToolButton;
42 ToolButton4: TToolButton;
43 procedure AConnectExecute(Sender: TObject);
44 procedure ADisconnectExecute(Sender: TObject);
45 procedure AExitExecute(Sender: TObject);
46 procedure AModuleListExecute(Sender: TObject);
47 procedure ASettingsExecute(Sender: TObject);
48 procedure AShowToolBarExecute(Sender: TObject);
49 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
50 procedure FormCreate(Sender: TObject);
51 procedure FormDestroy(Sender: TObject);
52 procedure FormShow(Sender: TObject);
53 procedure TabSheetShow(Sender: TObject);
54 private
55 ShowToolBar: Boolean;
56 procedure FormModuleListDestroy(Sender: TObject);
57 public
58 DataViewLists: TListObject; // TListObject<TDataViewList>
59 DataViewForms: TListObject; // TListObject<TDataViewForm>
60 procedure RegisterDataViewForm(View: TDataViewForm);
61 procedure RegisterDataViewList(View: TDataViewList);
62 procedure UnregisterDataViewForm(View: TDataViewForm);
63 procedure UnregisterDataViewList(View: TDataViewList);
64
65 procedure ReloadPages;
66 procedure UpdateInterface;
67 procedure LoadFromRegistry(AContext: TRegistryContext);
68 procedure SaveToRegistry(AContext: TRegistryContext);
69 end;
70
71var
72 FormMain: TFormMain;
73
74implementation
75
76uses
77 UCore, UFormSetting, UFormConnection;
78
79{$R *.lfm}
80
81{ TFormMain }
82
83procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
84begin
85end;
86
87procedure TFormMain.FormCreate(Sender: TObject);
88begin
89 DataViewLists := TListObject.Create;
90 DataViewLists.OwnsObjects := False;
91 DataViewForms := TListObject.Create;
92 DataViewForms.OwnsObjects := False;
93
94 LoadFromRegistry(Core.RegistryContext);
95 Core.Init;
96 Core.PersistentForm.Load(Self);
97 ReloadPages;
98end;
99
100procedure TFormMain.FormDestroy(Sender: TObject);
101begin
102 Core.Done;
103 SaveToRegistry(Core.RegistryContext);
104 Core.PersistentForm.Save(Self);
105 FreeAndNil(DataViewForms);
106 FreeAndNil(DataViewLists);
107end;
108
109procedure TFormMain.AExitExecute(Sender: TObject);
110begin
111 Close;
112end;
113
114procedure TFormMain.AModuleListExecute(Sender: TObject);
115begin
116 if not Assigned(Core.FormModuleList) then begin
117 Core.FormModuleList := TFormModuleList.Create(FormMain);
118 Core.FormModuleList.Manager := Core.ModuleManager;
119 Core.FormModuleList.AddHandlerOnBeforeDestruction(FormModuleListDestroy);
120 Core.FormModuleList.Options := [mloAllowEnable, mloShowEnable,
121 mloAllowInstall, mloShowDescription, mloShowDependencies, mloShowInfoBar,
122 mloShowInstalled];
123 Core.CoolTranslator1.TranslateComponentRecursive(Core.FormModuleList)
124 end;
125 Core.FormModuleList.Show;
126end;
127
128procedure TFormMain.AConnectExecute(Sender: TObject);
129begin
130 FormConnection.LoadFromDatabase(Core.Database);
131 if FormConnection.ShowModal = mrOk then begin
132 FormConnection.SaveToDatabase(Core.Database);
133 Core.Connect;
134 UpdateInterface;
135 end;
136end;
137
138procedure TFormMain.ADisconnectExecute(Sender: TObject);
139begin
140 Core.Database.Disconnect;
141 UpdateInterface;
142end;
143
144procedure TFormMain.ASettingsExecute(Sender: TObject);
145begin
146 FormSetting.ShowModal;
147end;
148
149procedure TFormMain.AShowToolBarExecute(Sender: TObject);
150begin
151 ShowToolBar := not ShowToolBar;
152 UpdateInterface;
153end;
154
155procedure TFormMain.FormShow(Sender: TObject);
156begin
157 UpdateInterface;
158end;
159
160procedure TFormMain.TabSheetShow(Sender: TObject);
161begin
162 if Assigned(Core.FormList) then Core.FormList.Free;
163 Core.FormList := TFormList.Create(Self);
164 Core.CoolTranslator1.TranslateComponentRecursive(Core.FormList);
165 with TFormList(Core.FormList) do begin
166 ManualDock(TTabSheet(Sender));
167 Align := alClient;
168 Show;
169 if TTabSheet(Sender).Tag < DataViewLists.Count then
170 View := TDataViewList(DataViewLists[TTabSheet(Sender).Tag])
171 else View := nil;
172 UpdateData;
173 end;
174end;
175
176procedure TFormMain.FormModuleListDestroy(Sender: TObject);
177begin
178 if Assigned(Core.FormModuleList) then Core.FormModuleList := nil;
179end;
180
181procedure TFormMain.ReloadPages;
182var
183 NewPage: TTabSheet;
184 I: Integer;
185begin
186 if Assigned(Core.FormList) then FreeAndNil(Core.FormList);
187 for I := PageControl1.PageCount - 1 downto 0 do
188 PageControl1.Pages[I].Free;
189 for I := 0 to DataViewLists.Count - 1 do
190 with TDataViewList(DataViewLists[I]) do begin
191 NewPage := TTabSheet.Create(PageControl1);
192 NewPage.Caption := Caption;
193 NewPage.Tag := I;
194 NewPage.ImageIndex := ImageIndex;
195 NewPage.OnShow := TabSheetShow;
196 NewPage.PageControl := PageControl1;
197 NewPage.Visible := True;
198 end;
199end;
200
201procedure TFormMain.RegisterDataViewForm(View: TDataViewForm);
202begin
203 DataViewForms.Add(View);
204end;
205
206procedure TFormMain.RegisterDataViewList(View: TDataViewList);
207begin
208 DataViewLists.Add(View);
209end;
210
211procedure TFormMain.UnregisterDataViewForm(View: TDataViewForm);
212begin
213 DataViewForms.Remove(View);
214end;
215
216procedure TFormMain.UnregisterDataViewList(View: TDataViewList);
217begin
218 DataViewLists.Remove(View);
219end;
220
221procedure TFormMain.UpdateInterface;
222begin
223 ToolBar1.Visible := ShowToolBar;
224 AShowToolBar.Checked := ShowToolBar;
225 ADisconnect.Enabled := Core.Database.Connected;
226end;
227
228procedure TFormMain.LoadFromRegistry(AContext: TRegistryContext);
229begin
230 with TRegistryEx.Create do
231 try
232 Context := AContext;
233 ShowToolBar := ReadBoolWithDefault('ShowToolBar', False);
234 finally
235 Free;
236 end;
237end;
238
239procedure TFormMain.SaveToRegistry(AContext: TRegistryContext);
240begin
241 with TRegistryEx.Create do
242 try
243 Context := AContext;
244 WriteBool('ShowToolBar', ShowToolBar);
245 finally
246 Free;
247 end;
248end;
249
250end.
251
Note: See TracBrowser for help on using the repository browser.