| 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 | 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 |
|
|---|
| 71 | var
|
|---|
| 72 | FormMain: TFormMain;
|
|---|
| 73 |
|
|---|
| 74 | implementation
|
|---|
| 75 |
|
|---|
| 76 | uses
|
|---|
| 77 | UCore, UFormSetting, UFormConnection;
|
|---|
| 78 |
|
|---|
| 79 | {$R *.lfm}
|
|---|
| 80 |
|
|---|
| 81 | { TFormMain }
|
|---|
| 82 |
|
|---|
| 83 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 84 | begin
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | procedure TFormMain.FormCreate(Sender: TObject);
|
|---|
| 88 | begin
|
|---|
| 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;
|
|---|
| 98 | end;
|
|---|
| 99 |
|
|---|
| 100 | procedure TFormMain.FormDestroy(Sender: TObject);
|
|---|
| 101 | begin
|
|---|
| 102 | Core.Done;
|
|---|
| 103 | SaveToRegistry(Core.RegistryContext);
|
|---|
| 104 | Core.PersistentForm.Save(Self);
|
|---|
| 105 | FreeAndNil(DataViewForms);
|
|---|
| 106 | FreeAndNil(DataViewLists);
|
|---|
| 107 | end;
|
|---|
| 108 |
|
|---|
| 109 | procedure TFormMain.AExitExecute(Sender: TObject);
|
|---|
| 110 | begin
|
|---|
| 111 | Close;
|
|---|
| 112 | end;
|
|---|
| 113 |
|
|---|
| 114 | procedure TFormMain.AModuleListExecute(Sender: TObject);
|
|---|
| 115 | begin
|
|---|
| 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;
|
|---|
| 126 | end;
|
|---|
| 127 |
|
|---|
| 128 | procedure TFormMain.AConnectExecute(Sender: TObject);
|
|---|
| 129 | begin
|
|---|
| 130 | FormConnection.LoadFromDatabase(Core.Database);
|
|---|
| 131 | if FormConnection.ShowModal = mrOk then begin
|
|---|
| 132 | FormConnection.SaveToDatabase(Core.Database);
|
|---|
| 133 | Core.Connect;
|
|---|
| 134 | UpdateInterface;
|
|---|
| 135 | end;
|
|---|
| 136 | end;
|
|---|
| 137 |
|
|---|
| 138 | procedure TFormMain.ADisconnectExecute(Sender: TObject);
|
|---|
| 139 | begin
|
|---|
| 140 | Core.Database.Disconnect;
|
|---|
| 141 | UpdateInterface;
|
|---|
| 142 | end;
|
|---|
| 143 |
|
|---|
| 144 | procedure TFormMain.ASettingsExecute(Sender: TObject);
|
|---|
| 145 | begin
|
|---|
| 146 | FormSetting.ShowModal;
|
|---|
| 147 | end;
|
|---|
| 148 |
|
|---|
| 149 | procedure TFormMain.AShowToolBarExecute(Sender: TObject);
|
|---|
| 150 | begin
|
|---|
| 151 | ShowToolBar := not ShowToolBar;
|
|---|
| 152 | UpdateInterface;
|
|---|
| 153 | end;
|
|---|
| 154 |
|
|---|
| 155 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 156 | begin
|
|---|
| 157 | UpdateInterface;
|
|---|
| 158 | end;
|
|---|
| 159 |
|
|---|
| 160 | procedure TFormMain.TabSheetShow(Sender: TObject);
|
|---|
| 161 | begin
|
|---|
| 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;
|
|---|
| 174 | end;
|
|---|
| 175 |
|
|---|
| 176 | procedure TFormMain.FormModuleListDestroy(Sender: TObject);
|
|---|
| 177 | begin
|
|---|
| 178 | if Assigned(Core.FormModuleList) then Core.FormModuleList := nil;
|
|---|
| 179 | end;
|
|---|
| 180 |
|
|---|
| 181 | procedure TFormMain.ReloadPages;
|
|---|
| 182 | var
|
|---|
| 183 | NewPage: TTabSheet;
|
|---|
| 184 | I: Integer;
|
|---|
| 185 | begin
|
|---|
| 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;
|
|---|
| 199 | end;
|
|---|
| 200 |
|
|---|
| 201 | procedure TFormMain.RegisterDataViewForm(View: TDataViewForm);
|
|---|
| 202 | begin
|
|---|
| 203 | DataViewForms.Add(View);
|
|---|
| 204 | end;
|
|---|
| 205 |
|
|---|
| 206 | procedure TFormMain.RegisterDataViewList(View: TDataViewList);
|
|---|
| 207 | begin
|
|---|
| 208 | DataViewLists.Add(View);
|
|---|
| 209 | end;
|
|---|
| 210 |
|
|---|
| 211 | procedure TFormMain.UnregisterDataViewForm(View: TDataViewForm);
|
|---|
| 212 | begin
|
|---|
| 213 | DataViewForms.Remove(View);
|
|---|
| 214 | end;
|
|---|
| 215 |
|
|---|
| 216 | procedure TFormMain.UnregisterDataViewList(View: TDataViewList);
|
|---|
| 217 | begin
|
|---|
| 218 | DataViewLists.Remove(View);
|
|---|
| 219 | end;
|
|---|
| 220 |
|
|---|
| 221 | procedure TFormMain.UpdateInterface;
|
|---|
| 222 | begin
|
|---|
| 223 | ToolBar1.Visible := ShowToolBar;
|
|---|
| 224 | AShowToolBar.Checked := ShowToolBar;
|
|---|
| 225 | ADisconnect.Enabled := Core.Database.Connected;
|
|---|
| 226 | end;
|
|---|
| 227 |
|
|---|
| 228 | procedure TFormMain.LoadFromRegistry(AContext: TRegistryContext);
|
|---|
| 229 | begin
|
|---|
| 230 | with TRegistryEx.Create do
|
|---|
| 231 | try
|
|---|
| 232 | Context := AContext;
|
|---|
| 233 | ShowToolBar := ReadBoolWithDefault('ShowToolBar', False);
|
|---|
| 234 | finally
|
|---|
| 235 | Free;
|
|---|
| 236 | end;
|
|---|
| 237 | end;
|
|---|
| 238 |
|
|---|
| 239 | procedure TFormMain.SaveToRegistry(AContext: TRegistryContext);
|
|---|
| 240 | begin
|
|---|
| 241 | with TRegistryEx.Create do
|
|---|
| 242 | try
|
|---|
| 243 | Context := AContext;
|
|---|
| 244 | WriteBool('ShowToolBar', ShowToolBar);
|
|---|
| 245 | finally
|
|---|
| 246 | Free;
|
|---|
| 247 | end;
|
|---|
| 248 | end;
|
|---|
| 249 |
|
|---|
| 250 | end.
|
|---|
| 251 |
|
|---|