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