Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit b2f7ee4

Browse files
Merge branch 'gumme-WpfDesignerPropGrid'
2 parents 1817318 + 98aa45a commit b2f7ee4

17 files changed

Lines changed: 328 additions & 227 deletions

File tree

samples/XamlDesigner/Document.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ public XamlErrorService XamlErrorService {
153153
}
154154
}
155155

156-
OutlineNode outlineRoot;
156+
IOutlineNode outlineRoot;
157157

158-
public OutlineNode OutlineRoot {
158+
public IOutlineNode OutlineRoot {
159159
get {
160160
return outlineRoot;
161161
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Reference Include="System.Core" />
5555
<Reference Include="System.Design" />
5656
<Reference Include="System.Drawing" />
57+
<Reference Include="System.Drawing" />
5758
<Reference Include="System.Drawing.Design" />
5859
<Reference Include="System.Windows.Forms" />
5960
<Reference Include="System.Xaml">

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ public void HitTest(Point mousePosition, bool testAdorners, bool testDesignSurfa
109109
return;
110110
}
111111
// First try hit-testing on the adorner layer.
112-
112+
113113
bool continueHitTest = true;
114-
114+
115+
HitTestFilterCallback filterBehavior = CustomHitTestFilterBehavior ?? FilterHitTestInvisibleElements;
116+
CustomHitTestFilterBehavior = null;
115117
hitTestElements.Clear();
116118

117119
if (testAdorners) {
120+
118121
RunHitTest(
119-
_adornerLayer, mousePosition, FilterHitTestInvisibleElements,
122+
_adornerLayer, mousePosition, filterBehavior,
120123
delegate(HitTestResult result) {
121124
if (result != null && result.VisualHit != null && result.VisualHit is Visual) {
122125
DesignPanelHitTestResult customResult = new DesignPanelHitTestResult((Visual)result.VisualHit);
@@ -135,14 +138,14 @@ public void HitTest(Point mousePosition, bool testAdorners, bool testDesignSurfa
135138
}
136139
});
137140
}
138-
141+
139142
if (continueHitTest && testDesignSurface) {
140143
RunHitTest(
141-
this.Child, mousePosition, FilterHitTestInvisibleElements,
144+
this.Child, mousePosition, filterBehavior,
142145
delegate(HitTestResult result) {
143146
if (result != null && result.VisualHit != null && result.VisualHit is Visual) {
144147
DesignPanelHitTestResult customResult = new DesignPanelHitTestResult((Visual)result.VisualHit);
145-
148+
146149
ViewService viewService = _context.Services.View;
147150
DependencyObject obj = result.VisualHit;
148151

@@ -210,6 +213,8 @@ public DesignPanel()
210213

211214
#region Properties
212215

216+
//Set custom HitTestFilterCallbak
217+
public HitTestFilterCallback CustomHitTestFilterBehavior { get; set; }
213218
/// <summary>
214219
/// Gets/Sets the design context.
215220
/// </summary>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ public Outline()
4040
}
4141

4242
public static readonly DependencyProperty RootProperty =
43-
DependencyProperty.Register("Root", typeof(OutlineNode), typeof(Outline));
43+
DependencyProperty.Register("Root", typeof(IOutlineNode), typeof(Outline));
4444

45-
public OutlineNode Root {
46-
get { return (OutlineNode)GetValue(RootProperty); }
45+
public IOutlineNode Root
46+
{
47+
get { return (IOutlineNode)GetValue(RootProperty); }
4748
set { SetValue(RootProperty, value); }
4849
}
4950

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

Lines changed: 30 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -34,167 +34,61 @@
3434

3535
namespace ICSharpCode.WpfDesign.Designer.OutlineView
3636
{
37-
public class OutlineNode : INotifyPropertyChanged
37+
public interface IOutlineNode
3838
{
39-
//Used to check if element can enter other containers
40-
public static PlacementType DummyPlacementType;
41-
42-
static OutlineNode()
43-
{
44-
DummyPlacementType = PlacementType.Register("DummyPlacement");
45-
}
46-
public static OutlineNode Create(DesignItem designItem)
47-
{
48-
OutlineNode node;
49-
if (!outlineNodes.TryGetValue(designItem, out node)) {
50-
node = new OutlineNode(designItem);
51-
outlineNodes[designItem] = node;
52-
}
53-
return node;
54-
}
39+
ISelectionService SelectionService { get; }
40+
bool IsExpanded { get; set; }
41+
DesignItem DesignItem { get; set; }
42+
bool IsSelected { get; set; }
43+
bool IsDesignTimeVisible { get; set; }
44+
bool IsDesignTimeLocked { get; }
45+
string Name { get; }
46+
bool CanInsert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy);
47+
void Insert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy);
48+
ObservableCollection<IOutlineNode> Children{ get; }
49+
}
50+
5551

52+
public class OutlineNode: OutlineNodeBase
53+
{
5654
//TODO: Reset with DesignContext
57-
static Dictionary<DesignItem, OutlineNode> outlineNodes = new Dictionary<DesignItem, OutlineNode>();
55+
static Dictionary<DesignItem, IOutlineNode> outlineNodes = new Dictionary<DesignItem, IOutlineNode>();
5856

59-
OutlineNode(DesignItem designItem)
57+
protected OutlineNode(DesignItem designitem): base(designitem)
6058
{
61-
DesignItem = designItem;
6259
UpdateChildren();
63-
64-
var hidden = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).ValueOnInstance;
65-
if (hidden != null && (bool) hidden == true) {
66-
this._isDesignTimeVisible = false;
67-
((FrameworkElement) this.DesignItem.Component).Visibility = Visibility.Hidden;
68-
}
69-
70-
var locked = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).ValueOnInstance;
71-
if (locked != null && (bool) locked == true) {
72-
this._isDesignTimeLocked = true;
73-
}
74-
75-
//TODO
76-
DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged);
77-
DesignItem.PropertyChanged += new PropertyChangedEventHandler(DesignItem_PropertyChanged);
7860
SelectionService.SelectionChanged += new EventHandler<DesignItemCollectionEventArgs>(Selection_SelectionChanged);
7961
}
8062

81-
public DesignItem DesignItem { get; private set; }
82-
83-
public ISelectionService SelectionService {
84-
get { return DesignItem.Services.Selection; }
85-
}
86-
87-
bool isExpanded = true;
88-
89-
public bool IsExpanded {
90-
get {
91-
return isExpanded;
92-
}
93-
set {
94-
isExpanded = value;
95-
RaisePropertyChanged("IsExpanded");
96-
}
97-
}
98-
99-
bool isSelected;
100-
101-
public bool IsSelected {
102-
get {
103-
return isSelected;
104-
}
105-
set {
106-
if (isSelected != value) {
107-
isSelected = value;
108-
SelectionService.SetSelectedComponents(new[] { DesignItem },
109-
value ? SelectionTypes.Add : SelectionTypes.Remove);
110-
RaisePropertyChanged("IsSelected");
111-
}
112-
}
113-
}
114-
115-
bool _isDesignTimeVisible = true;
116-
117-
public bool IsDesignTimeVisible
63+
static OutlineNode()
11864
{
119-
get {
120-
return _isDesignTimeVisible;
121-
}
122-
set {
123-
_isDesignTimeVisible = value;
124-
var ctl = DesignItem.Component as UIElement;
125-
ctl.Visibility = _isDesignTimeVisible ? Visibility.Visible : Visibility.Hidden;
126-
127-
RaisePropertyChanged("IsDesignTimeVisible");
128-
129-
if (!value)
130-
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).SetValue(true);
131-
else
132-
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).Reset();
133-
}
65+
DummyPlacementType = PlacementType.Register("DummyPlacement");
13466
}
13567

136-
bool _isDesignTimeLocked = false;
137-
138-
public bool IsDesignTimeLocked
68+
public static IOutlineNode Create(DesignItem designItem)
13969
{
140-
get {
141-
return _isDesignTimeLocked;
142-
}
143-
set {
144-
_isDesignTimeLocked = value;
145-
((XamlDesignItem)DesignItem).IsDesignTimeLocked = _isDesignTimeLocked;
146-
147-
RaisePropertyChanged("IsDesignTimeLocked");
148-
149-
// if (value)
150-
// DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).SetValue(true);
151-
// else
152-
// DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).Reset();
153-
}
154-
}
155-
156-
ObservableCollection<OutlineNode> children = new ObservableCollection<OutlineNode>();
157-
158-
public ObservableCollection<OutlineNode> Children {
159-
get { return children; }
160-
}
161-
162-
public string Name {
163-
get {
164-
if (string.IsNullOrEmpty(DesignItem.Name)) {
165-
return DesignItem.ComponentType.Name;
166-
}
167-
return DesignItem.ComponentType.Name + " (" + DesignItem.Name + ")";
70+
IOutlineNode node;
71+
if (!outlineNodes.TryGetValue(designItem, out node)) {
72+
node = new OutlineNode(designItem);
73+
outlineNodes[designItem] = node;
16874
}
75+
return node;
16976
}
17077

17178
void Selection_SelectionChanged(object sender, DesignItemCollectionEventArgs e)
17279
{
17380
IsSelected = DesignItem.Services.Selection.IsComponentSelected(DesignItem);
17481
}
17582

176-
void DesignItem_NameChanged(object sender, EventArgs e)
177-
{
178-
RaisePropertyChanged("Name");
179-
}
180-
181-
void DesignItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
182-
{
183-
if (e.PropertyName == DesignItem.ContentPropertyName) {
184-
UpdateChildren();
185-
}
186-
}
187-
188-
void UpdateChildren()
83+
protected override void UpdateChildren()
18984
{
19085
Children.Clear();
19186

19287
if (DesignItem.ContentPropertyName != null) {
19388
var content = DesignItem.ContentProperty;
19489
if (content.IsCollection) {
19590
UpdateChildrenCore(content.CollectionElements);
196-
}
197-
else {
91+
} else {
19892
if (content.Value != null) {
19993
UpdateChildrenCore(new[] { content.Value });
20094
}
@@ -208,16 +102,12 @@ void UpdateChildrenCore(IEnumerable<DesignItem> items)
208102
if (ModelTools.CanSelectComponent(item)) {
209103
var node = OutlineNode.Create(item);
210104
Children.Add(node);
211-
}
212-
else
213-
{
105+
} else {
214106
var content = item.ContentProperty;
215-
if (content != null)
216-
{
107+
if (content != null) {
217108
if (content.IsCollection) {
218109
UpdateChildrenCore(content.CollectionElements);
219-
}
220-
else {
110+
} else {
221111
if (content.Value != null) {
222112
UpdateChildrenCore(new[] { content.Value });
223113
}
@@ -226,57 +116,5 @@ void UpdateChildrenCore(IEnumerable<DesignItem> items)
226116
}
227117
}
228118
}
229-
230-
public bool CanInsert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)
231-
{
232-
var placementBehavior = DesignItem.GetBehavior<IPlacementBehavior>();
233-
if (placementBehavior == null)
234-
return false;
235-
var operation = PlacementOperation.Start(nodes.Select(node => node.DesignItem).ToArray(), DummyPlacementType);
236-
if (operation != null) {
237-
bool canEnter = placementBehavior.CanEnterContainer(operation, true);
238-
operation.Abort();
239-
return canEnter;
240-
}
241-
return false;
242-
}
243-
244-
public void Insert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)
245-
{
246-
using (var moveTransaction = DesignItem.Context.OpenGroup("Item moved in outline view", nodes.Select(n => n.DesignItem).ToList())) {
247-
if (copy) {
248-
nodes = nodes.Select(n => OutlineNode.Create(n.DesignItem.Clone())).ToList();
249-
} else {
250-
foreach (var node in nodes) {
251-
node.DesignItem.Remove();
252-
}
253-
}
254-
255-
var index = after == null ? 0 : Children.IndexOf(after) + 1;
256-
257-
var content = DesignItem.ContentProperty;
258-
if (content.IsCollection) {
259-
foreach (var node in nodes) {
260-
content.CollectionElements.Insert(index++, node.DesignItem);
261-
}
262-
} else {
263-
content.SetValue(nodes.First().DesignItem);
264-
}
265-
moveTransaction.Commit();
266-
}
267-
}
268-
269-
#region INotifyPropertyChanged Members
270-
271-
public event PropertyChangedEventHandler PropertyChanged;
272-
273-
void RaisePropertyChanged(string name)
274-
{
275-
if (PropertyChanged != null) {
276-
PropertyChanged(this, new PropertyChangedEventArgs(name));
277-
}
278-
}
279-
280-
#endregion
281119
}
282120
}

0 commit comments

Comments
 (0)