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 -
This commit is contained in:
paul 2009-12-17 14:05:01 +00:00
parent 28705f03fa
commit e4cdead4c8
6 changed files with 83 additions and 27 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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.

View File

@ -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;