1919
2020namespace ICSharpCode . WpfDesign . Designer . OutlineView
2121{
22- public class OutlineNode : INotifyPropertyChanged
22+ public interface IOutlineNode
2323 {
24- //Used to check if element can enter other containers
25- public static PlacementType DummyPlacementType ;
26-
27- static OutlineNode ( )
28- {
29- DummyPlacementType = PlacementType . Register ( "DummyPlacement" ) ;
30- }
31- public static OutlineNode Create ( DesignItem designItem )
32- {
33- OutlineNode node ;
34- if ( ! outlineNodes . TryGetValue ( designItem , out node ) ) {
35- node = new OutlineNode ( designItem ) ;
36- outlineNodes [ designItem ] = node ;
37- }
38- return node ;
39- }
24+ ISelectionService SelectionService { get ; }
25+ bool IsExpanded { get ; set ; }
26+ DesignItem DesignItem { get ; set ; }
27+ bool IsSelected { get ; set ; }
28+ bool IsDesignTimeVisible { get ; set ; }
29+ bool IsDesignTimeLocked { get ; }
30+ string Name { get ; }
31+ bool CanInsert ( IEnumerable < IOutlineNode > nodes , IOutlineNode after , bool copy ) ;
32+ void Insert ( IEnumerable < IOutlineNode > nodes , IOutlineNode after , bool copy ) ;
33+ }
34+
4035
36+ public class OutlineNode : OutlineNodeBase
37+ {
4138 //TODO: Reset with DesignContext
42- static Dictionary < DesignItem , OutlineNode > outlineNodes = new Dictionary < DesignItem , OutlineNode > ( ) ;
39+ static Dictionary < DesignItem , IOutlineNode > outlineNodes = new Dictionary < DesignItem , IOutlineNode > ( ) ;
4340
44- OutlineNode ( DesignItem designItem )
41+ protected OutlineNode ( DesignItem designitem ) : base ( designitem )
4542 {
46- DesignItem = designItem ;
4743 UpdateChildren ( ) ;
48-
49- var hidden = designItem . Properties . GetAttachedProperty ( DesignTimeProperties . IsHiddenProperty ) . ValueOnInstance ;
50- if ( hidden != null && ( bool ) hidden == true ) {
51- this . _isDesignTimeVisible = false ;
52- ( ( FrameworkElement ) this . DesignItem . Component ) . Visibility = Visibility . Hidden ;
53- }
54-
55- var locked = designItem . Properties . GetAttachedProperty ( DesignTimeProperties . IsLockedProperty ) . ValueOnInstance ;
56- if ( locked != null && ( bool ) locked == true ) {
57- this . _isDesignTimeLocked = true ;
58- }
59-
60- //TODO
61- DesignItem . NameChanged += new EventHandler ( DesignItem_NameChanged ) ;
62- DesignItem . PropertyChanged += new PropertyChangedEventHandler ( DesignItem_PropertyChanged ) ;
6344 SelectionService . SelectionChanged += new EventHandler < DesignItemCollectionEventArgs > ( Selection_SelectionChanged ) ;
6445 }
6546
66- public DesignItem DesignItem { get ; private set ; }
67-
68- public ISelectionService SelectionService {
69- get { return DesignItem . Services . Selection ; }
70- }
71-
72- bool isExpanded = true ;
73-
74- public bool IsExpanded {
75- get {
76- return isExpanded ;
77- }
78- set {
79- isExpanded = value ;
80- RaisePropertyChanged ( "IsExpanded" ) ;
81- }
82- }
83-
84- bool isSelected ;
85-
86- public bool IsSelected {
87- get {
88- return isSelected ;
89- }
90- set {
91- if ( isSelected != value ) {
92- isSelected = value ;
93- SelectionService . SetSelectedComponents ( new [ ] { DesignItem } ,
94- value ? SelectionTypes . Add : SelectionTypes . Remove ) ;
95- RaisePropertyChanged ( "IsSelected" ) ;
96- }
97- }
98- }
99-
100- bool _isDesignTimeVisible = true ;
101-
102- public bool IsDesignTimeVisible
47+ static OutlineNode ( )
10348 {
104- get {
105- return _isDesignTimeVisible ;
106- }
107- set {
108- _isDesignTimeVisible = value ;
109- var ctl = DesignItem . Component as UIElement ;
110- ctl . Visibility = _isDesignTimeVisible ? Visibility . Visible : Visibility . Hidden ;
111-
112- RaisePropertyChanged ( "IsDesignTimeVisible" ) ;
113-
114- if ( ! value )
115- DesignItem . Properties . GetAttachedProperty ( DesignTimeProperties . IsHiddenProperty ) . SetValue ( true ) ;
116- else
117- DesignItem . Properties . GetAttachedProperty ( DesignTimeProperties . IsHiddenProperty ) . Reset ( ) ;
118- }
49+ DummyPlacementType = PlacementType . Register ( "DummyPlacement" ) ;
11950 }
12051
121- bool _isDesignTimeLocked = false ;
122-
123- public bool IsDesignTimeLocked
52+ public static IOutlineNode Create ( DesignItem designItem )
12453 {
125- get {
126- return _isDesignTimeLocked ;
127- }
128- set {
129- _isDesignTimeLocked = value ;
130- ( ( XamlDesignItem ) DesignItem ) . IsDesignTimeLocked = _isDesignTimeLocked ;
131-
132- RaisePropertyChanged ( "IsDesignTimeLocked" ) ;
133-
134- // if (value)
135- // DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).SetValue(true);
136- // else
137- // DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).Reset();
138- }
139- }
140-
141- ObservableCollection < OutlineNode > children = new ObservableCollection < OutlineNode > ( ) ;
142-
143- public ObservableCollection < OutlineNode > Children {
144- get { return children ; }
145- }
146-
147- public string Name {
148- get {
149- if ( string . IsNullOrEmpty ( DesignItem . Name ) ) {
150- return DesignItem . ComponentType . Name ;
151- }
152- return DesignItem . ComponentType . Name + " (" + DesignItem . Name + ")" ;
54+ IOutlineNode node ;
55+ if ( ! outlineNodes . TryGetValue ( designItem , out node ) ) {
56+ node = new OutlineNode ( designItem ) ;
57+ outlineNodes [ designItem ] = node ;
15358 }
59+ return node ;
15460 }
15561
15662 void Selection_SelectionChanged ( object sender , DesignItemCollectionEventArgs e )
15763 {
15864 IsSelected = DesignItem . Services . Selection . IsComponentSelected ( DesignItem ) ;
15965 }
16066
161- void DesignItem_NameChanged ( object sender , EventArgs e )
162- {
163- RaisePropertyChanged ( "Name" ) ;
164- }
165-
166- void DesignItem_PropertyChanged ( object sender , PropertyChangedEventArgs e )
167- {
168- if ( e . PropertyName == DesignItem . ContentPropertyName ) {
169- UpdateChildren ( ) ;
170- }
171- }
172-
173- void UpdateChildren ( )
67+ protected override void UpdateChildren ( )
17468 {
17569 Children . Clear ( ) ;
17670
17771 if ( DesignItem . ContentPropertyName != null ) {
17872 var content = DesignItem . ContentProperty ;
17973 if ( content . IsCollection ) {
18074 UpdateChildrenCore ( content . CollectionElements ) ;
181- }
182- else {
75+ } else {
18376 if ( content . Value != null ) {
18477 UpdateChildrenCore ( new [ ] { content . Value } ) ;
18578 }
@@ -193,16 +86,12 @@ void UpdateChildrenCore(IEnumerable<DesignItem> items)
19386 if ( ModelTools . CanSelectComponent ( item ) ) {
19487 var node = OutlineNode . Create ( item ) ;
19588 Children . Add ( node ) ;
196- }
197- else
198- {
89+ } else {
19990 var content = item . ContentProperty ;
200- if ( content != null )
201- {
91+ if ( content != null ) {
20292 if ( content . IsCollection ) {
20393 UpdateChildrenCore ( content . CollectionElements ) ;
204- }
205- else {
94+ } else {
20695 if ( content . Value != null ) {
20796 UpdateChildrenCore ( new [ ] { content . Value } ) ;
20897 }
@@ -211,57 +100,5 @@ void UpdateChildrenCore(IEnumerable<DesignItem> items)
211100 }
212101 }
213102 }
214-
215- public bool CanInsert ( IEnumerable < OutlineNode > nodes , OutlineNode after , bool copy )
216- {
217- var placementBehavior = DesignItem . GetBehavior < IPlacementBehavior > ( ) ;
218- if ( placementBehavior == null )
219- return false ;
220- var operation = PlacementOperation . Start ( nodes . Select ( node => node . DesignItem ) . ToArray ( ) , DummyPlacementType ) ;
221- if ( operation != null ) {
222- bool canEnter = placementBehavior . CanEnterContainer ( operation , true ) ;
223- operation . Abort ( ) ;
224- return canEnter ;
225- }
226- return false ;
227- }
228-
229- public void Insert ( IEnumerable < OutlineNode > nodes , OutlineNode after , bool copy )
230- {
231- using ( var moveTransaction = DesignItem . Context . OpenGroup ( "Item moved in outline view" , nodes . Select ( n => n . DesignItem ) . ToList ( ) ) ) {
232- if ( copy ) {
233- nodes = nodes . Select ( n => OutlineNode . Create ( n . DesignItem . Clone ( ) ) ) . ToList ( ) ;
234- } else {
235- foreach ( var node in nodes ) {
236- node . DesignItem . Remove ( ) ;
237- }
238- }
239-
240- var index = after == null ? 0 : Children . IndexOf ( after ) + 1 ;
241-
242- var content = DesignItem . ContentProperty ;
243- if ( content . IsCollection ) {
244- foreach ( var node in nodes ) {
245- content . CollectionElements . Insert ( index ++ , node . DesignItem ) ;
246- }
247- } else {
248- content . SetValue ( nodes . First ( ) . DesignItem ) ;
249- }
250- moveTransaction . Commit ( ) ;
251- }
252- }
253-
254- #region INotifyPropertyChanged Members
255-
256- public event PropertyChangedEventHandler PropertyChanged ;
257-
258- void RaisePropertyChanged ( string name )
259- {
260- if ( PropertyChanged != null ) {
261- PropertyChanged ( this , new PropertyChangedEventArgs ( name ) ) ;
262- }
263- }
264-
265- #endregion
266103 }
267104}
0 commit comments