mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-15 14:50:37 +01:00
IDE: fixed TCustomFormEditor.GetAncestorLookupRoot to return the next ancestor root, instead of the deepest
git-svn-id: trunk@48681 -
This commit is contained in:
parent
75eb7cb004
commit
d505fceb00
@ -40,16 +40,17 @@ uses
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// LCL+FCL
|
// LCL+FCL
|
||||||
Classes, SysUtils, TypInfo, Math, LCLIntf, LCLType, LResources,
|
Classes, SysUtils, TypInfo, Math, LCLIntf, LCLType, LResources,
|
||||||
AVL_Tree, LCLMemManager, FileUtil, LazFileCache,
|
LCLMemManager, FileUtil, LazFileCache, AvgLvlTree,
|
||||||
LCLProc, Graphics, Controls, Forms, Menus, Dialogs,
|
LCLProc, Graphics, Controls, Forms, Menus, Dialogs,
|
||||||
|
CodeCache, CodeTree, CodeToolManager, FindDeclarationTool,
|
||||||
// IDEIntf
|
// IDEIntf
|
||||||
PropEdits, PropEditUtils, ObjectInspector, IDECommands, FormEditingIntf,
|
PropEdits, PropEditUtils, ObjectInspector, IDECommands, FormEditingIntf,
|
||||||
UnitResources, IDEOptionsIntf,
|
UnitResources, IDEOptionsIntf, IDEDialogs, ComponentEditors,
|
||||||
// IDE
|
// IDE
|
||||||
LazarusIDEStrConsts, ControlSelection, Project, JITForms, MainIntf,
|
LazarusIDEStrConsts, KeyMapping, EditorOptions, EnvironmentOpts,
|
||||||
|
ControlSelection, Project, JITForms, MainIntf,
|
||||||
CustomNonFormDesigner, NonControlDesigner, FrameDesigner, ComponentReg,
|
CustomNonFormDesigner, NonControlDesigner, FrameDesigner, ComponentReg,
|
||||||
IDEProcs, ComponentEditors, IDEDialogs, CodeCache, CodeToolManager, CodeTree,
|
IDEProcs,
|
||||||
FindDeclarationTool, KeyMapping, EditorOptions, EnvironmentOpts,
|
|
||||||
DesignerProcs, PackageDefs;
|
DesignerProcs, PackageDefs;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -68,18 +69,20 @@ type
|
|||||||
FOnSelectFrame: TSelectFrameEvent;
|
FOnSelectFrame: TSelectFrameEvent;
|
||||||
FSelection: TPersistentSelectionList;
|
FSelection: TPersistentSelectionList;
|
||||||
FObj_Inspector: TObjectInspectorDlg;
|
FObj_Inspector: TObjectInspectorDlg;
|
||||||
FDefineProperties: TAVLTree;// tree of TDefinePropertiesCacheItem
|
FDefineProperties: TAvgLvlTree;// tree of TDefinePropertiesCacheItem
|
||||||
FStandardDefinePropertiesRegistered: Boolean;
|
FStandardDefinePropertiesRegistered: Boolean;
|
||||||
FDesignerBaseClasses: TFPList; // list of TComponentClass
|
FDesignerBaseClasses: TFPList; // list of TComponentClass
|
||||||
FDesignerMediatorClasses: TFPList;// list of TDesignerMediatorClass
|
FDesignerMediatorClasses: TFPList;// list of TDesignerMediatorClass
|
||||||
FOnNodeGetImageIndex: TOnOINodeGetImageEvent;
|
FOnNodeGetImageIndex: TOnOINodeGetImageEvent;
|
||||||
function GetPropertyEditorHook: TPropertyEditorHook;
|
function GetPropertyEditorHook: TPropertyEditorHook;
|
||||||
function FindDefinePropertyNode(const APersistentClassName: string
|
function FindDefinePropertyNode(const APersistentClassName: string
|
||||||
): TAVLTreeNode;
|
): TAvgLvlTreeNode;
|
||||||
procedure FrameCompGetCreationClass(Sender: TObject;
|
procedure FrameCompGetCreationClass(Sender: TObject;
|
||||||
var NewComponentClass: TComponentClass);
|
var NewComponentClass: TComponentClass);
|
||||||
protected
|
protected
|
||||||
FNonFormForms: TAVLTree; // tree of TNonControlDesignerForm sorted for LookupRoot
|
FComponentToAncestorInstanceTree: TAvgLvlTree; // tree of TComponent to TComponent
|
||||||
|
FComponentToInheritedInstancesListTree: TAvgLvlTree; // tree of TComponent to TFPList (of TComponent)
|
||||||
|
FNonFormForms: TAvgLvlTree; // tree of TNonControlDesignerForm sorted for LookupRoot
|
||||||
procedure SetSelection(const ASelection: TPersistentSelectionList);
|
procedure SetSelection(const ASelection: TPersistentSelectionList);
|
||||||
procedure OnObjectInspectorModified(Sender: TObject);
|
procedure OnObjectInspectorModified(Sender: TObject);
|
||||||
procedure SetObj_Inspector(AnObjectInspector: TObjectInspectorDlg); virtual;
|
procedure SetObj_Inspector(AnObjectInspector: TObjectInspectorDlg); virtual;
|
||||||
@ -101,7 +104,7 @@ type
|
|||||||
|
|
||||||
function GetDesignerBaseClasses(Index: integer): TComponentClass; override;
|
function GetDesignerBaseClasses(Index: integer): TComponentClass; override;
|
||||||
procedure OnDesignerMenuItemClick(Sender: TObject); virtual;
|
procedure OnDesignerMenuItemClick(Sender: TObject); virtual;
|
||||||
function FindNonFormFormNode(LookupRoot: TComponent): TAVLTreeNode;
|
function FindNonFormFormNode(LookupRoot: TComponent): TAvgLvlTreeNode;
|
||||||
|
|
||||||
//because we only meet ObjInspectore here, not in abstract ancestor
|
//because we only meet ObjInspectore here, not in abstract ancestor
|
||||||
procedure DoOnNodeGetImageIndex(APersistent: TPersistent; var AImageIndex: integer); virtual;
|
procedure DoOnNodeGetImageIndex(APersistent: TPersistent; var AImageIndex: integer); virtual;
|
||||||
@ -455,12 +458,14 @@ var
|
|||||||
l: Integer;
|
l: Integer;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FNonFormForms := TAVLTree.Create(@CompareNonFormDesignerForms);
|
FNonFormForms := TAvgLvlTree.Create(@CompareNonFormDesignerForms);
|
||||||
FSelection := TPersistentSelectionList.Create;
|
FSelection := TPersistentSelectionList.Create;
|
||||||
FDesignerBaseClasses:=TFPList.Create;
|
FDesignerBaseClasses:=TFPList.Create;
|
||||||
FDesignerMediatorClasses:=TFPList.Create;
|
FDesignerMediatorClasses:=TFPList.Create;
|
||||||
for l:=Low(StandardDesignerBaseClasses) to High(StandardDesignerBaseClasses) do
|
for l:=Low(StandardDesignerBaseClasses) to High(StandardDesignerBaseClasses) do
|
||||||
FDesignerBaseClasses.Add(StandardDesignerBaseClasses[l]);
|
FDesignerBaseClasses.Add(StandardDesignerBaseClasses[l]);
|
||||||
|
FComponentToAncestorInstanceTree:=TAvgLvlTree.Create;
|
||||||
|
FComponentToInheritedInstancesListTree:=TAvgLvlTree.Create;
|
||||||
|
|
||||||
JITFormList := TJITForms.Create(nil);
|
JITFormList := TJITForms.Create(nil);
|
||||||
InitJITList(JITFormList);
|
InitJITList(JITFormList);
|
||||||
@ -485,6 +490,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
FreeAndNil(JITFormList);
|
FreeAndNil(JITFormList);
|
||||||
FreeAndNil(JITNonFormList);
|
FreeAndNil(JITNonFormList);
|
||||||
|
FreeAndNil(FComponentToAncestorInstanceTree);
|
||||||
|
FComponentToInheritedInstancesListTree.FreeAndClear;
|
||||||
|
FreeAndNil(FComponentToInheritedInstancesListTree);
|
||||||
FreeAndNil(FDesignerMediatorClasses);
|
FreeAndNil(FDesignerMediatorClasses);
|
||||||
FreeAndNil(FDesignerBaseClasses);
|
FreeAndNil(FDesignerBaseClasses);
|
||||||
FreeAndNil(FSelection);
|
FreeAndNil(FSelection);
|
||||||
@ -810,7 +818,7 @@ end;
|
|||||||
|
|
||||||
function TCustomFormEditor.FindNonFormForm(LookupRoot: TComponent): TCustomNonFormDesignerForm;
|
function TCustomFormEditor.FindNonFormForm(LookupRoot: TComponent): TCustomNonFormDesignerForm;
|
||||||
var
|
var
|
||||||
AVLNode: TAVLTreeNode;
|
AVLNode: TAvgLvlTreeNode;
|
||||||
begin
|
begin
|
||||||
AVLNode := FindNonFormFormNode(LookupRoot);
|
AVLNode := FindNonFormFormNode(LookupRoot);
|
||||||
if AVLNode <> nil then
|
if AVLNode <> nil then
|
||||||
@ -1593,6 +1601,8 @@ end;
|
|||||||
|
|
||||||
function TCustomFormEditor.GetAncestorLookupRoot(AComponent: TComponent
|
function TCustomFormEditor.GetAncestorLookupRoot(AComponent: TComponent
|
||||||
): TComponent;
|
): TComponent;
|
||||||
|
{ returns the ancestor of the Owner, if it owns a component with same name.
|
||||||
|
}
|
||||||
var
|
var
|
||||||
CurRoot: TComponent;
|
CurRoot: TComponent;
|
||||||
AncestorRoot: TComponent;
|
AncestorRoot: TComponent;
|
||||||
@ -1601,25 +1611,10 @@ begin
|
|||||||
if AComponent=nil then exit;
|
if AComponent=nil then exit;
|
||||||
CurRoot:=AComponent.Owner;
|
CurRoot:=AComponent.Owner;
|
||||||
if CurRoot=nil then exit;
|
if CurRoot=nil then exit;
|
||||||
|
AncestorRoot:=GetAncestorInstance(CurRoot);
|
||||||
if csInline in CurRoot.ComponentState then begin
|
if AncestorRoot=nil then exit;
|
||||||
// inline/embedded components (e.g. nested frame)
|
if AncestorRoot.FindComponent(AComponent.Name)=nil then exit;
|
||||||
// find the non inlined instance (the IDE always creates one, it may be hidden)
|
Result:=AncestorRoot;
|
||||||
CurRoot:=FindJITComponentByClass(TComponentClass(CurRoot.ClassType));
|
|
||||||
if CurRoot=nil then exit;
|
|
||||||
if CurRoot.FindComponent(AComponent.Name)=nil then exit;
|
|
||||||
Result:=CurRoot;
|
|
||||||
end;
|
|
||||||
|
|
||||||
repeat
|
|
||||||
// search in next ancestor
|
|
||||||
AncestorRoot:=GetAncestorInstance(CurRoot);
|
|
||||||
if AncestorRoot=nil then break;
|
|
||||||
if AncestorRoot.FindComponent(AComponent.Name)=nil then break;
|
|
||||||
// a better ancestor was found
|
|
||||||
Result:=AncestorRoot;
|
|
||||||
CurRoot:=AncestorRoot;
|
|
||||||
until false;
|
|
||||||
{$IFDEF VerboseFormEditor}
|
{$IFDEF VerboseFormEditor}
|
||||||
DebugLn(['TCustomFormEditor.GetAncestorLookupRoot AComponent=',DbgSName(AComponent),' Result=',DbgSName(Result)]);
|
DebugLn(['TCustomFormEditor.GetAncestorLookupRoot AComponent=',DbgSName(AComponent),' Result=',DbgSName(Result)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -1627,6 +1622,16 @@ end;
|
|||||||
|
|
||||||
function TCustomFormEditor.GetAncestorInstance(AComponent: TComponent
|
function TCustomFormEditor.GetAncestorInstance(AComponent: TComponent
|
||||||
): TComponent;
|
): TComponent;
|
||||||
|
{ Returns the next ancestor instance.
|
||||||
|
For example:
|
||||||
|
TFrame3 = class(TFrame2), TFrame2 = class(TFrame1)
|
||||||
|
Frame1 is the ancestor instance of Frame2.
|
||||||
|
Frame2 is the ancestor instance of Frame3.
|
||||||
|
|
||||||
|
If TFrame1 introduced Button1 then
|
||||||
|
TFrame1.Button1 is the ancestor instance of TFrame2.Button1.
|
||||||
|
TFrame2.Button1 is the ancestor instance of TFrame3.Button1.
|
||||||
|
}
|
||||||
var
|
var
|
||||||
aRoot: TComponent;
|
aRoot: TComponent;
|
||||||
begin
|
begin
|
||||||
@ -1640,7 +1645,7 @@ begin
|
|||||||
Result:=FindJITComponentByClass(TComponentClass(AComponent.ClassType));
|
Result:=FindJITComponentByClass(TComponentClass(AComponent.ClassType));
|
||||||
end else begin
|
end else begin
|
||||||
// child component
|
// child component
|
||||||
aRoot:=GetAncestorLookupRoot(AComponent);
|
aRoot:=GetAncestorInstance(AComponent.Owner);
|
||||||
if aRoot=nil then exit;
|
if aRoot=nil then exit;
|
||||||
Result:=aRoot.FindComponent(AComponent.Name);
|
Result:=aRoot.FindComponent(AComponent.Name);
|
||||||
end;
|
end;
|
||||||
@ -1717,7 +1722,7 @@ var
|
|||||||
APersistent: TPersistent;
|
APersistent: TPersistent;
|
||||||
CacheItem: TDefinePropertiesCacheItem;
|
CacheItem: TDefinePropertiesCacheItem;
|
||||||
DefinePropertiesReader: TDefinePropertiesReader;
|
DefinePropertiesReader: TDefinePropertiesReader;
|
||||||
ANode: TAVLTreeNode;
|
ANode: TAvgLvlTreeNode;
|
||||||
OldClassName: String;
|
OldClassName: String;
|
||||||
DefinePropertiesPersistent: TDefinePropertiesPersistent;
|
DefinePropertiesPersistent: TDefinePropertiesPersistent;
|
||||||
|
|
||||||
@ -1875,7 +1880,7 @@ end;
|
|||||||
procedure TCustomFormEditor.RegisterDefineProperty(const APersistentClassName,
|
procedure TCustomFormEditor.RegisterDefineProperty(const APersistentClassName,
|
||||||
Identifier: string);
|
Identifier: string);
|
||||||
var
|
var
|
||||||
ANode: TAVLTreeNode;
|
ANode: TAvgLvlTreeNode;
|
||||||
CacheItem: TDefinePropertiesCacheItem;
|
CacheItem: TDefinePropertiesCacheItem;
|
||||||
begin
|
begin
|
||||||
//DebugLn('TCustomFormEditor.RegisterDefineProperty ',APersistentClassName,' ',Identifier);
|
//DebugLn('TCustomFormEditor.RegisterDefineProperty ',APersistentClassName,' ',Identifier);
|
||||||
@ -2058,7 +2063,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomFormEditor.FindNonFormFormNode(LookupRoot: TComponent): TAVLTreeNode;
|
function TCustomFormEditor.FindNonFormFormNode(LookupRoot: TComponent): TAvgLvlTreeNode;
|
||||||
begin
|
begin
|
||||||
Result := FNonFormForms.FindKey(Pointer(LookupRoot),
|
Result := FNonFormForms.FindKey(Pointer(LookupRoot),
|
||||||
@CompareLookupRootAndNonFormDesignerForm);
|
@CompareLookupRootAndNonFormDesignerForm);
|
||||||
@ -2196,11 +2201,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomFormEditor.FindDefinePropertyNode(
|
function TCustomFormEditor.FindDefinePropertyNode(
|
||||||
const APersistentClassName: string): TAVLTreeNode;
|
const APersistentClassName: string): TAvgLvlTreeNode;
|
||||||
begin
|
begin
|
||||||
if FDefineProperties=nil then
|
if FDefineProperties=nil then
|
||||||
FDefineProperties:=
|
FDefineProperties:=
|
||||||
TAVLTree.Create(TListSortCompare(@CompareDefPropCacheItems));
|
TAvgLvlTree.Create(TListSortCompare(@CompareDefPropCacheItems));
|
||||||
Result:=FDefineProperties.FindKey(PChar(APersistentClassName),
|
Result:=FDefineProperties.FindKey(PChar(APersistentClassName),
|
||||||
TListSortCompare(@ComparePersClassNameAndDefPropCacheItem));
|
TListSortCompare(@ComparePersClassNameAndDefPropCacheItem));
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user