Ignore:
Timestamp:
Aug 6, 2012, 10:49:50 AM (12 years ago)
Author:
chronos
Message:
  • Modified: API revised to slave proxy model.
  • Added: Modules can control docking of forms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/StudioPackage/UDataModule.pas

    r13 r14  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Forms, SpecializedList, USource,
    9   UModularSystem, ULDStudioAPI;
     8  Classes, SysUtils, FileUtil, Forms, ActnList, Controls, SpecializedList,
     9  USource, UModularSystem, ULDStudioAPI, Menus, ComCtrls;
    1010
    1111type
     
    4040
    4141  TDataModule1 = class(TDataModule)
     42  published
     43    ActionListRegistred: TActionList;
     44    ImageListMain: TImageList;
     45    API: TLDStudioAPI;
     46    procedure APIDockForm(Form: TForm; Target: TDockTarget);
     47    procedure APIRegisterFileType(FileType: TSourceType);
     48    procedure APIRegisterForm(Form: TForm);
     49    procedure APIRegisterMainMenuItem(MenuItem: TMenuItem;
     50      ParentItem: TMenuItem; Index: Integer);
     51    procedure APIUnregisterAction(Action: TAction);
     52    procedure APIUnregisterFileType(FileType: TSourceType);
     53    procedure APIUnregisterForm(Form: TForm);
     54    procedure APIUnregisterMainMenuItem(MenuItem: TMenuItem);
    4255    procedure DataModuleCreate(Sender: TObject);
    4356    procedure DataModuleDestroy(Sender: TObject);
     57    procedure APIOpenFile(FileName: string);
     58    procedure APIRegisterAction(Action: TAction);
    4459  private
    45     API: TLDStudioAPI;
     60    procedure DockToPageControl(PageControl: TPageControl; Form: TForm);
    4661  public
    4762    ModuleManager: TModuleManager;
     
    127142  FileTypes.OwnsObjects := False;
    128143  OpenedFiles := TOpenedFiles.Create;
    129   API := TLDStudioAPI.Create;
    130144  ModuleManager := TModuleManager.Create(nil);
    131145  ModuleManager.API := API;
     
    138152  FormModuleList := TFormModuleList.Create(nil);
    139153
    140   TLDStudioAPI(ModuleManager.API).MainForm := FormMain;
    141   TLDStudioAPI(ModuleManager.API).MainMenu := FormMain.MainMenu;
    142   TLDStudioAPI(ModuleManager.API).FileTypes := FileTypes;
    143154  FormMain.Show;
    144155end;
    145156
     157procedure TDataModule1.APIUnregisterMainMenuItem(MenuItem: TMenuItem);
     158begin
     159  MenuItem.Parent.Delete(MenuItem.Parent.IndexOf(MenuItem));
     160end;
     161
     162procedure TDataModule1.APIRegisterMainMenuItem(MenuItem: TMenuItem;
     163  ParentItem: TMenuItem; Index: Integer);
     164begin
     165  if Assigned(ParentItem) then ParentItem.Insert(Index, MenuItem)
     166    else FormMain.MainMenu.Items.Insert(Index, MenuItem);
     167end;
     168
     169procedure TDataModule1.APIRegisterForm(Form: TForm);
     170begin
     171  Form.Parent := FormMain;
     172end;
     173
     174procedure TDataModule1.APIRegisterFileType(FileType: TSourceType);
     175begin
     176  FileTypes.Add(FileType);
     177end;
     178
     179procedure TDataModule1.DockToPageControl(PageControl: TPageControl; Form: TForm
     180  );
     181var
     182  NewTabSheet: TTabSheet;
     183begin
     184  NewTabSheet := TTabSheet.Create(PageControl);
     185  NewTabSheet.Parent := PageControl;
     186  NewTabSheet.Visible := True;
     187  NewTabSheet.Caption := Form.Caption;
     188  Form.Align := alClient;
     189  Form.ManualDock(NewTabSheet, nil, alClient);
     190  Form.Visible := True;
     191end;
     192
     193procedure TDataModule1.APIDockForm(Form: TForm; Target: TDockTarget);
     194begin
     195  with FormMain do
     196  case Target of
     197    dtCenter: DockToPageControl(PageControlCenter, Form);
     198//    dtTop: DockToPageControl(PageControlTop, Form);
     199    dtLeft: DockToPageControl(PageControlLeft, Form);
     200    dtRight: DockToPageControl(PageControlRight, Form);
     201    dtBottom: DockToPageControl(PageControlBottom, Form);
     202  end;
     203end;
     204
     205procedure TDataModule1.APIUnregisterAction(Action: TAction);
     206begin
     207  Action.ActionList := nil;
     208end;
     209
     210procedure TDataModule1.APIUnregisterFileType(FileType: TSourceType);
     211begin
     212  FileTypes.Remove(FileType);
     213end;
     214
     215procedure TDataModule1.APIUnregisterForm(Form: TForm);
     216begin
     217  Form.Parent := nil;
     218end;
     219
    146220procedure TDataModule1.DataModuleDestroy(Sender: TObject);
    147221begin
    148222  FreeAndNil(ModuleManager);
    149   FreeAndNil(API);
    150223  FreeAndNil(FormMain);
    151224  FreeAndNil(FormSourceCode);
     
    156229end;
    157230
     231procedure TDataModule1.APIOpenFile(FileName: string);
     232begin
     233  OpenedFiles.OpenFile(FileName);
     234end;
     235
     236procedure TDataModule1.APIRegisterAction(Action: TAction);
     237begin
     238  Action.ActionList := ActionListRegistred;
     239end;
     240
    158241end.
    159242
Note: See TracChangeset for help on using the changeset viewer.