1 | unit UFormMain;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Registry, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
9 | StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite,
|
---|
10 | UPersistentForm, UTreeState, SpecializedList, SpecializedDictionary,
|
---|
11 | URegistry, UCoolTranslator, USystem, UFormItemList;
|
---|
12 |
|
---|
13 | type
|
---|
14 | { TMainForm }
|
---|
15 |
|
---|
16 | TMainForm = class(TForm)
|
---|
17 | published
|
---|
18 | AConnect: TAction;
|
---|
19 | AAbout: TAction;
|
---|
20 | ADisconnect: TAction;
|
---|
21 | AImportStructure: TAction;
|
---|
22 | ASettings: TAction;
|
---|
23 | AToggleFullscreen: TAction;
|
---|
24 | AExit: TAction;
|
---|
25 | ActionListItem: TActionList;
|
---|
26 | ImageListActions: TImageList;
|
---|
27 | MainMenuMain: TMainMenu;
|
---|
28 | MenuItem1: TMenuItem;
|
---|
29 | MenuItem11: TMenuItem;
|
---|
30 | MenuItem12: TMenuItem;
|
---|
31 | MenuItem13: TMenuItem;
|
---|
32 | MenuItem14: TMenuItem;
|
---|
33 | MenuItem15: TMenuItem;
|
---|
34 | MenuItem16: TMenuItem;
|
---|
35 | MenuItem17: TMenuItem;
|
---|
36 | MenuItem18: TMenuItem;
|
---|
37 | MenuItem2: TMenuItem;
|
---|
38 | MenuItem20: TMenuItem;
|
---|
39 | MenuItem21: TMenuItem;
|
---|
40 | MenuItem22: TMenuItem;
|
---|
41 | MenuItem3: TMenuItem;
|
---|
42 | MenuItem4: TMenuItem;
|
---|
43 | PanelMenu: TPanel;
|
---|
44 | PanelData: TPanel;
|
---|
45 | PopupMenuItem: TPopupMenu;
|
---|
46 | Splitter1: TSplitter;
|
---|
47 | StatusBar1: TStatusBar;
|
---|
48 | ToolBar1: TToolBar;
|
---|
49 | ToolButton1: TToolButton;
|
---|
50 | ToolButton2: TToolButton;
|
---|
51 | ToolButton3: TToolButton;
|
---|
52 | ToolButton4: TToolButton;
|
---|
53 | ToolButton5: TToolButton;
|
---|
54 | procedure AAboutExecute(Sender: TObject);
|
---|
55 | procedure AConnectExecute(Sender: TObject);
|
---|
56 | procedure ADisconnectExecute(Sender: TObject);
|
---|
57 | procedure AExitExecute(Sender: TObject);
|
---|
58 | procedure AImportStructureExecute(Sender: TObject);
|
---|
59 | procedure ASettingsExecute(Sender: TObject);
|
---|
60 | procedure AToggleFullscreenExecute(Sender: TObject);
|
---|
61 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
62 | procedure FormCreate(Sender: TObject);
|
---|
63 | procedure FormDestroy(Sender: TObject);
|
---|
64 | procedure FormShow(Sender: TObject);
|
---|
65 | private
|
---|
66 | OriginalBounds: TRect;
|
---|
67 | OriginalWindowState: TWindowState;
|
---|
68 | ScreenBounds: TRect;
|
---|
69 | procedure LoadFromRegistry;
|
---|
70 | procedure SaveToRegistry;
|
---|
71 | procedure InitDock;
|
---|
72 | public
|
---|
73 | MainPanelForm: TItemListForm;
|
---|
74 | PersistentForm: TPersistentForm;
|
---|
75 | Report: TReport;
|
---|
76 | procedure UpdateInterface;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | var
|
---|
80 | MainForm: TMainForm;
|
---|
81 |
|
---|
82 | resourcestring
|
---|
83 | SItemNotFound = 'Item not found';
|
---|
84 | SObjectNotFound = 'Object not found';
|
---|
85 | SGroup = 'Groups';
|
---|
86 | SItemDeletion = 'Delete items';
|
---|
87 | SReallyWantToDelete = 'Really want to delete selected items?';
|
---|
88 |
|
---|
89 |
|
---|
90 | implementation
|
---|
91 |
|
---|
92 | uses
|
---|
93 | UFormItemView, UFormItemEdit, UFormItemAdd, UFormLogin, UFormSetting, UApplicationInfo,
|
---|
94 | UCore, UFormImportStructure, UFormAbout, UFormLoginProfile, UPDClientIni,
|
---|
95 | UPDClient, UPDClientMySQL, UPDClientXMLRPC, UFormMenu, UPDClientRegistry;
|
---|
96 |
|
---|
97 | {$R *.lfm}
|
---|
98 |
|
---|
99 | { TMainForm }
|
---|
100 |
|
---|
101 | procedure TMainForm.LoadFromRegistry;
|
---|
102 | begin
|
---|
103 | with TRegistryEx.Create do
|
---|
104 | try
|
---|
105 | RootKey := Core.RegistryRootKey;
|
---|
106 | OpenKey(Core.RegistryKey, True);
|
---|
107 | PanelMenu.Width := ReadIntegerWithDefault('GroupTreeWidth', 200);
|
---|
108 | with Core.CoolTranslator1 do
|
---|
109 | Language := Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''));
|
---|
110 | finally
|
---|
111 | Free;
|
---|
112 | end;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TMainForm.SaveToRegistry;
|
---|
116 | begin
|
---|
117 | with TRegistryEx.Create do
|
---|
118 | try
|
---|
119 | RootKey := Core.RegistryRootKey;
|
---|
120 | OpenKey(Core.RegistryKey, True);
|
---|
121 | WriteInteger('GroupTreeWidth', PanelMenu.Width);
|
---|
122 | with Core.CoolTranslator1 do
|
---|
123 | WriteString('LanguageCode', Language.Code);
|
---|
124 | finally
|
---|
125 | Free;
|
---|
126 | end;
|
---|
127 | end;
|
---|
128 |
|
---|
129 | procedure TMainForm.InitDock;
|
---|
130 | begin
|
---|
131 | MainPanelForm := TItemListForm.Create(Self);
|
---|
132 | MainPanelForm.ManualDock(PanelData, nil, alClient);
|
---|
133 | MainPanelForm.Align := alClient;
|
---|
134 | FormMenu.ManualDock(PanelMenu, nil, alClient);
|
---|
135 | FormMenu.Align := alClient;
|
---|
136 | FormMenu.Show;
|
---|
137 | end;
|
---|
138 |
|
---|
139 | procedure TMainForm.UpdateInterface;
|
---|
140 | var
|
---|
141 | I: Integer;
|
---|
142 | begin
|
---|
143 | ADisconnect.Enabled := Core.System.Active;
|
---|
144 | AConnect.Enabled := not Core.System.Active;
|
---|
145 | AImportStructure.Enabled := Core.System.Active;
|
---|
146 | if Assigned(MainPanelForm) then
|
---|
147 | Caption := MainPanelForm.Caption + ' - ' + ApplicationInfo.Name
|
---|
148 | else Caption := ApplicationInfo.Name;
|
---|
149 | Application.Title := Caption;
|
---|
150 | if Core.System.Active then
|
---|
151 | with Core.System.Client do
|
---|
152 | StatusBar1.Panels[0].Text := User + '@' + Host + ':' + IntToStr(Port) + '/' + Schema
|
---|
153 | else StatusBar1.Panels[0].Text := '';
|
---|
154 |
|
---|
155 | for I := 0 to ToolBar1.ButtonCount - 1 do
|
---|
156 | ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | procedure TMainForm.FormCreate(Sender: TObject);
|
---|
160 | begin
|
---|
161 | Report := TReport.Create;
|
---|
162 | Report.Base := Core.System;
|
---|
163 | PersistentForm := TPersistentForm.Create;
|
---|
164 | PersistentForm.RegistryKey := Core.RegistryKey;
|
---|
165 | end;
|
---|
166 |
|
---|
167 | procedure TMainForm.FormDestroy(Sender: TObject);
|
---|
168 | begin
|
---|
169 | FreeAndNil(MainPanelForm);
|
---|
170 | FreeAndNil(Report);
|
---|
171 | FreeAndNil(PersistentForm);
|
---|
172 | end;
|
---|
173 |
|
---|
174 | procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
175 | begin
|
---|
176 | ADisconnect.Execute;
|
---|
177 | PersistentForm.Save(Self);
|
---|
178 | SaveToRegistry;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | procedure TMainForm.ASettingsExecute(Sender: TObject);
|
---|
182 | begin
|
---|
183 | try
|
---|
184 | SettingForm := TSettingForm.Create(nil);
|
---|
185 | Core.CoolTranslator1.TranslateComponentRecursive(SettingForm);
|
---|
186 | SettingForm.ShowModal;
|
---|
187 | finally
|
---|
188 | SettingForm.Free;
|
---|
189 | end;
|
---|
190 | end;
|
---|
191 |
|
---|
192 | procedure TMainForm.AToggleFullscreenExecute(Sender: TObject);
|
---|
193 | begin
|
---|
194 | if BorderStyle <> bsNone then begin
|
---|
195 | // To full screen
|
---|
196 | OriginalWindowState := WindowState;
|
---|
197 | OriginalBounds := BoundsRect;
|
---|
198 |
|
---|
199 | BorderStyle := bsNone;
|
---|
200 | ScreenBounds := Screen.MonitorFromWindow(Handle).BoundsRect;
|
---|
201 | with ScreenBounds do
|
---|
202 | SetBounds(Left, Top, Right - Left, Bottom - Top) ;
|
---|
203 | end else begin
|
---|
204 | // From full screen
|
---|
205 | {$IFDEF MSWINDOWS}
|
---|
206 | BorderStyle := bsSizeable;
|
---|
207 | {$ENDIF}
|
---|
208 | if OriginalWindowState = wsMaximized then
|
---|
209 | WindowState := wsMaximized
|
---|
210 | else
|
---|
211 | with OriginalBounds do
|
---|
212 | SetBounds(Left, Top, Right - Left, Bottom - Top) ;
|
---|
213 | {$IFDEF LINUX}
|
---|
214 | BorderStyle := bsSizeable;
|
---|
215 | {$ENDIF}
|
---|
216 | end;
|
---|
217 | end;
|
---|
218 |
|
---|
219 | procedure TMainForm.AExitExecute(Sender: TObject);
|
---|
220 | begin
|
---|
221 | Close;
|
---|
222 | end;
|
---|
223 |
|
---|
224 | procedure TMainForm.AImportStructureExecute(Sender: TObject);
|
---|
225 | begin
|
---|
226 | try
|
---|
227 | ImportStructureForm := TImportStructureForm.Create(MainForm);
|
---|
228 | Core.CoolTranslator1.TranslateComponentRecursive(ImportStructureForm);
|
---|
229 | ImportStructureForm.ShowModal;
|
---|
230 | finally
|
---|
231 | ImportStructureForm.Free;
|
---|
232 | end;
|
---|
233 | end;
|
---|
234 |
|
---|
235 | procedure TMainForm.AConnectExecute(Sender: TObject);
|
---|
236 | begin
|
---|
237 | try
|
---|
238 | LoginForm := TLoginForm.Create(MainForm);
|
---|
239 | Core.CoolTranslator1.TranslateComponentRecursive(LoginForm);
|
---|
240 | Core.Profiles.LoadFromRegistry(Core.RegistryRootKey, Core.RegistryKey);
|
---|
241 | if LoginForm.ShowModal = mrOK then begin
|
---|
242 | with TConnectProfile(Core.Profiles[Core.LastProfile]) do begin
|
---|
243 | FreeAndNil(Core.System.Client);
|
---|
244 | if Protocol = cpMySQL then Core.System.Client := TPDClientMySQL.Create
|
---|
245 | //else if Protocol = cpDirect then Core.System.Client := TPDClientDirect.Create
|
---|
246 | else if Protocol = cpXMLRPC then Core.System.Client := TPDClientXMLRPC.Create
|
---|
247 | else if Protocol = cpINI then Core.System.Client := TPDClientIni.Create
|
---|
248 | else if Protocol = cpRegistry then Core.System.Client := TPDClientRegistry.Create;
|
---|
249 | Core.System.Client.Host := HostName;
|
---|
250 | Core.System.Client.Schema := Database;
|
---|
251 | Core.System.Client.User := Core.LastUserName;
|
---|
252 | Core.System.Client.Password := Core.LastPassword;
|
---|
253 | Core.System.Client.Port := Port;
|
---|
254 | end;
|
---|
255 | try
|
---|
256 | Core.System.Active := True;
|
---|
257 | FormMenu.LoadTree;
|
---|
258 | except
|
---|
259 | on E: Exception do ShowMessage(E.Message);
|
---|
260 | end;
|
---|
261 | end;
|
---|
262 | finally
|
---|
263 | LoginForm.Free;
|
---|
264 | UpdateInterface;
|
---|
265 | end;
|
---|
266 | end;
|
---|
267 |
|
---|
268 | procedure TMainForm.ADisconnectExecute(Sender: TObject);
|
---|
269 | begin
|
---|
270 | if Assigned(Core.System.Client) then
|
---|
271 | if Core.System.Active then begin
|
---|
272 | Core.System.Active := False;
|
---|
273 | FormMenu.TreeViewMenu.Items.Clear;
|
---|
274 | end;
|
---|
275 | UpdateInterface;
|
---|
276 | end;
|
---|
277 |
|
---|
278 | procedure TMainForm.AAboutExecute(Sender: TObject);
|
---|
279 | begin
|
---|
280 | try
|
---|
281 | AboutForm := TAboutForm.Create(nil);
|
---|
282 | Core.CoolTranslator1.TranslateComponentRecursive(AboutForm);
|
---|
283 | AboutForm.ShowModal;
|
---|
284 | finally
|
---|
285 | FreeAndNil(AboutForm);
|
---|
286 | end;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | procedure TMainForm.FormShow(Sender: TObject);
|
---|
290 | begin
|
---|
291 | PersistentForm.Load(Self);
|
---|
292 | LoadFromRegistry;
|
---|
293 | InitDock;
|
---|
294 | AConnect.Execute;
|
---|
295 | end;
|
---|
296 |
|
---|
297 | end.
|
---|
298 |
|
---|