Browse Source

Format changes

pull/315/head
tbulle 12 years ago
parent
commit
a3c162e9c0
  1. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/Outline.xaml.cs
  2. 163
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs
  3. 418
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs
  4. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs

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

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

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

@ -20,100 +20,85 @@ using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.OutlineView namespace ICSharpCode.WpfDesign.Designer.OutlineView
{ {
public interface IOutlineNode public interface IOutlineNode
{ {
ISelectionService SelectionService { get; } ISelectionService SelectionService { get; }
bool IsExpanded { get; set; } bool IsExpanded { get; set; }
DesignItem DesignItem { get; set; } DesignItem DesignItem { get; set; }
bool IsSelected { get; set; } bool IsSelected { get; set; }
bool IsDesignTimeVisible { get; set; } bool IsDesignTimeVisible { get; set; }
bool IsDesignTimeLocked { get; } bool IsDesignTimeLocked { get; }
string Name { get; } string Name { get; }
bool CanInsert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy); bool CanInsert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy);
void Insert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy); void Insert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy);
} }
public class OutlineNode: OutlineNodeBase public class OutlineNode: OutlineNodeBase
{ {
//TODO: Reset with DesignContext //TODO: Reset with DesignContext
static Dictionary<DesignItem, IOutlineNode> outlineNodes = new Dictionary<DesignItem, IOutlineNode>(); static Dictionary<DesignItem, IOutlineNode> outlineNodes = new Dictionary<DesignItem, IOutlineNode>();
protected OutlineNode(DesignItem designitem): base(designitem) protected OutlineNode(DesignItem designitem): base(designitem)
{ {
UpdateChildren(); UpdateChildren();
SelectionService.SelectionChanged += new EventHandler<DesignItemCollectionEventArgs>(Selection_SelectionChanged); SelectionService.SelectionChanged += new EventHandler<DesignItemCollectionEventArgs>(Selection_SelectionChanged);
} }
static OutlineNode() static OutlineNode()
{ {
DummyPlacementType = PlacementType.Register("DummyPlacement"); DummyPlacementType = PlacementType.Register("DummyPlacement");
} }
public static IOutlineNode Create(DesignItem designItem) public static IOutlineNode Create(DesignItem designItem)
{ {
IOutlineNode node; IOutlineNode node;
if (!outlineNodes.TryGetValue(designItem, out node)) if (!outlineNodes.TryGetValue(designItem, out node)) {
{ node = new OutlineNode(designItem);
node = new OutlineNode(designItem); outlineNodes[designItem] = node;
outlineNodes[designItem] = node; }
} return node;
return node; }
}
void Selection_SelectionChanged(object sender, DesignItemCollectionEventArgs e) void Selection_SelectionChanged(object sender, DesignItemCollectionEventArgs e)
{ {
IsSelected = DesignItem.Services.Selection.IsComponentSelected(DesignItem); IsSelected = DesignItem.Services.Selection.IsComponentSelected(DesignItem);
} }
protected override void UpdateChildren() protected override void UpdateChildren()
{ {
Children.Clear(); Children.Clear();
if (DesignItem.ContentPropertyName != null) if (DesignItem.ContentPropertyName != null) {
{ var content = DesignItem.ContentProperty;
var content = DesignItem.ContentProperty; if (content.IsCollection) {
if (content.IsCollection) UpdateChildrenCore(content.CollectionElements);
{ } else {
UpdateChildrenCore(content.CollectionElements); if (content.Value != null) {
} UpdateChildrenCore(new[] { content.Value });
else }
{ }
if (content.Value != null) }
{ }
UpdateChildrenCore(new[] { content.Value });
}
}
}
}
void UpdateChildrenCore(IEnumerable<DesignItem> items) void UpdateChildrenCore(IEnumerable<DesignItem> items)
{ {
foreach (var item in items) foreach (var item in items) {
{ if (ModelTools.CanSelectComponent(item)) {
if (ModelTools.CanSelectComponent(item)) var node = OutlineNode.Create(item);
{ Children.Add(node);
var node = OutlineNode.Create(item); } else {
Children.Add(node); var content = item.ContentProperty;
} if (content != null) {
else if (content.IsCollection) {
{ UpdateChildrenCore(content.CollectionElements);
var content = item.ContentProperty; } else {
if (content != null) if (content.Value != null) {
{ UpdateChildrenCore(new[] { content.Value });
if (content.IsCollection) }
{ }
UpdateChildrenCore(content.CollectionElements); }
} }
else }
{ }
if (content.Value != null) }
{ }
UpdateChildrenCore(new[] { content.Value });
}
}
}
}
}
}
}
}

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

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

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

@ -51,7 +51,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
public PropertyGridGroupMode GroupMode public PropertyGridGroupMode GroupMode
{ {
get { return _groupMode; } get { return _groupMode; }
set set
{ {
if (_groupMode != value) if (_groupMode != value)
@ -202,7 +202,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
if (selectedItems == null || selectedItems.Count == 0) return; if (selectedItems == null || selectedItems.Count == 0) return;
if (selectedItems.Count == 1) SingleItem = selectedItems[0]; if (selectedItems.Count == 1) SingleItem = selectedItems[0];
foreach (var md in GetDescriptors()) { foreach (var md in GetDescriptors()) {
if (PassesFilter(md.Name)) if (PassesFilter(md.Name))
AddNode(md); AddNode(md);
@ -210,7 +210,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
} finally { } finally {
reloadActive = false; reloadActive = false;
if (AggregatePropertiesUpdated != null) if (AggregatePropertiesUpdated != null)
AggregatePropertiesUpdated(this, EventArgs.Empty); AggregatePropertiesUpdated(this, EventArgs.Empty);
} }
} }

Loading…
Cancel
Save