Mercurial > silverbladetech
comparison Chronosv2/source/Presentation/ViewModel/ShortcutViewModel.cs @ 10:443821e55f06
Initial cleaned up add from Codeplex files
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Tue, 21 Feb 2012 17:25:44 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:904a9faadf8b | 10:443821e55f06 |
---|---|
1 /* | |
2 The MIT License | |
3 | |
4 Copyright (c) 2009-2010. Carlos Guzmán Álvarez. http://chronoswpf.codeplex.com/ | |
5 | |
6 Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 of this software and associated documentation files (the "Software"), to deal | |
8 in the Software without restriction, including without limitation the rights | |
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 copies of the Software, and to permit persons to whom the Software is | |
11 furnished to do so, subject to the following conditions: | |
12 | |
13 The above copyright notice and this permission notice shall be included in | |
14 all copies or substantial portions of the Software. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 THE SOFTWARE. | |
23 */ | |
24 | |
25 using System; | |
26 using System.ComponentModel; | |
27 using Chronos.Presentation.Core.Services; | |
28 using Chronos.Presentation.Core.ViewModel; | |
29 using Chronos.Presentation.Core.Windows; | |
30 using NLog; | |
31 using nRoute.Components; | |
32 | |
33 namespace Chronos.Presentation.ViewModel | |
34 { | |
35 /// <summary> | |
36 /// Base class for shortcut viewmodel implementations | |
37 /// </summary> | |
38 public abstract class ShortcutViewModel | |
39 : ClosableViewModel, IShortcutViewModel | |
40 { | |
41 #region · NotifyPropertyChanged Cached Instances · | |
42 | |
43 private static readonly PropertyChangedEventArgs IconStyleChangedArgs = CreateArgs<ShortcutViewModel>(x => x.IconStyle); | |
44 private static readonly PropertyChangedEventArgs TargetChangedArgs = CreateArgs<ShortcutViewModel>(x => x.Target); | |
45 private static readonly PropertyChangedEventArgs ParametersChangedArgs = CreateArgs<ShortcutViewModel>(x => x.Parameters); | |
46 | |
47 #endregion | |
48 | |
49 #region · Logger · | |
50 | |
51 private static Logger Logger = LogManager.GetCurrentClassLogger(); | |
52 | |
53 #endregion | |
54 | |
55 #region · Fields · | |
56 | |
57 private string target; | |
58 private string parameters; | |
59 private string iconStyle; | |
60 | |
61 #region · Commands · | |
62 | |
63 private ActionCommand openCommand; | |
64 | |
65 #endregion | |
66 | |
67 #endregion | |
68 | |
69 #region · Commands · | |
70 | |
71 /// <summary> | |
72 /// Gets the open command. | |
73 /// </summary> | |
74 /// <value>The open command.</value> | |
75 public ActionCommand OpenCommand | |
76 { | |
77 get | |
78 { | |
79 if (this.openCommand == null) | |
80 { | |
81 this.openCommand = new ActionCommand(() => OnOpen()); | |
82 } | |
83 | |
84 return this.openCommand; | |
85 } | |
86 } | |
87 | |
88 #endregion | |
89 | |
90 #region · Properties · | |
91 | |
92 /// <summary> | |
93 /// Gets or sets the icon style. | |
94 /// </summary> | |
95 /// <value>The icon style.</value> | |
96 public virtual string IconStyle | |
97 { | |
98 get { return this.iconStyle; } | |
99 set | |
100 { | |
101 if (this.iconStyle != value) | |
102 { | |
103 this.iconStyle = value; | |
104 this.NotifyPropertyChanged(IconStyleChangedArgs); | |
105 } | |
106 } | |
107 } | |
108 | |
109 /// <summary> | |
110 /// Gets or sets the shortcut target. | |
111 /// </summary> | |
112 /// <value>The shortcut target.</value> | |
113 public virtual string Target | |
114 { | |
115 get { return this.target; } | |
116 set | |
117 { | |
118 if (this.target != value) | |
119 { | |
120 this.target = value; | |
121 this.NotifyPropertyChanged(TargetChangedArgs); | |
122 } | |
123 } | |
124 } | |
125 | |
126 /// <summary> | |
127 /// Gets or sets the shortcut navigation parameters | |
128 /// </summary> | |
129 public virtual string Parameters | |
130 { | |
131 get { return this.parameters; } | |
132 set | |
133 { | |
134 if (this.parameters != value) | |
135 { | |
136 this.parameters = value; | |
137 this.NotifyPropertyChanged(ParametersChangedArgs); | |
138 } | |
139 } | |
140 } | |
141 | |
142 #endregion | |
143 | |
144 #region · Constructors · | |
145 | |
146 /// <summary> | |
147 /// Initializes a new instance of the <see cref="ShortcutViewModel"/> class. | |
148 /// </summary> | |
149 protected ShortcutViewModel() | |
150 : base() | |
151 { | |
152 } | |
153 | |
154 #endregion | |
155 | |
156 #region · Command Actions · | |
157 | |
158 /// <summary> | |
159 /// Called when the <see cref="OpenCommand"/> is executed. | |
160 /// </summary> | |
161 protected abstract void OnOpen(); | |
162 | |
163 #endregion | |
164 | |
165 #region · Overriden Methods · | |
166 | |
167 /// <summary> | |
168 /// Determines whether the view related to this view model can be closed. | |
169 /// </summary> | |
170 /// <returns> | |
171 /// <c>true</c> if the related view can be closed; otherwise, <c>false</c>. | |
172 /// </returns> | |
173 public override bool CanClose() | |
174 { | |
175 return true; | |
176 } | |
177 | |
178 /// <summary> | |
179 /// Called when the related view is being closed. | |
180 /// </summary> | |
181 public override void Close() | |
182 { | |
183 IShowMessageViewService showMessageService = this.GetViewService<IShowMessageViewService>(); | |
184 | |
185 showMessageService.ButtonSetup = DialogButton.YesNo; | |
186 showMessageService.Caption = "Eliminar acceso directo"; | |
187 showMessageService.Text = | |
188 String.Format( | |
189 "¿Está seguro de que desea eliminar permanentemente este acceso directo? {0}{1}", | |
190 Environment.NewLine, | |
191 this.Title); | |
192 | |
193 if (showMessageService.ShowMessage() == DialogResult.Yes) | |
194 { | |
195 Logger.Debug("Eliminando acceso directo '{0}'", this.Target); | |
196 | |
197 base.Close(); | |
198 | |
199 this.target = null; | |
200 this.parameters = null; | |
201 this.iconStyle = null; | |
202 this.openCommand = null; | |
203 } | |
204 } | |
205 | |
206 #endregion | |
207 } | |
208 } |