|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 |
|
16 |
| -using System.Collections.Generic; |
| 16 | +using ArcGIS.Desktop.Editing.Attributes; |
| 17 | +using ArcGIS.Desktop.Framework; |
17 | 18 | using ArcGIS.Desktop.Framework.Controls;
|
18 |
| -using System.Xml.Linq; |
19 |
| -using System.Windows.Controls; |
| 19 | +using ArcGIS.Desktop.Framework.Threading.Tasks; |
20 | 20 | using ArcGIS.Desktop.Mapping;
|
21 |
| -using ArcGIS.Desktop.Editing.Attributes; |
| 21 | +using System.Collections.Generic; |
| 22 | +using System.Windows.Controls; |
| 23 | +using System.Windows.Input; |
| 24 | +using System.Xml.Linq; |
22 | 25 |
|
23 | 26 | namespace InspectorTool
|
24 | 27 | {
|
25 |
| - internal class AttributeControlViewModel : EmbeddableControl |
| 28 | + internal class AttributeControlViewModel : EmbeddableControl |
| 29 | + { |
| 30 | + private EmbeddableControl _inspectorViewModel = null; |
| 31 | + private UserControl _inspectorView = null; |
| 32 | + private Dictionary<MapMember, List<long>> _selection = null; |
| 33 | + private static AttributeControlViewModel _dockpaneVM; |
| 34 | + private Inspector _featureInspector = null; |
| 35 | + |
| 36 | + public AttributeControlViewModel(XElement options, bool canChangeOptions) : base(options, canChangeOptions) |
26 | 37 | {
|
27 |
| - private EmbeddableControl _inspectorViewModel = null; |
28 |
| - private UserControl _inspectorView = null; |
29 |
| - private Dictionary<MapMember, List<long>> _selection = null; |
30 |
| - private Inspector _featureInspector = null; |
| 38 | + _dockpaneVM = this; |
31 | 39 |
|
32 |
| - public AttributeControlViewModel(XElement options, bool canChangeOptions) : base(options, canChangeOptions) |
33 |
| - { |
34 |
| - // create a new instance for the inspector |
35 |
| - _featureInspector = new Inspector(); |
36 |
| - // create an embeddable control from the inspector class to display on the pane |
37 |
| - var icontrol = _featureInspector.CreateEmbeddableControl(); |
38 |
| - |
39 |
| - // get view and viewmodel from the inspector |
40 |
| - InspectorViewModel = icontrol.Item1; |
41 |
| - InspectorView = icontrol.Item2; |
42 |
| - } |
| 40 | + // create an inspector instance to support editing events |
| 41 | + _dockpaneVM.AttributeInspector = new Inspector(); |
| 42 | + // create an embeddable control from the inspector class to display on the pane |
| 43 | + var icontrol = AttributeInspector.CreateEmbeddableControl(); |
43 | 44 |
|
44 |
| - /// <summary> |
45 |
| - /// Property containing an instance for the inspector. |
46 |
| - /// </summary> |
47 |
| - public Inspector AttributeInspector |
48 |
| - { |
49 |
| - get |
50 |
| - { |
51 |
| - return _featureInspector; |
52 |
| - } |
53 |
| - } |
| 45 | + // get view and viewmodel from the inspector |
| 46 | + InspectorViewModel = icontrol.Item1; |
| 47 | + InspectorView = icontrol.Item2; |
54 | 48 |
|
55 |
| - /// <summary> |
56 |
| - /// Access to the view model of the inspector |
57 |
| - /// </summary> |
58 |
| - public EmbeddableControl InspectorViewModel |
59 |
| - { |
60 |
| - get { return _inspectorViewModel; } |
61 |
| - set |
62 |
| - { |
63 |
| - if (value != null) |
64 |
| - { |
65 |
| - _inspectorViewModel = value; |
66 |
| - _inspectorViewModel.OpenAsync(); |
67 |
| - |
68 |
| - } |
69 |
| - else if (_inspectorViewModel != null) |
70 |
| - { |
71 |
| - _inspectorViewModel.CloseAsync(); |
72 |
| - _inspectorViewModel = value; |
73 |
| - } |
74 |
| - NotifyPropertyChanged(() => InspectorViewModel); |
75 |
| - } |
76 |
| - } |
| 49 | + // Listen for editing changes |
| 50 | + _dockpaneVM.AttributeInspector.PropertyChanged += InspectorViewModel_PropertyChanged; |
| 51 | + } |
77 | 52 |
|
78 |
| - /// <summary> |
79 |
| - /// Dictionary holding the selected features in the map to populate the tree view for |
80 |
| - /// layers and respective selected features. |
81 |
| - /// </summary> |
82 |
| - public Dictionary<MapMember, List<long>> SelectedMapFeatures |
| 53 | + private void InspectorViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) |
| 54 | + { |
| 55 | + // Did something change? |
| 56 | + if (e.PropertyName == "IsDirty") |
| 57 | + { |
| 58 | + // IsDirty has been updated, update the buttons (UI) accordingly |
| 59 | + _dockpaneVM.NotifyPropertyChanged(nameof(IsApplyEnabled)); |
| 60 | + _dockpaneVM.NotifyPropertyChanged(nameof(IsCancelEnabled)); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Property containing an instance for the inspector. |
| 66 | + /// </summary> |
| 67 | + internal Inspector AttributeInspector { get; private set; } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Access to the view model of the inspector |
| 71 | + /// </summary> |
| 72 | + public EmbeddableControl InspectorViewModel |
| 73 | + { |
| 74 | + get { return _inspectorViewModel; } |
| 75 | + set |
| 76 | + { |
| 77 | + if (value != null) |
83 | 78 | {
|
84 |
| - get |
85 |
| - { |
86 |
| - return _selection; |
87 |
| - } |
88 |
| - set |
89 |
| - { |
90 |
| - SetProperty(ref _selection, value, () => SelectedMapFeatures); |
91 |
| - } |
92 |
| - } |
| 79 | + _inspectorViewModel = value; |
| 80 | + _inspectorViewModel.OpenAsync(); |
93 | 81 |
|
94 |
| - /// <summary> |
95 |
| - /// Property for the inspector UI. |
96 |
| - /// </summary> |
97 |
| - public UserControl InspectorView |
| 82 | + } |
| 83 | + else if (_inspectorViewModel != null) |
98 | 84 | {
|
99 |
| - get { return _inspectorView; } |
100 |
| - set { SetProperty(ref _inspectorView, value, () => InspectorView); } |
| 85 | + _inspectorViewModel.CloseAsync(); |
| 86 | + _inspectorViewModel = value; |
101 | 87 | }
|
| 88 | + NotifyPropertyChanged(() => InspectorViewModel); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + /// <summary> |
| 93 | + /// Dictionary holding the selected features in the map to populate the tree view for |
| 94 | + /// layers and respective selected features. |
| 95 | + /// </summary> |
| 96 | + public Dictionary<MapMember, List<long>> SelectedMapFeatures |
| 97 | + { |
| 98 | + get => _selection; |
| 99 | + set => SetProperty(ref _selection, value); |
102 | 100 | }
|
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Property for the inspector UI. |
| 104 | + /// </summary> |
| 105 | + public UserControl InspectorView |
| 106 | + { |
| 107 | + get { return _inspectorView; } |
| 108 | + set { SetProperty(ref _inspectorView, value); } |
| 109 | + } |
| 110 | + public bool IsApplyEnabled => AttributeInspector?.IsDirty ?? false; |
| 111 | + public bool IsCancelEnabled => AttributeInspector?.IsDirty ?? false; |
| 112 | + |
| 113 | + public ICommand CancelCommand |
| 114 | + { |
| 115 | + get => new RelayCommand(() => AttributeInspector?.Cancel()); |
| 116 | + } |
| 117 | + |
| 118 | + public ICommand ApplyCommand |
| 119 | + { |
| 120 | + get => new RelayCommand(() => |
| 121 | + { |
| 122 | + QueuedTask.Run(() => |
| 123 | + { |
| 124 | + //Apply the attribute changes. |
| 125 | + //Writing them back to the database in an Edit Operation. |
| 126 | + AttributeInspector?.Apply(); |
| 127 | + }); |
| 128 | + }); |
| 129 | + } |
| 130 | + } |
103 | 131 | }
|
0 commit comments