Browse Source

Implemented inteface for OutlineNode so that a custom outlinenode can be implemented

pull/315/head
tbulle 12 years ago
parent
commit
b67af16c45
  1. 1
      src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj
  2. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/Outline.xaml.cs
  3. 344
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs
  4. 239
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs
  5. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/CollectionEditor.xaml.cs
  6. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs
  7. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  8. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

1
src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj

@ -54,6 +54,7 @@
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Design" /> <Reference Include="System.Design" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Design" /> <Reference Include="System.Drawing.Design" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml"> <Reference Include="System.Xaml">

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/Outline.xaml.cs

@ -25,10 +25,11 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
} }
public static readonly DependencyProperty RootProperty = public static readonly DependencyProperty RootProperty =
DependencyProperty.Register("Root", typeof(OutlineNode), typeof(Outline)); DependencyProperty.Register("Root", typeof(IOutlineNode), typeof(Outline));
public OutlineNode Root { public IOutlineNode Root
get { return (OutlineNode)GetValue(RootProperty); } {
get { return (IOutlineNode)GetValue(RootProperty); }
set { SetValue(RootProperty, value); } set { SetValue(RootProperty, value); }
} }

344
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs

@ -19,249 +19,101 @@ using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.OutlineView namespace ICSharpCode.WpfDesign.Designer.OutlineView
{ {
public class OutlineNode : INotifyPropertyChanged public interface IOutlineNode
{ {
//Used to check if element can enter other containers ISelectionService SelectionService { get; }
public static PlacementType DummyPlacementType; bool IsExpanded { get; set; }
DesignItem DesignItem { get; set; }
static OutlineNode() bool IsSelected { get; set; }
{ bool IsDesignTimeVisible { get; set; }
DummyPlacementType = PlacementType.Register("DummyPlacement"); bool IsDesignTimeLocked { get; }
} string Name { get; }
public static OutlineNode Create(DesignItem designItem) bool CanInsert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy);
{ void Insert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy);
OutlineNode node; }
if (!outlineNodes.TryGetValue(designItem, out node)) {
node = new OutlineNode(designItem);
outlineNodes[designItem] = node; public class OutlineNode: OutlineNodeBase
} {
return node; //TODO: Reset with DesignContext
} static Dictionary<DesignItem, IOutlineNode> outlineNodes = new Dictionary<DesignItem, IOutlineNode>();
//TODO: Reset with DesignContext protected OutlineNode(DesignItem designitem): base(designitem)
static Dictionary<DesignItem, OutlineNode> outlineNodes = new Dictionary<DesignItem, OutlineNode>(); {
UpdateChildren();
OutlineNode(DesignItem designItem) SelectionService.SelectionChanged += new EventHandler<DesignItemCollectionEventArgs>(Selection_SelectionChanged);
{ }
DesignItem = designItem;
UpdateChildren(); static OutlineNode()
{
var hidden = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).ValueOnInstance; DummyPlacementType = PlacementType.Register("DummyPlacement");
if (hidden != null && (bool) hidden == true) { }
this._isDesignTimeVisible = false;
((FrameworkElement) this.DesignItem.Component).Visibility = Visibility.Hidden; public static IOutlineNode Create(DesignItem designItem)
} {
IOutlineNode node;
var locked = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).ValueOnInstance; if (!outlineNodes.TryGetValue(designItem, out node))
if (locked != null && (bool) locked == true) { {
this._isDesignTimeLocked = true; node = new OutlineNode(designItem);
} outlineNodes[designItem] = node;
}
//TODO return node;
DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged); }
DesignItem.PropertyChanged += new PropertyChangedEventHandler(DesignItem_PropertyChanged);
SelectionService.SelectionChanged += new EventHandler<DesignItemCollectionEventArgs>(Selection_SelectionChanged); void Selection_SelectionChanged(object sender, DesignItemCollectionEventArgs e)
} {
IsSelected = DesignItem.Services.Selection.IsComponentSelected(DesignItem);
public DesignItem DesignItem { get; private set; } }
public ISelectionService SelectionService { protected override void UpdateChildren()
get { return DesignItem.Services.Selection; } {
} Children.Clear();
bool isExpanded = true; if (DesignItem.ContentPropertyName != null)
{
public bool IsExpanded { var content = DesignItem.ContentProperty;
get { if (content.IsCollection)
return isExpanded; {
} UpdateChildrenCore(content.CollectionElements);
set { }
isExpanded = value; else
RaisePropertyChanged("IsExpanded"); {
} if (content.Value != null)
} {
UpdateChildrenCore(new[] { content.Value });
bool isSelected; }
}
public bool IsSelected { }
get { }
return isSelected;
} void UpdateChildrenCore(IEnumerable<DesignItem> items)
set { {
if (isSelected != value) { foreach (var item in items)
isSelected = value; {
SelectionService.SetSelectedComponents(new[] { DesignItem }, if (ModelTools.CanSelectComponent(item))
value ? SelectionTypes.Add : SelectionTypes.Remove); {
RaisePropertyChanged("IsSelected"); var node = OutlineNode.Create(item);
} Children.Add(node);
} }
} else
{
bool _isDesignTimeVisible = true; var content = item.ContentProperty;
if (content != null)
public bool IsDesignTimeVisible {
{ if (content.IsCollection)
get { {
return _isDesignTimeVisible; UpdateChildrenCore(content.CollectionElements);
} }
set { else
_isDesignTimeVisible = value; {
var ctl = DesignItem.Component as UIElement; if (content.Value != null)
ctl.Visibility = _isDesignTimeVisible ? Visibility.Visible : Visibility.Hidden; {
UpdateChildrenCore(new[] { content.Value });
RaisePropertyChanged("IsDesignTimeVisible"); }
}
if (!value) }
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).SetValue(true); }
else }
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).Reset(); }
} }
} }
bool _isDesignTimeLocked = false;
public bool IsDesignTimeLocked
{
get {
return _isDesignTimeLocked;
}
set {
_isDesignTimeLocked = value;
((XamlDesignItem)DesignItem).IsDesignTimeLocked = _isDesignTimeLocked;
RaisePropertyChanged("IsDesignTimeLocked");
// if (value)
// DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).SetValue(true);
// else
// DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).Reset();
}
}
ObservableCollection<OutlineNode> children = new ObservableCollection<OutlineNode>();
public ObservableCollection<OutlineNode> Children {
get { return children; }
}
public string Name {
get {
if (string.IsNullOrEmpty(DesignItem.Name)) {
return DesignItem.ComponentType.Name;
}
return DesignItem.ComponentType.Name + " (" + DesignItem.Name + ")";
}
}
void Selection_SelectionChanged(object sender, DesignItemCollectionEventArgs e)
{
IsSelected = DesignItem.Services.Selection.IsComponentSelected(DesignItem);
}
void DesignItem_NameChanged(object sender, EventArgs e)
{
RaisePropertyChanged("Name");
}
void DesignItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == DesignItem.ContentPropertyName) {
UpdateChildren();
}
}
void UpdateChildren()
{
Children.Clear();
if (DesignItem.ContentPropertyName != null) {
var content = DesignItem.ContentProperty;
if (content.IsCollection) {
UpdateChildrenCore(content.CollectionElements);
}
else {
if (content.Value != null) {
UpdateChildrenCore(new[] { content.Value });
}
}
}
}
void UpdateChildrenCore(IEnumerable<DesignItem> items)
{
foreach (var item in items) {
if (ModelTools.CanSelectComponent(item)) {
var node = OutlineNode.Create(item);
Children.Add(node);
}
else
{
var content = item.ContentProperty;
if (content != null)
{
if (content.IsCollection) {
UpdateChildrenCore(content.CollectionElements);
}
else {
if (content.Value != null) {
UpdateChildrenCore(new[] { content.Value });
}
}
}
}
}
}
public bool CanInsert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)
{
var placementBehavior = DesignItem.GetBehavior<IPlacementBehavior>();
if (placementBehavior == null)
return false;
var operation = PlacementOperation.Start(nodes.Select(node => node.DesignItem).ToArray(), DummyPlacementType);
if (operation != null) {
bool canEnter = placementBehavior.CanEnterContainer(operation, true);
operation.Abort();
return canEnter;
}
return false;
}
public void Insert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)
{
using (var moveTransaction = DesignItem.Context.OpenGroup("Item moved in outline view", nodes.Select(n => n.DesignItem).ToList())) {
if (copy) {
nodes = nodes.Select(n => OutlineNode.Create(n.DesignItem.Clone())).ToList();
} else {
foreach (var node in nodes) {
node.DesignItem.Remove();
}
}
var index = after == null ? 0 : Children.IndexOf(after) + 1;
var content = DesignItem.ContentProperty;
if (content.IsCollection) {
foreach (var node in nodes) {
content.CollectionElements.Insert(index++, node.DesignItem);
}
} else {
content.SetValue(nodes.First().DesignItem);
}
moveTransaction.Commit();
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string name)
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
}

239
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs

@ -0,0 +1,239 @@
/*
* Created by SharpDevelop.
* User: trubra
* Date: 2014-01-28
* Time: 10:09
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Linq;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.OutlineView
{
/// <summary>
/// Description of OutlineNodeBase.
/// </summary>
public abstract class OutlineNodeBase : INotifyPropertyChanged, IOutlineNode
{
protected abstract void UpdateChildren();
//Used to check if element can enter other containers
protected static PlacementType DummyPlacementType;
protected OutlineNodeBase(DesignItem designItem)
{
DesignItem = designItem;
var hidden = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).ValueOnInstance;
if (hidden != null && (bool)hidden)
{
_isDesignTimeVisible = false;
((FrameworkElement)DesignItem.Component).Visibility = Visibility.Hidden;
}
var locked = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).ValueOnInstance;
if (locked != null && (bool)locked)
{
_isDesignTimeLocked = true;
}
//TODO
DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged);
DesignItem.PropertyChanged += new PropertyChangedEventHandler(DesignItem_PropertyChanged);
}
public DesignItem DesignItem { get; set; }
public ISelectionService SelectionService
{
get { return DesignItem.Services.Selection; }
}
bool isExpanded = true;
public bool IsExpanded
{
get
{
return isExpanded;
}
set
{
isExpanded = value;
RaisePropertyChanged("IsExpanded");
}
}
bool isSelected;
public bool IsSelected
{
get
{
return isSelected;
}
set
{
if (isSelected != value)
{
isSelected = value;
SelectionService.SetSelectedComponents(new[] { DesignItem },
value ? SelectionTypes.Add : SelectionTypes.Remove);
RaisePropertyChanged("IsSelected");
}
}
}
bool _isDesignTimeVisible = true;
public bool IsDesignTimeVisible
{
get
{
return _isDesignTimeVisible;
}
set
{
_isDesignTimeVisible = value;
var ctl = DesignItem.Component as UIElement;
if(ctl!=null)
ctl.Visibility = _isDesignTimeVisible ? Visibility.Visible : Visibility.Hidden;
RaisePropertyChanged("IsDesignTimeVisible");
if (!value)
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).SetValue(true);
else
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).Reset();
}
}
bool _isDesignTimeLocked = false;
public bool IsDesignTimeLocked
{
get
{
return _isDesignTimeLocked;
}
set
{
_isDesignTimeLocked = value;
((XamlDesignItem)DesignItem).IsDesignTimeLocked = _isDesignTimeLocked;
RaisePropertyChanged("IsDesignTimeLocked");
// if (value)
// DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).SetValue(true);
// else
// DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).Reset();
}
}
ObservableCollection<IOutlineNode> children = new ObservableCollection<IOutlineNode>();
public ObservableCollection<IOutlineNode> Children
{
get { return children; }
}
public string Name
{
get
{
if (string.IsNullOrEmpty(DesignItem.Name))
{
return DesignItem.ComponentType.Name;
}
return DesignItem.ComponentType.Name + " (" + DesignItem.Name + ")";
}
}
void DesignItem_NameChanged(object sender, EventArgs e)
{
RaisePropertyChanged("Name");
}
void DesignItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == DesignItem.ContentPropertyName)
{
UpdateChildren();
}
}
public bool CanInsert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy)
{
var placementBehavior = DesignItem.GetBehavior<IPlacementBehavior>();
if (placementBehavior == null)
return false;
var operation = PlacementOperation.Start(nodes.Select(node => node.DesignItem).ToArray(), DummyPlacementType);
if (operation != null)
{
bool canEnter = placementBehavior.CanEnterContainer(operation, true);
operation.Abort();
return canEnter;
}
return false;
}
public virtual void Insert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy)
{
using (var moveTransaction = DesignItem.Context.OpenGroup("Item moved in outline view", nodes.Select(n => n.DesignItem).ToList()))
{
if (copy)
{
nodes = nodes.Select(n => OutlineNode.Create(n.DesignItem.Clone())).ToList();
}
else
{
foreach (var node in nodes)
{
node.DesignItem.Remove();
}
}
var index = after == null ? 0 : Children.IndexOf(after) + 1;
var content = DesignItem.ContentProperty;
if (content.IsCollection)
{
foreach (var node in nodes)
{
content.CollectionElements.Insert(index++, node.DesignItem);
}
}
else
{
content.SetValue(nodes.First().DesignItem);
}
moveTransaction.Commit();
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/CollectionEditor.xaml.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
if(control!=null){ if(control!=null){
TypeMappings.TryGetValue(control.GetType(), out _type); TypeMappings.TryGetValue(control.GetType(), out _type);
if (_type != null) { if (_type != null) {
OutlineNode node = OutlineNode.Create(item); IOutlineNode node = OutlineNode.Create(item);
Outline.Root = node; Outline.Root = node;
PropertyGridView.PropertyGrid.SelectedItems = item.Services.Selection.SelectedItems; PropertyGridView.PropertyGrid.SelectedItems = item.Services.Selection.SelectedItems;
} }

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs

@ -45,13 +45,13 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
public CategoriesCollection Categories { get; private set; } public CategoriesCollection Categories { get; private set; }
public PropertyNodeCollection Events { get; private set; } public PropertyNodeCollection Events { get; private set; }
public EventHandler AggregatePropertiesUpdated { get; set; } public event EventHandler AggregatePropertiesUpdated;
private PropertyGridGroupMode _groupMode; private PropertyGridGroupMode _groupMode;
public PropertyGridGroupMode GroupMode public PropertyGridGroupMode GroupMode
{ {
get { return _groupMode; } get { return _groupMode; }
set set
{ {
if (_groupMode != value) if (_groupMode != value)

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

@ -146,7 +146,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
{ {
CreateComponentTool cct = new CreateComponentTool(createdItem); CreateComponentTool cct = new CreateComponentTool(createdItem);
return AddItemWithCustomSize(container, cct.CreateItem(container.Context), position, size); return AddItemWithCustomSize(container, cct.CreateItem(container.Context), position, size);
} }
public static bool AddItemWithDefaultSize(DesignItem container, Type createdItem, Size size) public static bool AddItemWithDefaultSize(DesignItem container, Type createdItem, Size size)
{ {

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -87,6 +87,7 @@
</Compile> </Compile>
<Compile Include="Extensions\RenderTransformOriginExtension.cs" /> <Compile Include="Extensions\RenderTransformOriginExtension.cs" />
<Compile Include="Extensions\RightClickContextMenuExtension.cs" /> <Compile Include="Extensions\RightClickContextMenuExtension.cs" />
<Compile Include="OutlineView\OutlineNodeBase.cs" />
<Compile Include="PropertyGrid\Editors\FlatCollectionEditor.xaml.cs"> <Compile Include="PropertyGrid\Editors\FlatCollectionEditor.xaml.cs">
<DependentUpon>FlatCollectionEditor.xaml</DependentUpon> <DependentUpon>FlatCollectionEditor.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>

Loading…
Cancel
Save