|
1 using System; |
|
2 using System.Net; |
|
3 using System.Windows; |
|
4 using System.Windows.Controls; |
|
5 using System.Windows.Documents; |
|
6 using System.Windows.Ink; |
|
7 using System.Windows.Input; |
|
8 using System.Windows.Media; |
|
9 using System.Windows.Media.Animation; |
|
10 using System.Windows.Shapes; |
|
11 using System.Windows.Data; |
|
12 using SLExtensions.Input; |
|
13 using Iri.Modernisation.BaseMVVM.Commands; |
|
14 using Iri.Modernisation.Data.Models; |
|
15 using System.Collections.Generic; |
|
16 using System.Linq; |
|
17 using Iri.Modernisation.Controls.View; |
|
18 namespace Iri.Modernisation.Controls.ViewModel |
|
19 { |
|
20 |
|
21 /// <summary> |
|
22 /// ViewModel du module d'annotation |
|
23 /// </summary> |
|
24 public class AnnotationMakerVM : BaseMVVM.ViewModel.ViewModel |
|
25 { |
|
26 /// <summary> |
|
27 /// Element référent |
|
28 /// </summary> |
|
29 private PolemicElement _refElement; |
|
30 public PolemicElement RefElement |
|
31 { |
|
32 get |
|
33 { |
|
34 return _refElement; |
|
35 } |
|
36 set |
|
37 { |
|
38 _refElement = value; |
|
39 |
|
40 _newAnnotation = new Annotation(((PolemicElement)value).Chapter); |
|
41 Begin = ((PolemicElement)value).TimerIn.TotalMilliseconds; |
|
42 End = ((PolemicElement)value).TimerOut.TotalMilliseconds; |
|
43 BasicRelation = new PolemicLink() { FromElement = ((PolemicElement)value), ToElement = _newAnnotation, Type = PolemicElementType.Basic }; |
|
44 PolemicRelation = new PolemicLink(); |
|
45 PolemicRelation.FromElement = _newAnnotation; |
|
46 |
|
47 OnPropertyChanged(String.Empty); |
|
48 //OnPropertyChanged("RefElement"); |
|
49 //OnPropertyChanged("IsControlEnable"); |
|
50 |
|
51 } |
|
52 } |
|
53 |
|
54 /// <summary> |
|
55 /// Savoir si le module de liens est activé |
|
56 /// </summary> |
|
57 public bool IsBinderActive { get; set; } |
|
58 public List<String> RefTags |
|
59 { |
|
60 get |
|
61 { |
|
62 if (_refElement != null) |
|
63 { |
|
64 return _refElement.Tags; |
|
65 } |
|
66 else |
|
67 { |
|
68 return new List<String>(); |
|
69 } |
|
70 } |
|
71 } |
|
72 |
|
73 /// <summary> |
|
74 /// Annotation créé |
|
75 /// </summary> |
|
76 private Annotation _newAnnotation; |
|
77 |
|
78 /// <summary> |
|
79 /// Temps de début de l'annotation |
|
80 /// </summary> |
|
81 private TimeSpan _begin; |
|
82 public double Begin |
|
83 { |
|
84 get |
|
85 { |
|
86 return _begin.TotalMilliseconds; |
|
87 } |
|
88 set |
|
89 { |
|
90 _begin = TimeSpan.FromMilliseconds(value); |
|
91 _newAnnotation.TimerIn = TimeSpan.FromMilliseconds(value); |
|
92 OnPropertyChanged("Begin"); |
|
93 } |
|
94 } |
|
95 |
|
96 /// <summary> |
|
97 /// Temps de fin de l'annotation |
|
98 /// </summary> |
|
99 private TimeSpan _end; |
|
100 public double End |
|
101 { |
|
102 get |
|
103 { |
|
104 return _end.TotalMilliseconds; |
|
105 } |
|
106 set |
|
107 { |
|
108 _end = TimeSpan.FromMilliseconds(value); |
|
109 _newAnnotation.TimerOut = TimeSpan.FromMilliseconds(value); |
|
110 OnPropertyChanged("End"); |
|
111 } |
|
112 } |
|
113 |
|
114 /// <summary> |
|
115 /// Type de l'annotation |
|
116 /// </summary> |
|
117 private PolemicElementType _type; |
|
118 public PolemicElementType Type |
|
119 { |
|
120 get |
|
121 { |
|
122 return _type; |
|
123 } |
|
124 set |
|
125 { |
|
126 _type = value; |
|
127 _newAnnotation.Type = value; |
|
128 OnPropertyChanged("Type"); |
|
129 } |
|
130 } |
|
131 |
|
132 /// <summary> |
|
133 /// Convertion Rectange |
|
134 /// </summary> |
|
135 private Rectangle _selectedType; |
|
136 public Rectangle SelectedType |
|
137 { |
|
138 get |
|
139 { |
|
140 return _selectedType; |
|
141 } |
|
142 set |
|
143 { |
|
144 _selectedType = value; |
|
145 |
|
146 Type = (PolemicElementType)((Rectangle)_selectedType).Resources["PolemicType"]; |
|
147 } |
|
148 } |
|
149 |
|
150 /// <summary> |
|
151 /// Titre de l'annotation |
|
152 /// </summary> |
|
153 private String _title; |
|
154 public String Title |
|
155 { |
|
156 get |
|
157 { return _title; } |
|
158 set |
|
159 { |
|
160 _title = value; |
|
161 _newAnnotation.Title = value; |
|
162 OnPropertyChanged("Title"); |
|
163 } |
|
164 } |
|
165 |
|
166 /// <summary> |
|
167 /// Description de l'annotation |
|
168 /// </summary> |
|
169 private String _description; |
|
170 public String Description |
|
171 { |
|
172 get |
|
173 { |
|
174 return _description; |
|
175 } |
|
176 set |
|
177 { |
|
178 _description = value; |
|
179 _newAnnotation.Description = value; |
|
180 OnPropertyChanged("Description"); |
|
181 } |
|
182 |
|
183 } |
|
184 |
|
185 /// <summary> |
|
186 /// Tags de l'annotation |
|
187 /// </summary> |
|
188 public List<String> _tags =new List<String>(); |
|
189 public String Tags |
|
190 { |
|
191 get |
|
192 { |
|
193 try |
|
194 { |
|
195 return String.Join(",", _tags.ToArray()); |
|
196 } |
|
197 catch |
|
198 { |
|
199 return String.Empty; |
|
200 } |
|
201 } |
|
202 set |
|
203 { |
|
204 String val = (String)value; |
|
205 _tags = val.Split(',').ToList(); |
|
206 _newAnnotation.Tags = val.Split(',').ToList(); |
|
207 OnPropertyChanged("Tags"); |
|
208 |
|
209 |
|
210 } |
|
211 } |
|
212 |
|
213 /// <summary> |
|
214 /// Relation basique |
|
215 /// </summary> |
|
216 private PolemicLink _basicRelation; |
|
217 public PolemicLink BasicRelation |
|
218 { |
|
219 get |
|
220 { |
|
221 return _basicRelation; |
|
222 } |
|
223 set |
|
224 { |
|
225 _basicRelation = value; |
|
226 OnPropertyChanged("BasicRelation"); |
|
227 } |
|
228 |
|
229 |
|
230 } |
|
231 |
|
232 /// <summary> |
|
233 /// Relation polémique |
|
234 /// </summary> |
|
235 private PolemicLink _polemicRelation; |
|
236 public PolemicLink PolemicRelation |
|
237 { |
|
238 get |
|
239 { |
|
240 |
|
241 return _polemicRelation; |
|
242 } |
|
243 set |
|
244 { |
|
245 _polemicRelation = value; |
|
246 OnPropertyChanged("PolemicRelation"); |
|
247 } |
|
248 |
|
249 |
|
250 } |
|
251 |
|
252 /// <summary> |
|
253 /// Détermine si le control est activé ou non |
|
254 /// </summary> |
|
255 public bool IsControlEnable |
|
256 { |
|
257 get |
|
258 { |
|
259 return _refElement != null; |
|
260 } |
|
261 } |
|
262 |
|
263 /// <summary> |
|
264 /// Permet d'initialiser les commands; |
|
265 /// </summary> |
|
266 private void InitializeCommands() |
|
267 { |
|
268 Commands.ContextualBinderLayer.BeginBind.Executed += new EventHandler<ExecutedEventArgs>(BeginBind_Executed); |
|
269 Commands.ContextualBinderLayer.SelectBind.Executed += new EventHandler<ExecutedEventArgs>(SelectBind_Executed); |
|
270 Commands.ContextualBinderLayer.ActiveBind.Executed += new EventHandler<ExecutedEventArgs>(ActiveBind_Executed); |
|
271 Commands.ContextualBinderLayer.DesactiveBind.Executed += new EventHandler<ExecutedEventArgs>(DesactiveBind_Executed); |
|
272 Commands.AnnotationMaker.OkClick.Executed += new EventHandler<ExecutedEventArgs>(OkClickAnnotationMaker_Executed); |
|
273 } |
|
274 |
|
275 void DesactiveBind_Executed(object sender, ExecutedEventArgs e) |
|
276 { |
|
277 IsBinderActive = false; |
|
278 } |
|
279 |
|
280 void ActiveBind_Executed(object sender, ExecutedEventArgs e) |
|
281 { |
|
282 IsBinderActive = true; |
|
283 } |
|
284 |
|
285 |
|
286 |
|
287 void SelectBind_Executed(object sender, ExecutedEventArgs e) |
|
288 { |
|
289 if (IsControlEnable && IsBinderActive ) |
|
290 { |
|
291 PolemicRelation.ToElement = (PolemicElement)e.Source; |
|
292 OnPropertyChanged("PolemicRelation"); |
|
293 } |
|
294 |
|
295 } |
|
296 |
|
297 void BeginBind_Executed(object sender, ExecutedEventArgs e) |
|
298 { |
|
299 if (IsControlEnable) |
|
300 { |
|
301 PolemicRelation.Type = ((ContextualLinkBinder)e.Parameter).PolemicType; |
|
302 PolemicRelation.ToElement = null; |
|
303 OnPropertyChanged("PolemicRelation"); |
|
304 |
|
305 } |
|
306 |
|
307 } |
|
308 |
|
309 |
|
310 |
|
311 void OkClickAnnotationMaker_Executed(object sender, ExecutedEventArgs e) |
|
312 { |
|
313 String message = "Ok clicked "+Type+" \n"; |
|
314 message += _begin + "-->" + _end; |
|
315 message += "\n" + Title; |
|
316 message += "\n" + Description; |
|
317 |
|
318 foreach (string tag in _tags) |
|
319 { |
|
320 message += "\n|-" + tag; |
|
321 } |
|
322 |
|
323 message += "PolemicLink "+PolemicRelation.Type; |
|
324 MessageBox.Show(message); |
|
325 } |
|
326 |
|
327 /// <summary> |
|
328 /// Constructeur par défaut |
|
329 /// </summary> |
|
330 public AnnotationMakerVM() |
|
331 { |
|
332 |
|
333 InitializeCommands(); |
|
334 |
|
335 } |
|
336 |
|
337 /// <summary> |
|
338 /// Constructeur par référence |
|
339 /// </summary> |
|
340 /// <param name="refAParam">Element référant</param> |
|
341 public AnnotationMakerVM(PolemicElement refAParam) |
|
342 { |
|
343 |
|
344 |
|
345 RefElement = refAParam; |
|
346 |
|
347 |
|
348 |
|
349 _newAnnotation = new Annotation(RefElement.Chapter); |
|
350 _begin = RefElement.TimerIn; |
|
351 _end = RefElement.TimerOut; |
|
352 _basicRelation = new PolemicLink() { FromElement = RefElement, ToElement = _newAnnotation, Type = PolemicElementType.Basic }; |
|
353 _polemicRelation = new PolemicLink(); |
|
354 PolemicRelation.FromElement = _newAnnotation; |
|
355 InitializeCommands(); |
|
356 } |
|
357 |
|
358 |
|
359 } |
|
360 |
|
361 } |