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/StudioCommon/ULDStudioAPI.pas

    r11 r14  
    1010
    1111type
     12  TDockTarget = (dtCenter, dtLeft, dtRight, dtBottom, dtTop);
     13  TOpenFileEvent = procedure (FileName: string) of object;
     14  TRegisterFileTypeEvent = procedure (FileType: TSourceType) of object;
     15  TRegisterFormEvent = procedure (Form: TForm) of object;
     16  TRegisterActionEvent = procedure (Action: TAction) of object;
     17  TRegisterMainMenuItemEvent = procedure (MenuItem: TMenuItem; ParentItem: TMenuItem;
     18    Index: Integer) of object;
     19  TUnregisterMainMenuItemEvent = procedure (MenuItem: TMenuItem) of object;
     20  TDockFormEvent = procedure (Form: TForm; Target: TDockTarget) of object;
    1221
    1322  { TLDStudioAPI }
     
    1524  TLDStudioAPI = class(TAPI)
    1625  private
     26    FOnDockForm: TDockFormEvent;
     27    FOnOpenFile: TOpenFileEvent;
     28    FOnRegisterAction: TRegisterActionEvent;
     29    FOnRegisterFileType: TRegisterFileTypeEvent;
     30    FOnRegisterForm: TRegisterFormEvent;
     31    FOnRegisterMainMenuItem: TRegisterMainMenuItemEvent;
     32    FOnUnregisterAction: TRegisterActionEvent;
     33    FOnUnregisterFileType: TRegisterFileTypeEvent;
     34    FOnUnregisterForm: TRegisterFormEvent;
     35    FOnUnregisterMainMenuItem: TUnregisterMainMenuItemEvent;
    1736  public
    18     Actions: TActionList;
    19     MainForm: TForm;
    20     MainMenu: TMainMenu;
    21     FileTypes: TFileTypes;
    2237    constructor Create;
    2338    destructor Destroy; override;
    2439
    25     // API functions
     40    // API client functions
    2641    procedure OpenFile(FileName: string);
    2742    procedure RegisterFileType(FileType: TSourceType);
     
    3449      Index: Integer);
    3550    procedure UnregisterMainMenuItem(MenuItem: TMenuItem);
     51    procedure DockForm(Form: TForm; Target: TDockTarget);
     52
     53  published
     54    // API handling
     55    property OnOpenFile: TOpenFileEvent read FOnOpenFile write FOnOpenFile;
     56    property OnRegisterFileType: TRegisterFileTypeEvent
     57      read FOnRegisterFileType write FOnRegisterFileType;
     58    property OnUnregisterFileType: TRegisterFileTypeEvent
     59      read FOnUnregisterFileType write FOnUnregisterFileType;
     60    property OnRegisterForm: TRegisterFormEvent
     61      read FOnRegisterForm write FOnRegisterForm;
     62    property OnUnregisterForm: TRegisterFormEvent
     63      read FOnUnregisterForm write FOnUnregisterForm;
     64    property OnRegisterAction: TRegisterActionEvent
     65      read FOnRegisterAction write FOnRegisterAction;
     66    property OnUnregisterAction: TRegisterActionEvent
     67      read FOnUnregisterAction write FOnUnregisterAction;
     68    property OnRegisterMainMenuItem: TRegisterMainMenuItemEvent
     69      read FOnRegisterMainMenuItem write FOnRegisterMainMenuItem;
     70    property OnUnregisterMainMenuItem: TUnregisterMainMenuItemEvent
     71      read FOnUnregisterMainMenuItem write FOnUnregisterMainMenuItem;
     72    property OnDockForm: TDockFormEvent read FOnDockForm write FOnDockForm;
    3673  end;
    3774
     75procedure Register;
     76
     77
    3878implementation
     79
     80procedure Register;
     81begin
     82  RegisterComponents('LibreDevelop', [TLDStudioAPI]);
     83end;
    3984
    4085{ TLDStudioAPI }
     
    4287constructor TLDStudioAPI.Create;
    4388begin
    44   Actions := TActionList.Create(nil);
    4589end;
    4690
    4791destructor TLDStudioAPI.Destroy;
    4892begin
    49   FreeAndNil(Actions);
    5093  inherited Destroy;
    5194end;
     
    5396procedure TLDStudioAPI.OpenFile(FileName: string);
    5497begin
    55 
     98  if Assigned(FOnOpenFile) then
     99    FOnOpenFile(FileName);
    56100end;
    57101
    58102procedure TLDStudioAPI.RegisterFileType(FileType: TSourceType);
    59103begin
    60   FileTypes.Add(FileType);
     104  if Assigned(FOnRegisterFileType) then
     105    FOnRegisterFileType(FileType);
    61106end;
    62107
    63108procedure TLDStudioAPI.UnregisterFileType(FileType: TSourceType);
    64109begin
    65   FileTypes.Remove(FileType);
     110  if Assigned(FOnUnregisterFileType) then
     111    FOnUnregisterFileType(FileType);
    66112end;
    67113
    68114procedure TLDStudioAPI.RegisterForm(Form: TForm);
    69115begin
    70   Form.Parent := MainForm;
     116  if Assigned(FOnRegisterForm) then
     117    FOnRegisterForm(Form);
    71118end;
    72119
    73120procedure TLDStudioAPI.UnregisterForm(Form: TForm);
    74121begin
    75   Form.Parent := nil;
     122  if Assigned(FOnUnregisterForm) then
     123    FOnUnregisterForm(Form);
    76124end;
    77125
    78126procedure TLDStudioAPI.RegisterAction(Action: TAction);
    79127begin
    80   Action.ActionList := Actions;
     128  if Assigned(FOnRegisterAction) then
     129    FOnRegisterAction(Action);
    81130end;
    82131
    83132procedure TLDStudioAPI.UnregisterAction(Action: TAction);
    84133begin
    85   Action.ActionList := nil;
     134  if Assigned(FOnUnregisterAction) then
     135    FOnUnregisterAction(Action);
    86136end;
    87137
     
    89139  ParentItem: TMenuItem; Index: Integer);
    90140begin
    91   if Assigned(ParentItem) then ParentItem.Insert(Index, MenuItem)
    92     else MainMenu.Items.Insert(Index, MenuItem);
     141  if Assigned(FOnRegisterMainMenuItem) then
     142    FOnRegisterMainMenuItem(MenuItem, ParentItem, Index);
    93143end;
    94144
    95145procedure TLDStudioAPI.UnregisterMainMenuItem(MenuItem: TMenuItem);
    96146begin
    97   MenuItem.Parent.Delete(MenuItem.Parent.IndexOf(MenuItem));
     147  if Assigned(FOnUnregisterMainMenuItem) then
     148    FOnUnregisterMainMenuItem(MenuItem);
     149end;
     150
     151procedure TLDStudioAPI.DockForm(Form: TForm; Target: TDockTarget);
     152begin
     153  if Assigned(FOnDockForm) then
     154    FOnDockForm(Form, Target);
    98155end;
    99156
Note: See TracChangeset for help on using the changeset viewer.