mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-02 14:32:36 +02:00
MG: component editors can now add menuitems to the designer popupmenu
git-svn-id: trunk@1994 -
This commit is contained in:
parent
33c0df6f93
commit
0b6577c626
@ -37,8 +37,8 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, LCLType, LCLLinux, Forms, Controls, LMessages, GraphType, Graphics,
|
Classes, LCLType, LCLLinux, Forms, Controls, LMessages, GraphType, Graphics,
|
||||||
ControlSelection, CustomFormEditor, FormEditor, UnitEditor, CompReg, Menus,
|
Dialogs, ControlSelection, CustomFormEditor, FormEditor, UnitEditor, CompReg,
|
||||||
AlignCompsDlg, SizeCompsDlg, ScaleCompsDlg, ExtCtrls, EnvironmentOpts,
|
Menus, AlignCompsDlg, SizeCompsDlg, ScaleCompsDlg, ExtCtrls, EnvironmentOpts,
|
||||||
DesignerProcs, PropEdits, ComponentEditors;
|
DesignerProcs, PropEdits, ComponentEditors;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -67,9 +67,7 @@ type
|
|||||||
FFormEditor : TFormEditor;
|
FFormEditor : TFormEditor;
|
||||||
FSourceEditor : TSourceEditor;
|
FSourceEditor : TSourceEditor;
|
||||||
FFlags: TDesignerFlags;
|
FFlags: TDesignerFlags;
|
||||||
//FHasSized: boolean;
|
|
||||||
FGridColor: TColor;
|
FGridColor: TColor;
|
||||||
//FDuringPaintControl: boolean;
|
|
||||||
FOnAddComponent: TOnAddComponent;
|
FOnAddComponent: TOnAddComponent;
|
||||||
FOnComponentListChanged: TNotifyEvent;
|
FOnComponentListChanged: TNotifyEvent;
|
||||||
FOnGetSelectedComponentClass: TOnGetSelectedComponentClass;
|
FOnGetSelectedComponentClass: TOnGetSelectedComponentClass;
|
||||||
@ -89,11 +87,11 @@ type
|
|||||||
FSizeMenuItem: TMenuItem;
|
FSizeMenuItem: TMenuItem;
|
||||||
FBringToFrontMenuItem: TMenuItem;
|
FBringToFrontMenuItem: TMenuItem;
|
||||||
FSendToBackMenuItem: TMenuItem;
|
FSendToBackMenuItem: TMenuItem;
|
||||||
//FShowHints: boolean;
|
|
||||||
|
|
||||||
//hint stuff
|
//hint stuff
|
||||||
FHintTimer : TTimer;
|
FHintTimer : TTimer;
|
||||||
FHintWIndow : THintWindow;
|
FHintWIndow : THintWindow;
|
||||||
|
|
||||||
function GetGridColor: TColor;
|
function GetGridColor: TColor;
|
||||||
function GetShowGrid: boolean;
|
function GetShowGrid: boolean;
|
||||||
function GetGridSizeX: integer;
|
function GetGridSizeX: integer;
|
||||||
@ -117,6 +115,7 @@ type
|
|||||||
MouseDownClickCount: integer;
|
MouseDownClickCount: integer;
|
||||||
MouseUpPos: TPoint;
|
MouseUpPos: TPoint;
|
||||||
LastMouseMovePos: TPoint;
|
LastMouseMovePos: TPoint;
|
||||||
|
PopupMenuComponentEditor: TBaseComponentEditor;
|
||||||
|
|
||||||
function PaintControl(Sender: TControl; TheMessage: TLMPaint):boolean;
|
function PaintControl(Sender: TControl; TheMessage: TLMPaint):boolean;
|
||||||
function SizeControl(Sender: TControl; TheMessage: TLMSize):boolean;
|
function SizeControl(Sender: TControl; TheMessage: TLMSize):boolean;
|
||||||
@ -143,7 +142,8 @@ type
|
|||||||
procedure OnBringToFrontMenuClick(Sender: TObject);
|
procedure OnBringToFrontMenuClick(Sender: TObject);
|
||||||
procedure OnSendToBackMenuClick(Sender: TObject);
|
procedure OnSendToBackMenuClick(Sender: TObject);
|
||||||
Procedure OnFormActivated;
|
Procedure OnFormActivated;
|
||||||
|
procedure OnComponentEditorVerbMenuItemClick(Sender: TObject);
|
||||||
|
|
||||||
function GetPropertyEditorHook: TPropertyEditorHook; override;
|
function GetPropertyEditorHook: TPropertyEditorHook; override;
|
||||||
public
|
public
|
||||||
ControlSelection : TControlSelection;
|
ControlSelection : TControlSelection;
|
||||||
@ -161,6 +161,9 @@ type
|
|||||||
function NonVisualComponentLeftTop(AComponent: TComponent): TPoint;
|
function NonVisualComponentLeftTop(AComponent: TComponent): TPoint;
|
||||||
function NonVisualComponentAtPos(x,y: integer): TComponent;
|
function NonVisualComponentAtPos(x,y: integer): TComponent;
|
||||||
function GetDesignedComponent(AComponent: TComponent): TComponent;
|
function GetDesignedComponent(AComponent: TComponent): TComponent;
|
||||||
|
function GetComponentEditorForSelection: TBaseComponentEditor;
|
||||||
|
procedure AddComponentEditorMenuItems(
|
||||||
|
AComponentEditor: TBaseComponentEditor; AParentMenuItem: TMenuItem);
|
||||||
|
|
||||||
function IsDesignMsg(Sender: TControl;
|
function IsDesignMsg(Sender: TControl;
|
||||||
var TheMessage: TLMessage): Boolean; override;
|
var TheMessage: TLMessage): Boolean; override;
|
||||||
@ -343,11 +346,11 @@ begin
|
|||||||
except
|
except
|
||||||
on E: Exception do begin
|
on E: Exception do begin
|
||||||
writeln('TDesigner.InvokeComponentEditor ERROR: ',E.Message);
|
writeln('TDesigner.InvokeComponentEditor ERROR: ',E.Message);
|
||||||
{MessageDlg('Error in '+CompEditor.ClassName,
|
MessageDlg('Error in '+CompEditor.ClassName,
|
||||||
'The component editor of class "'+CompEditor.ClassName+'"'
|
'The component editor of class "'+CompEditor.ClassName+'"'
|
||||||
+'has created an error:'#13
|
+'has created the error:'#13
|
||||||
+'"'+E.Message+'"',
|
+'"'+E.Message+'"',
|
||||||
mtError,[mbOk],0);}
|
mtError,[mbOk],0);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -815,6 +818,7 @@ begin
|
|||||||
SetCaptureControl(nil);
|
SetCaptureControl(nil);
|
||||||
|
|
||||||
MouseUpPos:=GetFormRelativeMousePosition(Form);
|
MouseUpPos:=GetFormRelativeMousePosition(Form);
|
||||||
|
PopupMenuComponentEditor:=GetComponentEditorForSelection;
|
||||||
BuildPopupMenu;
|
BuildPopupMenu;
|
||||||
FPopupMenu.Popup(MouseUpPos.X,MouseUpPos.Y);
|
FPopupMenu.Popup(MouseUpPos.X,MouseUpPos.Y);
|
||||||
end;
|
end;
|
||||||
@ -953,6 +957,7 @@ Begin
|
|||||||
writeln('[TDesigner.Notification] opRemove ',
|
writeln('[TDesigner.Notification] opRemove ',
|
||||||
AComponent.Name,':',AComponent.ClassName);
|
AComponent.Name,':',AComponent.ClassName);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
PopupMenuComponentEditor:=nil;
|
||||||
ControlSelection.Remove(AComponent);
|
ControlSelection.Remove(AComponent);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1045,6 +1050,32 @@ Begin
|
|||||||
OnRenameComponent(Self,AComponent,NewName);
|
OnRenameComponent(Self,AComponent,NewName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDesigner.OnComponentEditorVerbMenuItemClick(Sender: TObject);
|
||||||
|
var
|
||||||
|
Verb: integer;
|
||||||
|
VerbCaption: string;
|
||||||
|
AMenuItem: TMenuItem;
|
||||||
|
begin
|
||||||
|
if (PopupMenuComponentEditor=nil) or (Sender=nil) then exit;
|
||||||
|
if not (Sender is TMenuItem) then exit;
|
||||||
|
AMenuItem:=TMenuItem(Sender);
|
||||||
|
Verb:=AMenuItem.MenuIndex;
|
||||||
|
VerbCaption:=AMenuItem.Caption;
|
||||||
|
try
|
||||||
|
PopupMenuComponentEditor.ExecuteVerb(Verb);
|
||||||
|
except
|
||||||
|
on E: Exception do begin
|
||||||
|
writeln('TDesigner.OnComponentEditorVerbMenuItemClick ERROR: ',E.Message);
|
||||||
|
MessageDlg('Error in '+PopupMenuComponentEditor.ClassName,
|
||||||
|
'The component editor of class "'+PopupMenuComponentEditor.ClassName+'"'#13
|
||||||
|
+'invoked with verb #'+IntToStr(Verb)+' "'+VerbCaption+'"'#13
|
||||||
|
+'has created the error:'#13
|
||||||
|
+'"'+E.Message+'"',
|
||||||
|
mtError,[mbOk],0);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TDesigner.GetGridColor: TColor;
|
function TDesigner.GetGridColor: TColor;
|
||||||
begin
|
begin
|
||||||
Result:=EnvironmentOptions.GridColor;
|
Result:=EnvironmentOptions.GridColor;
|
||||||
@ -1181,6 +1212,37 @@ begin
|
|||||||
Result:=TControl(Result).Parent;
|
Result:=TControl(Result).Parent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TDesigner.GetComponentEditorForSelection: TBaseComponentEditor;
|
||||||
|
begin
|
||||||
|
Result:=nil;
|
||||||
|
if ControlSelection.Count<>1 then exit;
|
||||||
|
Result:=FormEditor1.GetComponentEditor(ControlSelection[0].Component);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDesigner.AddComponentEditorMenuItems(
|
||||||
|
AComponentEditor: TBaseComponentEditor; AParentMenuItem: TMenuItem);
|
||||||
|
var
|
||||||
|
VerbCount, i: integer;
|
||||||
|
NewMenuItem: TMenuItem;
|
||||||
|
begin
|
||||||
|
if (AComponentEditor=nil) or (AParentMenuItem=nil) then exit;
|
||||||
|
VerbCount:=AComponentEditor.GetVerbCount;
|
||||||
|
for i:=0 to VerbCount-1 do begin
|
||||||
|
NewMenuItem:=TMenuItem.Create(AParentMenuItem);
|
||||||
|
NewMenuItem.Name:='ComponentEditorVerMenuItem'+IntToStr(i);
|
||||||
|
NewMenuItem.Caption:=AComponentEditor.GetVerb(i);
|
||||||
|
NewMenuItem.OnClick:=@OnComponentEditorVerbMenuItemClick;
|
||||||
|
AParentMenuItem.Add(NewMenuItem);
|
||||||
|
AComponentEditor.PrepareItem(i,NewMenuItem);
|
||||||
|
end;
|
||||||
|
if VerbCount>0 then begin
|
||||||
|
// Add seperator
|
||||||
|
NewMenuItem:=TMenuItem.Create(AParentMenuItem);
|
||||||
|
NewMenuItem.Caption:='-';
|
||||||
|
AParentMenuItem.Add(NewMenuItem);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TDesigner.NonVisualComponentAtPos(x,y: integer): TComponent;
|
function TDesigner.NonVisualComponentAtPos(x,y: integer): TComponent;
|
||||||
var i: integer;
|
var i: integer;
|
||||||
LeftTop: TPoint;
|
LeftTop: TPoint;
|
||||||
@ -1217,6 +1279,8 @@ begin
|
|||||||
|
|
||||||
FPopupMenu:=TPopupMenu.Create(nil);
|
FPopupMenu:=TPopupMenu.Create(nil);
|
||||||
|
|
||||||
|
AddComponentEditorMenuItems(PopupMenuComponentEditor,FPopupMenu.Items);
|
||||||
|
|
||||||
FAlignMenuItem := TMenuItem.Create(FPopupMenu);
|
FAlignMenuItem := TMenuItem.Create(FPopupMenu);
|
||||||
with FAlignMenuItem do begin
|
with FAlignMenuItem do begin
|
||||||
Caption := 'Align';
|
Caption := 'Align';
|
||||||
|
Loading…
Reference in New Issue
Block a user