diff options
Diffstat (limited to 'src/WixToolset.WixBA/RootViewModel.cs')
-rw-r--r-- | src/WixToolset.WixBA/RootViewModel.cs | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/src/WixToolset.WixBA/RootViewModel.cs b/src/WixToolset.WixBA/RootViewModel.cs new file mode 100644 index 00000000..1de89adf --- /dev/null +++ b/src/WixToolset.WixBA/RootViewModel.cs | |||
@@ -0,0 +1,204 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.UX | ||
4 | { | ||
5 | using System; | ||
6 | using System.Diagnostics; | ||
7 | using System.Reflection; | ||
8 | using System.Windows; | ||
9 | using System.Windows.Input; | ||
10 | using System.Windows.Threading; | ||
11 | using WixToolset.Bootstrapper; | ||
12 | |||
13 | /// <summary> | ||
14 | /// The errors returned from the engine | ||
15 | /// </summary> | ||
16 | public enum Error | ||
17 | { | ||
18 | UserCancelled = 1223, | ||
19 | } | ||
20 | |||
21 | /// <summary> | ||
22 | /// The model of the root view in WixBA. | ||
23 | /// </summary> | ||
24 | public class RootViewModel : PropertyNotifyBase | ||
25 | { | ||
26 | private ICommand cancelCommand; | ||
27 | private ICommand closeCommand; | ||
28 | |||
29 | private bool canceled; | ||
30 | private InstallationState installState; | ||
31 | private DetectionState detectState; | ||
32 | |||
33 | /// <summary> | ||
34 | /// Creates a new model of the root view. | ||
35 | /// </summary> | ||
36 | public RootViewModel() | ||
37 | { | ||
38 | this.InstallationViewModel = new InstallationViewModel(this); | ||
39 | this.ProgressViewModel = new ProgressViewModel(this); | ||
40 | this.UpdateViewModel = new UpdateViewModel(this); | ||
41 | } | ||
42 | |||
43 | public InstallationViewModel InstallationViewModel { get; private set; } | ||
44 | public ProgressViewModel ProgressViewModel { get; private set; } | ||
45 | public UpdateViewModel UpdateViewModel { get; private set; } | ||
46 | public Dispatcher Dispatcher { get; set; } | ||
47 | public IntPtr ViewWindowHandle { get; set; } | ||
48 | public bool AutoClose { get; set; } | ||
49 | |||
50 | public ICommand CloseCommand | ||
51 | { | ||
52 | get | ||
53 | { | ||
54 | if (this.closeCommand == null) | ||
55 | { | ||
56 | this.closeCommand = new RelayCommand(param => WixBA.View.Close()); | ||
57 | } | ||
58 | |||
59 | return this.closeCommand; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | public ICommand CancelCommand | ||
64 | { | ||
65 | get | ||
66 | { | ||
67 | if (this.cancelCommand == null) | ||
68 | { | ||
69 | this.cancelCommand = new RelayCommand(param => | ||
70 | { | ||
71 | this.CancelButton_Click(); | ||
72 | }, | ||
73 | param => !this.Canceled); | ||
74 | } | ||
75 | |||
76 | return this.cancelCommand; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | public bool CancelAvailable | ||
81 | { | ||
82 | get { return InstallationState.Applying == this.InstallState; } | ||
83 | } | ||
84 | |||
85 | public bool Canceled | ||
86 | { | ||
87 | get | ||
88 | { | ||
89 | return this.canceled; | ||
90 | } | ||
91 | |||
92 | set | ||
93 | { | ||
94 | if (this.canceled != value) | ||
95 | { | ||
96 | this.canceled = value; | ||
97 | base.OnPropertyChanged("Canceled"); | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | /// <summary> | ||
103 | /// Gets and sets the detect state of the view's model. | ||
104 | /// </summary> | ||
105 | public DetectionState DetectState | ||
106 | { | ||
107 | get | ||
108 | { | ||
109 | return this.detectState; | ||
110 | } | ||
111 | |||
112 | set | ||
113 | { | ||
114 | if (this.detectState != value) | ||
115 | { | ||
116 | this.detectState = value; | ||
117 | |||
118 | // Notify all the properties derived from the state that the state changed. | ||
119 | base.OnPropertyChanged("DetectState"); | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | /// <summary> | ||
125 | /// Gets and sets the installation state of the view's model. | ||
126 | /// </summary> | ||
127 | public InstallationState InstallState | ||
128 | { | ||
129 | get | ||
130 | { | ||
131 | return this.installState; | ||
132 | } | ||
133 | |||
134 | set | ||
135 | { | ||
136 | if (this.installState != value) | ||
137 | { | ||
138 | this.installState = value; | ||
139 | |||
140 | // Notify all the properties derived from the state that the state changed. | ||
141 | base.OnPropertyChanged("InstallState"); | ||
142 | base.OnPropertyChanged("CancelAvailable"); | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
147 | /// <summary> | ||
148 | /// Gets and sets the state of the view's model before apply begins in order to return to that state if cancel or rollback occurs. | ||
149 | /// </summary> | ||
150 | public InstallationState PreApplyState { get; set; } | ||
151 | |||
152 | /// <summary> | ||
153 | /// Gets and sets the path where the bundle is currently installed or will be installed. | ||
154 | /// </summary> | ||
155 | public string InstallDirectory | ||
156 | { | ||
157 | get | ||
158 | { | ||
159 | return WixBA.Model.InstallDirectory; | ||
160 | } | ||
161 | |||
162 | set | ||
163 | { | ||
164 | if (WixBA.Model.InstallDirectory != value) | ||
165 | { | ||
166 | WixBA.Model.InstallDirectory = value; | ||
167 | base.OnPropertyChanged("InstallDirectory"); | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /// <summary> | ||
173 | /// The Title of this bundle. | ||
174 | /// </summary> | ||
175 | public string Title | ||
176 | { | ||
177 | get | ||
178 | { | ||
179 | return WixDistribution.ShortProduct; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// Prompts the user to make sure they want to cancel. | ||
185 | /// This needs to run on the UI thread, use Dispatcher.Invoke to call this from a background thread. | ||
186 | /// </summary> | ||
187 | public void CancelButton_Click() | ||
188 | { | ||
189 | if (this.Canceled) | ||
190 | { | ||
191 | return; | ||
192 | } | ||
193 | |||
194 | if (Display.Full == WixBA.Model.Command.Display) | ||
195 | { | ||
196 | this.Canceled = (MessageBoxResult.Yes == MessageBox.Show(WixBA.View, "Are you sure you want to cancel?", "WiX Toolset", MessageBoxButton.YesNo, MessageBoxImage.Error)); | ||
197 | } | ||
198 | else | ||
199 | { | ||
200 | this.Canceled = true; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | } | ||