From fb9c855546d74cb3e25d65ad778b98b1eb8ef963 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 29 May 2012 09:42:07 +0000 Subject: [PATCH] IDEIntf: added TObjectInspectorDlg.EnableHookGetSelection, IDE: designer selection is now stored in TheControlSelection, as OI does not always exist git-svn-id: trunk@37450 - --- designer/controlselection.pp | 58 ++++++++-------- ide/main.pp | 36 ++++++---- ideintf/objectinspector.pp | 125 +++++++++++++++++++++-------------- 3 files changed, 131 insertions(+), 88 deletions(-) diff --git a/designer/controlselection.pp b/designer/controlselection.pp index 8166056f97..317a8ec312 100644 --- a/designer/controlselection.pp +++ b/designer/controlselection.pp @@ -240,7 +240,7 @@ type cssBoundsNeedsUpdate, cssBoundsNeedsSaving, cssParentLevelNeedsUpdate, - cssNotSavingBounds, + cssDoNotSaveBounds, cssSnapping, cssChangedDuringLock, cssRubberbandActive, @@ -377,26 +377,26 @@ type destructor Destroy; override; procedure OnIdle(Sender: TObject; var Done: Boolean); - // items - property Items[Index:integer]:TSelectedControl - read GetItems write SetItems; default; - function Count:integer; - procedure Sort(SortProc: TSelectionSortCompare); - procedure BeginUpdate; procedure EndUpdate; procedure DoChange(ForceUpdate: Boolean = False); property UpdateLock: integer read FUpdateLock; - function IndexOf(APersistent: TPersistent):integer; - function Add(APersistent: TPersistent):integer; + // items + property Items[Index:integer]: TSelectedControl + read GetItems write SetItems; default; + function Count: integer; + procedure Sort(SortProc: TSelectionSortCompare); + function IndexOf(APersistent: TPersistent): integer; + function Add(APersistent: TPersistent): integer; procedure Remove(APersistent: TPersistent); - procedure Delete(Index:integer); + procedure Delete(Index: integer); procedure Clear; function Equals(const ASelection: TPersistentSelectionList): boolean; reintroduce; function AssignPersistent(APersistent: TPersistent): boolean; procedure Assign(AControlSelection: TControlSelection); reintroduce; - procedure AssignSelection(const ASelection: TPersistentSelectionList); + procedure AssignSelection(const ASelection: TPersistentSelectionList); // set selection + procedure GetSelection(const ASelection: TPersistentSelectionList); function IsSelected(APersistent: TPersistent): Boolean; function IsOnlySelected(APersistent: TPersistent): Boolean; function ParentLevel: integer; @@ -1972,7 +1972,7 @@ var i: integer; g: TGrabIndex; begin - if cssNotSavingBounds in FStates then exit; + if cssDoNotSaveBounds in FStates then exit; //debugln('TControlSelection.SaveBounds'); if FUpdateLock > 0 then begin @@ -2092,7 +2092,6 @@ function TControlSelection.Equals(const ASelection: TPersistentSelectionList ): boolean; var i: Integer; - Index: Integer; Instance: TPersistent; begin if (ASelection=nil) then begin @@ -2102,25 +2101,18 @@ begin Result:=Count=ASelection.Count; if not Result then exit; - Index:=0; for i:=0 to ASelection.Count-1 do begin Instance := ASelection[i]; - if Instance is TPersistent then begin - if Items[Index].Persistent<>Instance then begin - Result:=false; - exit; - end; - inc(Index); - end; + if Items[i].Persistent<>Instance then exit(false); end; end; procedure TControlSelection.Assign(AControlSelection: TControlSelection); var i:integer; begin - if (AControlSelection=Self) or (cssNotSavingBounds in FStates) then exit; - Include(FStates,cssNotSavingBounds); + if (AControlSelection=Self) or (cssDoNotSaveBounds in FStates) then exit; + Include(FStates,cssDoNotSaveBounds); BeginUpdate; Clear; FControls.Capacity:=AControlSelection.Count; @@ -2128,7 +2120,7 @@ begin Add(AControlSelection[i].Persistent); SetCustomForm; UpdateBounds; - Exclude(FStates,cssNotSavingBounds); + Exclude(FStates,cssDoNotSaveBounds); SaveBounds; EndUpdate; DoChange; @@ -2141,8 +2133,8 @@ var instance: TPersistent; begin if Equals(ASelection) then exit; - if (cssNotSavingBounds in FStates) then exit; - Include(FStates,cssNotSavingBounds); + if (cssDoNotSaveBounds in FStates) then exit; + Include(FStates,cssDoNotSaveBounds); BeginUpdate; Clear; FControls.Capacity:=ASelection.Count; @@ -2153,12 +2145,24 @@ begin end; SetCustomForm; UpdateBounds; - Exclude(FStates,cssNotSavingBounds); + Exclude(FStates,cssDoNotSaveBounds); SaveBounds; EndUpdate; DoChange; end; +procedure TControlSelection.GetSelection( + const ASelection: TPersistentSelectionList); +var + i: Integer; +begin + if ASelection=nil then exit; + if Equals(ASelection) then exit; + ASelection.Clear; + for i:=0 to Count-1 do + ASelection.Add(Items[i].Persistent); +end; + function TControlSelection.IsSelected(APersistent: TPersistent): Boolean; begin Result:=(IndexOf(APersistent)>=0); diff --git a/ide/main.pp b/ide/main.pp index 0846b6e397..b0aaf8f4a8 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -551,6 +551,7 @@ type procedure OnControlSelectionPropsChanged(Sender: TObject); procedure OnControlSelectionFormChanged(Sender: TObject; OldForm, NewForm: TCustomForm); + procedure OnGetDesignerSelection(const ASelection: TPersistentSelectionList); // project inspector procedure ProjInspectorOpen(Sender: TObject); @@ -1682,16 +1683,16 @@ begin (ObjectInspector1.Selection.Count > 0) then begin C := ObjectInspector1.Selection[0].ClassType; - if C.InheritsFrom(TForm) then C := TForm - else - if C.InheritsFrom(TCustomForm) then C := TCustomForm - else - if C.InheritsFrom(TDataModule) then C := TDataModule - else - if C.InheritsFrom(TFrame) then C := TFrame; + if C.InheritsFrom(TForm) then + C := TForm + else if C.InheritsFrom(TCustomForm) then + C := TCustomForm + else if C.InheritsFrom(TDataModule) then + C := TDataModule + else if C.InheritsFrom(TFrame) then + C := TFrame; end; - if ObjectInspector1.GetActivePropertyRow = nil then begin if C <> nil then @@ -2186,6 +2187,7 @@ begin TheControlSelection.OnChange:=@OnControlSelectionChanged; TheControlSelection.OnPropertiesChanged:=@OnControlSelectionPropsChanged; TheControlSelection.OnSelectionFormChanged:=@OnControlSelectionFormChanged; + GlobalDesignHook.AddHandlerGetSelection(@OnGetDesignerSelection); end; procedure TMainIDE.SetupIDECommands; @@ -14879,6 +14881,13 @@ begin UpdateIDEComponentPalette; end; +procedure TMainIDE.OnGetDesignerSelection( + const ASelection: TPersistentSelectionList); +begin + if TheControlSelection=nil then exit; + TheControlSelection.GetSelection(ASelection); +end; + // ----------------------------------------------------------------------------- @@ -17570,11 +17579,9 @@ begin ObjectInspector1.OnPropertyHint:=@OIOnPropertyHint; ObjectInspector1.OnDestroy:=@OIOnDestroy; ObjectInspector1.OnAutoShow:=@OIOnAutoShow; - ObjectInspector1.PropertyEditorHook:=GlobalDesignHook; - if FormEditor1<>nil then - FormEditor1.Obj_Inspector := ObjectInspector1; + ObjectInspector1.EnableHookGetSelection:=false; // the selection is stored in TheControlSelection - // after OI changes the hints needs to be updated + // after OI changes the hints need to be updated // do that after some idle time OIChangedTimer:=TIdleTimer.Create(OwningComponent); with OIChangedTimer do begin @@ -17583,6 +17590,11 @@ begin OnTimer:=@OIChangedTimerTimer; end; EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1); + + // connect to designers + ObjectInspector1.PropertyEditorHook:=GlobalDesignHook; + if FormEditor1<>nil then + FormEditor1.Obj_Inspector := ObjectInspector1; end; procedure TMainIDE.OnApplicationUserInput(Sender: TObject; Msg: Cardinal); diff --git a/ideintf/objectinspector.pp b/ideintf/objectinspector.pp index eb68e6cde1..d65bd52b49 100644 --- a/ideintf/objectinspector.pp +++ b/ideintf/objectinspector.pp @@ -39,12 +39,12 @@ uses // FCL SysUtils, Types, Classes, TypInfo, // LCL - InterfaceBase, Forms, Buttons, Graphics, GraphType, LCLProc, - StdCtrls, LCLType, LCLIntf, Controls, ComCtrls, ExtCtrls, - LMessages, LResources, LazConfigStorage, Menus, Dialogs, Themes, - TreeFilterEdit, ObjInspStrConsts, + InterfaceBase, Forms, Buttons, Graphics, GraphType, LCLProc, StdCtrls, + LCLType, LCLIntf, Controls, ComCtrls, ExtCtrls, LMessages, LResources, + LazConfigStorage, Menus, Dialogs, Themes, TreeFilterEdit, ObjInspStrConsts, PropEdits, GraphPropEdits, ListViewPropEdit, ImageListEditor, - ComponentTreeView, ComponentEditors, IDEImagesIntf, OIFavouriteProperties; + ComponentTreeView, ComponentEditors, IDEImagesIntf, OIFavouriteProperties, + PropEditUtils; const OIOptionsFileVersion = 3; @@ -693,10 +693,12 @@ type procedure DoCollectionAddItem(Sender: TObject); procedure DoZOrderItemClick(Sender: TObject); private + FEnableHookGetSelection: boolean; FInSelection: Boolean; FOnAutoShow: TNotifyEvent; function GetComponentTreeHeight: integer; function GetInfoBoxHeight: integer; + procedure SetEnableHookGetSelection(AValue: boolean); protected function PersistentToString(APersistent: TPersistent): string; procedure AddPersistentToList(APersistent: TPersistent; List: TStrings); @@ -737,49 +739,51 @@ type procedure FocusGrid(Grid: TOICustomPropertyGrid = nil); property AutoShow: Boolean read FAutoShow write FAutoShow; + property ComponentTreeHeight: integer read GetComponentTreeHeight + write SetComponentTreeHeight; property DefaultItemHeight: integer read FDefaultItemHeight write SetDefaultItemHeight; - property Selection: TPersistentSelectionList - read FSelection write SetSelection; + property EnableHookGetSelection: boolean read FEnableHookGetSelection + write SetEnableHookGetSelection; + property Favourites: TOIFavouriteProperties read FFavourites write SetFavourites; + property GridControl[Page: TObjectInspectorPage]: TOICustomPropertyGrid + read GetGridControl; + property InfoBoxHeight: integer read GetInfoBoxHeight write SetInfoBoxHeight; property OnAddAvailPersistent: TOnAddAvailablePersistent read FOnAddAvailablePersistent write FOnAddAvailablePersistent; - property OnSelectPersistentsInOI: TNotifyEvent - read FOnSelectPersistentsInOI write FOnSelectPersistentsInOI; - property PropertyEditorHook: TPropertyEditorHook - read FPropertyEditorHook write SetPropertyEditorHook; + property OnAddToFavourites: TNotifyEvent read FOnAddToFavourites + write FOnAddToFavourites; + property OnAutoShow: TNotifyEvent read FOnAutoShow write FOnAutoShow; + property OnFindDeclarationOfProperty: TNotifyEvent + read FOnFindDeclarationOfProperty write FOnFindDeclarationOfProperty; property OnModified: TNotifyEvent read FOnModified write FOnModified; - property OnSelectionChange: TNotifyEvent read FOnSelectionChange write FOnSelectionChange; + property OnOIKeyDown: TKeyEvent read FOnOIKeyDown write FOnOIKeyDown; property OnPropertyHint: TOIPropertyHint read FOnPropertyHint write FOnPropertyHint; - property OnShowOptions: TNotifyEvent read FOnShowOptions - write SetOnShowOptions; - property OnRemainingKeyUp: TKeyEvent read FOnRemainingKeyUp - write FOnRemainingKeyUp; property OnRemainingKeyDown: TKeyEvent read FOnRemainingKeyDown write FOnRemainingKeyDown; + property OnRemainingKeyUp: TKeyEvent read FOnRemainingKeyUp + write FOnRemainingKeyUp; + property OnRemoveFromFavourites: TNotifyEvent read FOnRemoveFromFavourites + write FOnRemoveFromFavourites; + property OnSelectionChange: TNotifyEvent read FOnSelectionChange write FOnSelectionChange; + property OnSelectPersistentsInOI: TNotifyEvent + read FOnSelectPersistentsInOI write FOnSelectPersistentsInOI; + property OnShowOptions: TNotifyEvent read FOnShowOptions + write SetOnShowOptions; property OnUpdateRestricted: TNotifyEvent read FOnUpdateRestricted write FOnUpdateRestricted; + property OnViewRestricted: TNotifyEvent read FOnViewRestricted write FOnViewRestricted; + property PropertyEditorHook: TPropertyEditorHook + read FPropertyEditorHook write SetPropertyEditorHook; + property RestrictedProps: TOIRestrictedProperties read FRestricted write SetRestricted; + property Selection: TPersistentSelectionList + read FSelection write SetSelection; property ShowComponentTree: boolean read FShowComponentTree write SetShowComponentTree; property ShowFavorites: Boolean read FShowFavorites write SetShowFavorites; - property ShowRestricted: Boolean read FShowRestricted write SetShowRestricted; - property ComponentTreeHeight: integer read GetComponentTreeHeight - write SetComponentTreeHeight; - property InfoBoxHeight: integer read GetInfoBoxHeight write SetInfoBoxHeight; - property ShowStatusBar: Boolean read FShowStatusBar write SetShowStatusBar; property ShowInfoBox: Boolean read FShowInfoBox write SetShowInfoBox; - property GridControl[Page: TObjectInspectorPage]: TOICustomPropertyGrid - read GetGridControl; - property Favourites: TOIFavouriteProperties read FFavourites write SetFavourites; - property RestrictedProps: TOIRestrictedProperties read FRestricted write SetRestricted; - property OnAddToFavourites: TNotifyEvent read FOnAddToFavourites - write FOnAddToFavourites; - property OnRemoveFromFavourites: TNotifyEvent read FOnRemoveFromFavourites - write FOnRemoveFromFavourites; - property OnViewRestricted: TNotifyEvent read FOnViewRestricted write FOnViewRestricted; - property OnOIKeyDown: TKeyEvent read FOnOIKeyDown write FOnOIKeyDown; - property OnFindDeclarationOfProperty: TNotifyEvent - read FOnFindDeclarationOfProperty write FOnFindDeclarationOfProperty; - property OnAutoShow: TNotifyEvent read FOnAutoShow write FOnAutoShow; + property ShowRestricted: Boolean read FShowRestricted write SetShowRestricted; + property ShowStatusBar: Boolean read FShowStatusBar write SetShowStatusBar; end; const @@ -3872,6 +3876,7 @@ constructor TObjectInspectorDlg.Create(AnOwner: TComponent); begin inherited Create(AnOwner); + FEnableHookGetSelection:= true; FPropertyEditorHook:=nil; FInSelection := False; FSelection:=TPersistentSelectionList.Create; @@ -4014,6 +4019,7 @@ end; procedure TObjectInspectorDlg.SetPropertyEditorHook(NewValue:TPropertyEditorHook); var Page: TObjectInspectorPage; + ASelection: TPersistentSelectionList; begin if FPropertyEditorHook=NewValue then exit; if FPropertyEditorHook<>nil then begin @@ -4024,13 +4030,23 @@ begin FPropertyEditorHook.AddHandlerChangeLookupRoot(@HookLookupRootChange); FPropertyEditorHook.AddHandlerRefreshPropertyValues( @HookRefreshPropertyValues); - FPropertyEditorHook.AddHandlerGetSelection(@HookGetSelection); FPropertyEditorHook.AddHandlerSetSelection(@HookSetSelection); - // select root component - FSelection.Clear; - if (FPropertyEditorHook<>nil) and (FPropertyEditorHook.LookupRoot<>nil) - and (FPropertyEditorHook.LookupRoot is TComponent) then - FSelection.Add(TComponent(FPropertyEditorHook.LookupRoot)); + if EnableHookGetSelection then begin + FPropertyEditorHook.AddHandlerGetSelection(@HookGetSelection); + // select root component + FSelection.Clear; + if (FPropertyEditorHook<>nil) and (FPropertyEditorHook.LookupRoot<>nil) + and (FPropertyEditorHook.LookupRoot is TComponent) then + FSelection.Add(TComponent(FPropertyEditorHook.LookupRoot)); + end else begin + ASelection:=TPersistentSelectionList.Create; + try + FPropertyEditorHook.GetSelection(ASelection); + Selection := ASelection; + finally + ASelection.Free; + end; + end; FillPersistentComboBox; for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do if GridControl[Page]<>nil then @@ -4235,10 +4251,14 @@ procedure TObjectInspectorDlg.SetSelection(const ASelection: TPersistentSelectio begin if (not Assigned(ASelection)) then exit; - if FInSelection and FSelection.IsEqual(ASelection) then - exit; // prevent endless loops - if (not ASelection.ForceUpdate) and FSelection.IsEqual(ASelection) then - exit; // nothing changed + if FSelection.IsEqual(ASelection) then + begin + if FInSelection then + exit; // prevent endless loops + if (not ASelection.ForceUpdate) then + exit; // nothing changed + ASelection.ForceUpdate:=false; + end; FInSelection := True; try // ToDo: Clear filter only if a selected node is hidden (Visible=False) @@ -5253,11 +5273,18 @@ end; function TObjectInspectorDlg.GetInfoBoxHeight: integer; begin - if Assigned(InfoPanel) then - Result := InfoPanel.Height - else // Will never happen, remove later. JuMa - raise Exception.Create('InfoPanel=nil in TObjectInspectorDlg.GetInfoBoxHeight'); - //Result := FInfoBoxHeight; + Result := InfoPanel.Height; +end; + +procedure TObjectInspectorDlg.SetEnableHookGetSelection(AValue: boolean); +begin + if FEnableHookGetSelection=AValue then Exit; + FEnableHookGetSelection:=AValue; + if PropertyEditorHook<>nil then + if EnableHookGetSelection then + FPropertyEditorHook.AddHandlerGetSelection(@HookGetSelection) + else + FPropertyEditorHook.RemoveHandlerGetSelection(@HookGetSelection) end; procedure TObjectInspectorDlg.HookRefreshPropertyValues;