Changeset 14 for trunk/StudioCommon/ULDStudioAPI.pas
- Timestamp:
- Aug 6, 2012, 10:49:50 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/StudioCommon/ULDStudioAPI.pas
r11 r14 10 10 11 11 type 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; 12 21 13 22 { TLDStudioAPI } … … 15 24 TLDStudioAPI = class(TAPI) 16 25 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; 17 36 public 18 Actions: TActionList;19 MainForm: TForm;20 MainMenu: TMainMenu;21 FileTypes: TFileTypes;22 37 constructor Create; 23 38 destructor Destroy; override; 24 39 25 // API functions40 // API client functions 26 41 procedure OpenFile(FileName: string); 27 42 procedure RegisterFileType(FileType: TSourceType); … … 34 49 Index: Integer); 35 50 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; 36 73 end; 37 74 75 procedure Register; 76 77 38 78 implementation 79 80 procedure Register; 81 begin 82 RegisterComponents('LibreDevelop', [TLDStudioAPI]); 83 end; 39 84 40 85 { TLDStudioAPI } … … 42 87 constructor TLDStudioAPI.Create; 43 88 begin 44 Actions := TActionList.Create(nil);45 89 end; 46 90 47 91 destructor TLDStudioAPI.Destroy; 48 92 begin 49 FreeAndNil(Actions);50 93 inherited Destroy; 51 94 end; … … 53 96 procedure TLDStudioAPI.OpenFile(FileName: string); 54 97 begin 55 98 if Assigned(FOnOpenFile) then 99 FOnOpenFile(FileName); 56 100 end; 57 101 58 102 procedure TLDStudioAPI.RegisterFileType(FileType: TSourceType); 59 103 begin 60 FileTypes.Add(FileType); 104 if Assigned(FOnRegisterFileType) then 105 FOnRegisterFileType(FileType); 61 106 end; 62 107 63 108 procedure TLDStudioAPI.UnregisterFileType(FileType: TSourceType); 64 109 begin 65 FileTypes.Remove(FileType); 110 if Assigned(FOnUnregisterFileType) then 111 FOnUnregisterFileType(FileType); 66 112 end; 67 113 68 114 procedure TLDStudioAPI.RegisterForm(Form: TForm); 69 115 begin 70 Form.Parent := MainForm; 116 if Assigned(FOnRegisterForm) then 117 FOnRegisterForm(Form); 71 118 end; 72 119 73 120 procedure TLDStudioAPI.UnregisterForm(Form: TForm); 74 121 begin 75 Form.Parent := nil; 122 if Assigned(FOnUnregisterForm) then 123 FOnUnregisterForm(Form); 76 124 end; 77 125 78 126 procedure TLDStudioAPI.RegisterAction(Action: TAction); 79 127 begin 80 Action.ActionList := Actions; 128 if Assigned(FOnRegisterAction) then 129 FOnRegisterAction(Action); 81 130 end; 82 131 83 132 procedure TLDStudioAPI.UnregisterAction(Action: TAction); 84 133 begin 85 Action.ActionList := nil; 134 if Assigned(FOnUnregisterAction) then 135 FOnUnregisterAction(Action); 86 136 end; 87 137 … … 89 139 ParentItem: TMenuItem; Index: Integer); 90 140 begin 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); 93 143 end; 94 144 95 145 procedure TLDStudioAPI.UnregisterMainMenuItem(MenuItem: TMenuItem); 96 146 begin 97 MenuItem.Parent.Delete(MenuItem.Parent.IndexOf(MenuItem)); 147 if Assigned(FOnUnregisterMainMenuItem) then 148 FOnUnregisterMainMenuItem(MenuItem); 149 end; 150 151 procedure TLDStudioAPI.DockForm(Form: TForm; Target: TDockTarget); 152 begin 153 if Assigned(FOnDockForm) then 154 FOnDockForm(Form, Target); 98 155 end; 99 156
Note:
See TracChangeset
for help on using the changeset viewer.