@@ -17,42 +17,26 @@ namespace Avalonia.Diagnostics.ViewModels
17
17
internal class ControlDetailsViewModel : ViewModelBase , IDisposable
18
18
{
19
19
private readonly IVisual _control ;
20
- private readonly IDictionary < object , List < PropertyViewModel > > _propertyIndex ;
20
+ private IDictionary < object , List < PropertyViewModel > > _propertyIndex ;
21
21
private PropertyViewModel ? _selectedProperty ;
22
+ private DataGridCollectionView _propertiesView ;
22
23
private bool _snapshotStyles ;
23
24
private bool _showInactiveStyles ;
24
25
private string ? _styleStatus ;
26
+ private object _selectedEntity ;
27
+ private readonly Stack < Tuple < string , object > > _selectedEntitiesStack = new Stack < Tuple < string , object > > ( ) ;
28
+ private string _selectedEntityName ;
29
+ private string _selectedEntityType ;
25
30
26
31
public ControlDetailsViewModel ( TreePageViewModel treePage , IVisual control )
27
32
{
28
33
_control = control ;
29
34
30
35
TreePage = treePage ;
31
-
32
- var properties = GetAvaloniaProperties ( control )
33
- . Concat ( GetClrProperties ( control ) )
34
- . OrderBy ( x => x , PropertyComparer . Instance )
35
- . ThenBy ( x => x . Name )
36
- . ToList ( ) ;
37
-
38
- _propertyIndex = properties . GroupBy ( x => x . Key ) . ToDictionary ( x => x . Key , x => x . ToList ( ) ) ;
39
-
40
- var view = new DataGridCollectionView ( properties ) ;
41
- view . GroupDescriptions . Add ( new DataGridPathGroupDescription ( nameof ( AvaloniaPropertyViewModel . Group ) ) ) ;
42
- view . Filter = FilterProperty ;
43
- PropertiesView = view ;
44
-
36
+
45
37
Layout = new ControlLayoutViewModel ( control ) ;
46
38
47
- if ( control is INotifyPropertyChanged inpc )
48
- {
49
- inpc . PropertyChanged += ControlPropertyChanged ;
50
- }
51
-
52
- if ( control is AvaloniaObject ao )
53
- {
54
- ao . PropertyChanged += ControlPropertyChanged ;
55
- }
39
+ NavigateToProperty ( control , ( control as IControl ) ? . Name ?? control . ToString ( ) ) ;
56
40
57
41
AppliedStyles = new ObservableCollection < StyleViewModel > ( ) ;
58
42
PseudoClasses = new ObservableCollection < PseudoClassViewModel > ( ) ;
@@ -133,12 +117,46 @@ public ControlDetailsViewModel(TreePageViewModel treePage, IVisual control)
133
117
134
118
public TreePageViewModel TreePage { get ; }
135
119
136
- public DataGridCollectionView PropertiesView { get ; }
120
+ public DataGridCollectionView PropertiesView
121
+ {
122
+ get => _propertiesView ;
123
+ private set => RaiseAndSetIfChanged ( ref _propertiesView , value ) ;
124
+ }
137
125
138
126
public ObservableCollection < StyleViewModel > AppliedStyles { get ; }
139
127
140
128
public ObservableCollection < PseudoClassViewModel > PseudoClasses { get ; }
141
129
130
+ public object SelectedEntity
131
+ {
132
+ get => _selectedEntity ;
133
+ set
134
+ {
135
+ RaiseAndSetIfChanged ( ref _selectedEntity , value ) ;
136
+
137
+ }
138
+ }
139
+
140
+ public string SelectedEntityName
141
+ {
142
+ get => _selectedEntityName ;
143
+ set
144
+ {
145
+ RaiseAndSetIfChanged ( ref _selectedEntityName , value ) ;
146
+
147
+ }
148
+ }
149
+
150
+ public string SelectedEntityType
151
+ {
152
+ get => _selectedEntityType ;
153
+ set
154
+ {
155
+ RaiseAndSetIfChanged ( ref _selectedEntityType , value ) ;
156
+
157
+ }
158
+ }
159
+
142
160
public PropertyViewModel ? SelectedProperty
143
161
{
144
162
get => _selectedProperty ;
@@ -378,5 +396,69 @@ private int GroupIndex(string? group)
378
396
}
379
397
}
380
398
}
399
+
400
+ public void ApplySelectedProperty ( )
401
+ {
402
+ if ( SelectedProperty == null ) return ;
403
+
404
+ var property = ( _selectedEntity as IControl ) ? . GetValue ( SelectedProperty . Key as AvaloniaProperty ) ;
405
+ if ( property == null )
406
+ {
407
+ property = _selectedEntity . GetType ( ) . GetProperty ( SelectedProperty . Name ) ? . GetValue ( _selectedEntity ) ;
408
+ }
409
+
410
+ if ( property == null ) return ;
411
+ _selectedEntitiesStack . Push ( new Tuple < string , object > ( SelectedEntityName , SelectedEntity ) ) ;
412
+ NavigateToProperty ( property , SelectedProperty . Name ) ;
413
+ }
414
+
415
+ public void ApplyParentProperty ( )
416
+ {
417
+ if ( _selectedEntitiesStack . Any ( ) )
418
+ {
419
+ var property = _selectedEntitiesStack . Pop ( ) ;
420
+ NavigateToProperty ( property . Item2 , property . Item1 ) ;
421
+ }
422
+ }
423
+
424
+ protected void NavigateToProperty ( object o , string entityName )
425
+ {
426
+ if ( SelectedEntity is INotifyPropertyChanged inpc1 )
427
+ {
428
+ inpc1 . PropertyChanged -= ControlPropertyChanged ;
429
+ }
430
+
431
+ if ( SelectedEntity is AvaloniaObject ao1 )
432
+ {
433
+ ao1 . PropertyChanged -= ControlPropertyChanged ;
434
+ }
435
+
436
+ SelectedEntity = o ;
437
+ SelectedEntityName = entityName ;
438
+ SelectedEntityType = o . ToString ( ) ;
439
+ var properties = GetAvaloniaProperties ( o )
440
+ . Concat ( GetClrProperties ( o ) )
441
+ . OrderBy ( x => x , PropertyComparer . Instance )
442
+ . ThenBy ( x => x . Name )
443
+ . ToList ( ) ;
444
+
445
+ _propertyIndex = properties . GroupBy ( x => x . Key ) . ToDictionary ( x => x . Key , x => x . ToList ( ) ) ;
446
+
447
+ var view = new DataGridCollectionView ( properties ) ;
448
+ view . GroupDescriptions . Add ( new DataGridPathGroupDescription ( nameof ( AvaloniaPropertyViewModel . Group ) ) ) ;
449
+ view . Filter = FilterProperty ;
450
+ PropertiesView = view ;
451
+
452
+ if ( o is INotifyPropertyChanged inpc2 )
453
+ {
454
+ inpc2 . PropertyChanged += ControlPropertyChanged ;
455
+ }
456
+
457
+ if ( o is AvaloniaObject ao2 )
458
+ {
459
+ ao2 . PropertyChanged += ControlPropertyChanged ;
460
+ }
461
+
462
+ }
381
463
}
382
464
}
0 commit comments