Designer: Remove direct OI dependency of "Change Parent" feature, use events.

git-svn-id: trunk@52194 -
This commit is contained in:
juha 2016-04-14 10:02:16 +00:00
parent 47e2727bb5
commit 58317e2f8a
3 changed files with 26 additions and 16 deletions

View File

@ -777,7 +777,7 @@ type
function GetActivePropertyGrid: TOICustomPropertyGrid;
function GetActivePropertyRow: TOIPropertyGridRow;
function GetCurRowDefaultValue(var DefaultStr: string): Boolean;
function GetHasParentCandidates: Boolean;
function HasParentCandidates: Boolean;
procedure ChangeParent;
procedure HookRefreshPropertyValues;
procedure ActivateGrid(Grid: TOICustomPropertyGrid);
@ -4550,7 +4550,7 @@ begin
Result.Add(FPropertyEditorHook.LookupRoot);
end;
function TObjectInspectorDlg.GetHasParentCandidates: Boolean;
function TObjectInspectorDlg.HasParentCandidates: Boolean;
var
Candidates: TFPList=nil;
begin
@ -5565,7 +5565,7 @@ var
end;
var
b, AtLeastOneComp, CanChangeClass, HasParentCandidates: Boolean;
b, AtLeastOneComp, CanChangeClass, HasParentCand: Boolean;
CurRow: TOIPropertyGridRow;
Persistent: TPersistent;
Page: TObjectInspectorPage;
@ -5580,7 +5580,7 @@ begin
Persistent := GetSelectedPersistent;
AtLeastOneComp := False;
CanChangeClass := False;
HasParentCandidates := False;
HasParentCand := False;
// show component editors only for component treeview
if MainPopupMenu.PopupComponent = ComponentTree then
begin
@ -5603,7 +5603,7 @@ begin
AddZOrderMenuItems;
// check existing of Change Parent candidates
if AtLeastOneComp then
HasParentCandidates := GetHasParentCandidates;
HasParentCand := HasParentCandidates;
end;
CutPopupMenuItem.Visible := AtLeastOneComp;
CopyPopupMenuItem.Visible := AtLeastOneComp;
@ -5611,8 +5611,8 @@ begin
DeletePopupMenuItem.Visible := AtLeastOneComp;
OptionsSeparatorMenuItem2.Visible := AtLeastOneComp;
ChangeClassPopupmenuItem.Visible := CanChangeClass;
ChangeParentPopupmenuItem.Visible := HasParentCandidates;
OptionsSeparatorMenuItem3.Visible := CanChangeClass or HasParentCandidates;
ChangeParentPopupmenuItem.Visible := HasParentCand;
OptionsSeparatorMenuItem3.Visible := CanChangeClass or HasParentCand;
// The editors can do menu actions, for example set defaults and constraints
CurRow := GetActivePropertyRow;

View File

@ -45,11 +45,11 @@ uses
LazFileUtils, LazFileCache,
// IDEIntf
IDEDialogs, PropEdits, PropEditUtils, ComponentEditors, MenuIntf, IDEImagesIntf,
FormEditingIntf, ComponentReg, IDECommands, LazIDEIntf, ProjectIntf, MainIntf,
FormEditingIntf, ComponentReg, IDECommands, LazIDEIntf, ProjectIntf,
// IDE
LazarusIDEStrConsts, EnvironmentOpts, EditorOptions, SourceEditor,
// Designer
AlignCompsDlg, SizeCompsDlg, ScaleCompsDlg, TabOrderDlg, AnchorEditor, DesignerProcs,
AlignCompsDlg, SizeCompsDlg, ScaleCompsDlg, DesignerProcs,
CustomFormEditor, AskCompNameDlg, ControlSelection, ChangeClassDialog;
type
@ -74,6 +74,7 @@ type
TOnComponentAdded = procedure(Sender: TObject; AComponent: TComponent;
ARegisteredComponent: TRegisteredComponent) of object;
TOnForwardKeyToObjectInspector = procedure(Sender: TObject; Key: TUTF8Char) of object;
TOnHasParentCandidates = function: Boolean of object;
TDesignerFlag = (
dfHasSized,
@ -106,6 +107,8 @@ type
FFlags: TDesignerFlags;
FGridColor: TColor;
FMediator: TDesignerMediator;
FOnChangeParent: TProcedureOfObject;
FOnHasParentCandidates: TOnHasParentCandidates;
FOnPastedComponents: TOnPastedComponents;
FProcessingDesignerEvent: Integer;
FOnActivated: TNotifyEvent;
@ -376,6 +379,10 @@ type
property OnShowTabOrderEditor: TNotifyEvent read FOnShowTabOrderEditor write FOnShowTabOrderEditor;
property OnForwardKeyToObjectInspector: TOnForwardKeyToObjectInspector read FOnForwardKeyToObjectInspector
write FOnForwardKeyToObjectInspector;
property OnHasParentCandidates: TOnHasParentCandidates read FOnHasParentCandidates
write FOnHasParentCandidates;
property OnChangeParent: TProcedureOfObject read FOnChangeParent write FOnChangeParent;
property ShowGrid: boolean read GetShowGrid write SetShowGrid;
property ShowBorderSpacing: boolean read GetShowBorderSpacing write SetShowBorderSpacing;
property ShowEditorHints: boolean read GetShowEditorHints write SetShowEditorHints;
@ -3263,10 +3270,8 @@ end;
procedure TDesigner.OnChangeParentMenuClick(Sender: TObject);
begin
Assert(ObjectInspector1.PropertyEditorHook.LookupRoot = LookupRoot,
'TDesigner.OnChangeParentMenuClick: LookupRoot mismatch.');
if Assigned(ObjectInspector1) then
ObjectInspector1.ChangeParent;
if Assigned(OnChangeParent) then
OnChangeParent();
end;
procedure TDesigner.OnSnapToGridOptionMenuClick(Sender: TObject);
@ -3914,8 +3919,8 @@ begin
DesignerMenuChangeClass.Enabled := CompsAreSelected and (ControlSelection.Count = 1);
// Disable ViewLFM menu item for virtual units. There is no form file yet.
DesignerMenuViewLFM.Enabled := not UnitIsVirtual;
DesignerMenuChangeParent.Enabled := Assigned(ObjectInspector1)
and ObjectInspector1.GetHasParentCandidates;
DesignerMenuChangeParent.Enabled := Assigned(OnHasParentCandidates)
and OnHasParentCandidates();
DesignerMenuSnapToGridOption.Checked := EnvironmentOptions.SnapToGrid;
DesignerMenuSnapToGuideLinesOption.Checked := EnvironmentOptions.SnapToGuideLines;
end;

View File

@ -3478,8 +3478,13 @@ begin
OnForwardKeyToObjectInspector:=@ForwardKeyToObjectInspector;
OnShowAnchorEditor:=@OnDesignerShowAnchorEditor;
OnShowTabOrderEditor:=@OnDesignerShowTabOrderEditor;
if Assigned(ObjectInspector1) then
begin
OnHasParentCandidates:=@ObjectInspector1.HasParentCandidates;
OnChangeParent:=@ObjectInspector1.ChangeParent;
end;
ShowEditorHints:=EnvironmentOptions.ShowEditorHints;
ShowComponentCaptions := EnvironmentOptions.ShowComponentCaptions;
ShowComponentCaptions:=EnvironmentOptions.ShowComponentCaptions;
end;
if AnUnitInfo<>nil then
AnUnitInfo.LoadedDesigner:=true;