From e4cdead4c8991b82f8185eb8db441bada226b11a Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 17 Dec 2009 14:05:01 +0000 Subject: [PATCH] ide, ideintf: component treeview improvements - add menu item to add collection items for TCollection and TCollectionItem - better find selected persistent - fix all calls of GetDesignerForm (no need to cast to TComponent) so if persistent changes then IDE also sets modified state git-svn-id: trunk@23163 - --- designer/controlselection.pp | 2 +- ide/customformeditor.pp | 6 +-- ideintf/componenttreeview.pas | 2 +- ideintf/objectinspector.pp | 80 ++++++++++++++++++++++++++++++----- ideintf/objinspstrconsts.pas | 2 + ideintf/propedits.pp | 18 ++++---- 6 files changed, 83 insertions(+), 27 deletions(-) diff --git a/designer/controlselection.pp b/designer/controlselection.pp index d3bb15f44b..ae1e780653 100644 --- a/designer/controlselection.pp +++ b/designer/controlselection.pp @@ -580,7 +580,7 @@ begin FIsNonVisualComponent:=FIsTComponent and (not FIsTControl); if (Owner.Mediator<>nil) and FIsTComponent then FIsNonVisualComponent:=Owner.Mediator.ComponentIsIcon(TComponent(FPersistent)); - FDesignerForm:=GetDesignerForm(TComponent(FPersistent)); + FDesignerForm:=GetDesignerForm(FPersistent); FIsVisible:=FIsTComponent and (not ComponentIsInvisible(TComponent(APersistent))); end; diff --git a/ide/customformeditor.pp b/ide/customformeditor.pp index 3ff253c475..048d4de151 100644 --- a/ide/customformeditor.pp +++ b/ide/customformeditor.pp @@ -2796,11 +2796,7 @@ begin or (FSelection.Count <= 0) then Exit; Instance := FSelection[0]; - if Instance is TComponent then - CustomForm:=GetDesignerForm(TComponent(Instance)) - else - CustomForm:=nil; - + CustomForm:=GetDesignerForm(Instance); if (CustomForm<>nil) and (CustomForm.Designer<>nil) then CustomForm.Designer.Modified; end; diff --git a/ideintf/componenttreeview.pas b/ideintf/componenttreeview.pas index 2abf7a2a97..271899187f 100644 --- a/ideintf/componenttreeview.pas +++ b/ideintf/componenttreeview.pas @@ -555,7 +555,7 @@ begin RootNode.ImageIndex := 0; RootNode.SelectedIndex := RootNode.ImageIndex; RootNode.MultiSelected := Selection.IndexOf(RootObject) >= 0; - + // create candidate nodes for every child Candidate := TComponentCandidate.Create; Candidate.APersistent := RootObject; diff --git a/ideintf/objectinspector.pp b/ideintf/objectinspector.pp index f4adde8aa1..750c3d1560 100644 --- a/ideintf/objectinspector.pp +++ b/ideintf/objectinspector.pp @@ -633,7 +633,6 @@ type procedure ComponentRestrictedPaint(Sender: TObject); procedure DoUpdateRestricted; procedure DoViewRestricted; - procedure DoComponentEditorVerbMenuItemClick(Sender: TObject); private FAutoShow: Boolean; FFavourites: TOIFavouriteProperties; @@ -684,6 +683,8 @@ type procedure ShowNextPage(Delta: integer); procedure RestrictedPaint( ABox: TPaintBox; const ARestrictions: TWidgetSetRestrictionsArray); + procedure DoComponentEditorVerbMenuItemClick(Sender: TObject); + procedure DoCollectionAddItem(Sender: TObject); protected function PersistentToString(APersistent: TPersistent): string; procedure AddPersistentToList(APersistent: TPersistent; List: TStrings); @@ -701,6 +702,8 @@ type procedure CreateNoteBook; procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure KeyUp(var Key: Word; Shift: TShiftState); override; + procedure DoModified; + function GetSelectedPersistent: TPersistent; function GetComponentEditorForSelection: TBaseComponentEditor; property ComponentEditor: TBaseComponentEditor read FComponentEditor write SetComponentEditor; public @@ -4125,8 +4128,7 @@ begin end; end; -procedure TObjectInspectorDlg.SetSelection( - const ASelection:TPersistentSelectionList); +procedure TObjectInspectorDlg.SetSelection(const ASelection: TPersistentSelectionList); begin if not ASelection.ForceUpdate and FSelection.IsEqual(ASelection) then Exit; @@ -4243,9 +4245,7 @@ var AComponent: TComponent absolute APersistent; ADesigner: TIDesigner; begin - if not Assigned(ComponentTree.Selected) then - Exit(nil); - APersistent := TPersistent(ComponentTree.Selected.Data); + APersistent := GetSelectedPersistent; if not (APersistent is TComponent) then Exit(nil); ADesigner := FindRootDesigner(AComponent); @@ -4471,7 +4471,7 @@ end; procedure TObjectInspectorDlg.OnGridModified(Sender: TObject); begin - if Assigned(FOnModified) then FOnModified(Self); + DoModified; end; procedure TObjectInspectorDlg.OnGridSelectionChange(Sender: TObject); @@ -4864,6 +4864,20 @@ begin OnRemainingKeyUp(Self,Key,Shift); end; +procedure TObjectInspectorDlg.DoModified; +begin + if Assigned(FOnModified) then + FOnModified(Self) +end; + +function TObjectInspectorDlg.GetSelectedPersistent: TPersistent; +begin + if ComponentTree.Selection.Count = 1 then + Result := ComponentTree.Selection[0] + else + Result := nil; +end; + procedure TObjectInspectorDlg.OnShowHintPopupMenuItemClick(Sender : TObject); var Page: TObjectInspectorPage; @@ -4900,8 +4914,6 @@ procedure TObjectInspectorDlg.OnMainPopupMenuPopup(Sender: TObject); I, VerbCount: Integer; Item: TMenuItem; begin - if (ComponentEditor = nil) then - Exit; VerbCount := ComponentEditor.GetVerbCount; for I := 0 to VerbCount - 1 do begin @@ -4919,14 +4931,38 @@ procedure TObjectInspectorDlg.OnMainPopupMenuPopup(Sender: TObject); end; end; + procedure AddCollectionEditorMenuItems(ACollection: TCollection); + var + Item: TMenuItem; + begin + Item := NewItem(oisAddCollectionItem, 0, False, True, + @DoCollectionAddItem, 0, 'ComponentEditorVerbMenuItem0'); + MainPopupMenu.Items.Insert(0, Item); + Item := NewLine; + Item.Name := 'ComponentEditorVerbMenuItem1'; + MainPopupMenu.Items.Insert(1, Item); + end; + var DefaultStr: String; CurGrid: TOICustomPropertyGrid; CurRow: TOIPropertyGridRow; + Persistent: TPersistent; begin - ComponentEditor := GetComponentEditorForSelection; RemoveComponentEditorMenuItems; - AddComponentEditorMenuItems; + ComponentEditor := GetComponentEditorForSelection; + if ComponentEditor <> nil then + AddComponentEditorMenuItems + else + begin + // check if it is a TCollection + Persistent := GetSelectedPersistent; + if Persistent is TCollection then + AddCollectionEditorMenuItems(TCollection(Persistent)) + else + if Persistent is TCollectionItem then + AddCollectionEditorMenuItems(TCollectionItem(Persistent).Collection); + end; SetDefaultPopupMenuItem.Enabled := GetCurRowDefaultValue(DefaultStr); if SetDefaultPopupMenuItem.Enabled then SetDefaultPopupMenuItem.Caption := Format(oisSetToDefault, [DefaultStr]) @@ -4990,6 +5026,28 @@ begin ComponentEditor.ExecuteVerb(Verb); end; +procedure TObjectInspectorDlg.DoCollectionAddItem(Sender: TObject); +var + Persistent: TPersistent; + Collection: TCollection absolute Persistent; +begin + Persistent := GetSelectedPersistent; + if Persistent = nil then + Exit; + if Persistent is TCollectionItem then + Persistent := TCollectionItem(Persistent).Collection; + if not (Persistent is TCollection) then + Exit; + Collection.Add; + DoModified; + Selection.ForceUpdate := True; + try + SetSelection(Selection); + finally + Selection.ForceUpdate := False; + end; +end; + procedure TObjectInspectorDlg.HookRefreshPropertyValues; begin RefreshPropertyValues; diff --git a/ideintf/objinspstrconsts.pas b/ideintf/objinspstrconsts.pas index bafb111a56..788883ebb3 100644 --- a/ideintf/objinspstrconsts.pas +++ b/ideintf/objinspstrconsts.pas @@ -468,6 +468,8 @@ resourcestring oisUnableToChangeParentOfControlToNewParent = 'Unable to change parent of ' +'control %s%s%s to new parent %s%s%s.%s%s'; + oisAddCollectionItem = '&Add Item'; + implementation end. diff --git a/ideintf/propedits.pp b/ideintf/propedits.pp index 515ee3473f..77e46e2842 100644 --- a/ideintf/propedits.pp +++ b/ideintf/propedits.pp @@ -6027,20 +6027,20 @@ begin if ARoot=nil then continue; if (ARoot<>APersistent) and (List.IndexOf(ARoot)>=0) then continue; List.Add(ARoot); - if ARoot is TComponent then begin - // ... get the designer ... - AForm:=GetDesignerForm(TComponent(ARoot)); - if (AForm<>nil) and (AForm.Designer<>nil) then - AForm.Designer.Modified; // ... and mark it modified - end; + // ... get the designer ... + AForm:=GetDesignerForm(ARoot); + if (AForm <> nil) and (AForm.Designer <> nil) then + AForm.Designer.Modified; // ... and mark it modified end; finally List.Free; end; end - else if (FLookupRoot<>nil) and (FLookupRoot is TComponent) then begin - AForm:=GetDesignerForm(TComponent(FLookupRoot)); - if (AForm<>nil) and (AForm.Designer<>nil) then + else + if (FLookupRoot <> nil) then + begin + AForm := GetDesignerForm(FLookupRoot); + if (AForm <> nil) and (AForm.Designer <> nil) then AForm.Designer.Modified; end; end;