| author | totetm <> |
| Thu, 11 Feb 2010 17:29:23 +0100 | |
| changeset 42 | 594fdedecf7f |
| parent 41 | b51a10574e7f |
| child 46 | ab3057b82260 |
| permissions | -rw-r--r-- |
| 0 | 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.Collections.Generic; |
|
12 |
using Iri.Modernisation.Data.Models; |
|
13 |
using Iri.Modernisation.Data.LDTClass; |
|
14 |
using Iri.Modernisation.BaseMVVM.Commands; |
|
15 |
using Iri.Modernisation.BaseMVVM.ViewModel; |
|
| 25 | 16 |
using System.Collections.ObjectModel; |
| 0 | 17 |
namespace Iri.Modernisation.Controls.ViewModel |
18 |
{ |
|
| 25 | 19 |
/// <summary> |
20 |
/// ViewModel de ConsultationView |
|
21 |
/// </summary> |
|
| 0 | 22 |
public class ConsultationViewVM : BaseMVVM.ViewModel.ViewModel |
23 |
{ |
|
| 35 | 24 |
|
| 0 | 25 |
private PolemicElement _selectedElement; |
| 25 | 26 |
/// <summary> |
27 |
/// PolemicElement sélectionné |
|
28 |
/// </summary> |
|
| 0 | 29 |
public PolemicElement SelectedElement |
30 |
{ |
|
31 |
get |
|
32 |
{ |
|
33 |
return _selectedElement; |
|
34 |
} |
|
35 |
set |
|
36 |
{ |
|
37 |
_selectedElement = value; |
|
38 |
OnPropertyChanged("SelectedElement"); |
|
39 |
} |
|
40 |
} |
|
41 |
||
| 25 | 42 |
private ObservableCollection<BookTimeLineVM> _selectedVideoBooks; |
43 |
/// <summary> |
|
44 |
/// Liste des Livres Sélectionnés |
|
45 |
/// </summary> |
|
46 |
public ObservableCollection<BookTimeLineVM> SelectedVideoBooks |
|
| 0 | 47 |
{ |
48 |
get |
|
49 |
{ |
|
50 |
||
51 |
return _selectedVideoBooks; |
|
52 |
} |
|
53 |
set |
|
54 |
{ |
|
55 |
_selectedVideoBooks = value; |
|
56 |
OnPropertyChanged("SelectedVideoBooks"); |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
private int _selectedVideoBookIndex=-1; |
|
| 25 | 61 |
/// <summary> |
62 |
/// Index du livre sélectionné |
|
63 |
/// </summary> |
|
| 0 | 64 |
public int SelectedVideoBookIndex |
65 |
{ |
|
66 |
get |
|
67 |
{ |
|
68 |
return _selectedVideoBookIndex; |
|
69 |
} |
|
70 |
set |
|
71 |
{ |
|
72 |
_selectedVideoBookIndex= value; |
|
73 |
OnPropertyChanged("SelectedVideoBookIndex"); |
|
| 42 | 74 |
if (_selectedVideoBooks.Count > value && value >= 0) |
75 |
{ |
|
76 |
ConsultationBookViewContextMenu.SelectedBookVM = (_selectedVideoBooks[value]); |
|
77 |
} |
|
78 |
else |
|
79 |
{ |
|
80 |
ConsultationBookViewContextMenu.SelectedBookVM = null; |
|
81 |
} |
|
| 0 | 82 |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
private ConsultationBookViewVM _consultationBookViewContextMenu; |
|
| 25 | 87 |
/// <summary> |
88 |
/// ViewModel de ConsultationBook |
|
89 |
/// </summary> |
|
| 0 | 90 |
public ConsultationBookViewVM ConsultationBookViewContextMenu |
91 |
{ |
|
92 |
get |
|
93 |
{ |
|
94 |
return _consultationBookViewContextMenu; |
|
95 |
} |
|
96 |
set |
|
97 |
{ |
|
98 |
_consultationBookViewContextMenu = value; |
|
99 |
OnPropertyChanged(null); |
|
100 |
} |
|
101 |
} |
|
| 35 | 102 |
/// <summary> |
103 |
/// Loader pour chargement à la volée des VideoLivres selectionnés |
|
104 |
/// </summary> |
|
| 38 | 105 |
//private Loader<VideoBook> _loaderVideoBook { get; set; } |
106 |
private VideoBookLoader _loaderVideoBook { get; set; } |
|
| 0 | 107 |
private AnnotationMakerVM _annotationMakerVM; |
| 25 | 108 |
/// <summary> |
109 |
/// ViewModel de AnnotationMaker |
|
110 |
/// </summary> |
|
| 0 | 111 |
public AnnotationMakerVM ViewModelAnnotationMaker |
112 |
{ |
|
113 |
get |
|
114 |
{ |
|
115 |
return _annotationMakerVM; |
|
116 |
} |
|
| 30 | 117 |
set |
118 |
{ |
|
119 |
_annotationMakerVM = value; |
|
120 |
OnPropertyChanged("ViewModelAnnotationMaker"); |
|
121 |
} |
|
| 0 | 122 |
} |
| 35 | 123 |
|
124 |
private void InitializeCommands() |
|
125 |
{ |
|
| 38 | 126 |
Commands.ClickMenu.CreateNewTextualAnnotation.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(CreateNewTextualAnnotation_Executed); |
| 35 | 127 |
Commands.ConsultMenu.ClickBook.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(ClickBook_Executed); |
128 |
Commands.PolemicElement.SelectPolemicElement.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(SelectPolemicElement_Executed); |
|
| 38 | 129 |
Commands.AnnotationMaker.NewAnnotationFinished.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(NewAnnotationFinished_Executed); |
|
41
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
130 |
Commands.BookTimeLine.LeftClickOnElement.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(LeftClickOnElement_Executed); |
| 42 | 131 |
Commands.BookTimeLine.CloseBookTimeLine.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(CloseBookTimeLine_Executed); |
132 |
} |
|
133 |
||
134 |
void CloseBookTimeLine_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
135 |
{ |
|
136 |
SelectedVideoBooks.Remove((BookTimeLineVM)e.Parameter); |
|
137 |
BookDeleted(this,new ConsultationVieVMSelectBookArg(((BookTimeLineVM)e.Parameter).SelectedBook)); |
|
|
41
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
138 |
} |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
139 |
|
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
140 |
void LeftClickOnElement_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
141 |
{ |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
142 |
TimeSpan TimeToGo = (TimeSpan)e.Parameter; |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
143 |
PolemicElementVM ClickedElement = (PolemicElementVM)e.Source; |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
144 |
if(ConsultationBookViewContextMenu.SelectedBook == ClickedElement.Chapter.Book) |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
145 |
{ |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
146 |
ConsultationBookViewContextMenu.ActualVideoSourceVM.GoTo(TimeToGo); |
|
b51a10574e7f
LeftClick on an element in BookTimeLine set time at begining of the element.
totetm <>
parents:
39
diff
changeset
|
147 |
} |
| 38 | 148 |
} |
149 |
||
150 |
void NewAnnotationFinished_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
151 |
{ |
|
152 |
Annotation createdAnnotation = ((Annotation)e.Parameter); |
|
153 |
PolemicElement refElement = ((PolemicElement)e.Source); |
|
| 39 | 154 |
// refElement.Chapter.Annotations.Add(createdAnnotation); |
| 38 | 155 |
//refElement.Chapter.Book.Save(); |
156 |
||
157 |
|
|
| 35 | 158 |
} |
| 42 | 159 |
|
160 |
List<String> InDownloadFile { get; set; } |
|
161 |
||
| 35 | 162 |
/// <summary> |
163 |
/// Evenement lors d'un click sur un livre de la liste |
|
164 |
/// </summary> |
|
165 |
/// <param name="sender"></param> |
|
166 |
/// <param name="e"></param> |
|
167 |
private void ClickBook_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
168 |
{ |
|
169 |
||
170 |
bool CanAdd = true; |
|
| 42 | 171 |
VideoBook clickedVideoBook = ((VideoBook)e.Parameter); |
| 35 | 172 |
//On regarde si le VideoLivre qu'on à choisis n'est pas déjà dans la liste des VideoLivres sélectionné |
173 |
foreach (BookTimeLineVM BookTLVM in SelectedVideoBooks) |
|
174 |
{ |
|
| 42 | 175 |
if (BookTLVM.SelectedBook.LdtPath == clickedVideoBook.LdtPath) |
| 35 | 176 |
{ |
177 |
CanAdd = false; |
|
178 |
} |
|
179 |
} |
|
| 42 | 180 |
if (CanAdd && !InDownloadFile.Contains(clickedVideoBook.LdtPath)) |
| 35 | 181 |
{ |
182 |
//Préparation du loader |
|
| 38 | 183 |
/* _loaderVideoBook = new Loader<VideoBook>(LDTFileReader.ConvertToVideoBook); |
| 36 | 184 |
_loaderVideoBook.LoaderFinished += new EventHandler<EventArgs>(LoaderVideoBook_LoaderFinished); |
| 38 | 185 |
_loaderVideoBook.Load(((VideoBook)e.Parameter).LdtPath);*/ |
| 42 | 186 |
InDownloadFile.Add(clickedVideoBook .LdtPath); |
| 38 | 187 |
_loaderVideoBook = new VideoBookLoader(); |
188 |
_loaderVideoBook.LoaderFinished += new EventHandler<LoaderEventArgs<VideoBook>>(_loaderVideoBook_LoaderFinished); |
|
| 42 | 189 |
_loaderVideoBook.Load(clickedVideoBook.LdtPath); |
| 35 | 190 |
} |
191 |
|
|
192 |
||
193 |
} |
|
194 |
||
| 38 | 195 |
void _loaderVideoBook_LoaderFinished(object sender, LoaderEventArgs<VideoBook> e) |
196 |
{ |
|
197 |
VideoBook addedVideoBook = ((LoaderEventArgs<VideoBook>)e).CreatedObject; |
|
198 |
BookTimeLineVM temp = new BookTimeLineVM(addedVideoBook); |
|
199 |
temp.ViewModelVideoViewer = ConsultationBookViewContextMenu.ActualVideoSourceVM; |
|
| 42 | 200 |
SelectedVideoBooks.Add(temp); |
201 |
InDownloadFile.Remove(addedVideoBook.LdtPath); |
|
202 |
||
203 |
if(BookDownloaded!=null) |
|
204 |
BookDownloaded(this,new ConsultationVieVMSelectBookArg(addedVideoBook)); |
|
| 38 | 205 |
} |
206 |
||
| 42 | 207 |
public event EventHandler<ConsultationVieVMSelectBookArg> BookDownloaded; |
208 |
public event EventHandler<ConsultationVieVMSelectBookArg> BookDeleted; |
|
| 35 | 209 |
|
210 |
|
|
| 25 | 211 |
private void CreateNewTextualAnnotation_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
| 0 | 212 |
{ |
| 30 | 213 |
ViewModelAnnotationMaker.RefElement=SelectedElement; |
| 38 | 214 |
|
| 0 | 215 |
} |
216 |
public ConsultationViewVM() |
|
217 |
{ |
|
218 |
InitializeCommands(); |
|
| 42 | 219 |
InDownloadFile = new List<string>(); |
| 0 | 220 |
_consultationBookViewContextMenu = new ConsultationBookViewVM(); |
| 30 | 221 |
ViewModelAnnotationMaker = new AnnotationMakerVM(); |
| 0 | 222 |
SelectedVideoBooks = new SLExtensions.Collections.ObjectModel.ObservableCollection<BookTimeLineVM>(); |
223 |
} |
|
224 |
||
| 25 | 225 |
private void SelectPolemicElement_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
| 0 | 226 |
{ |
227 |
SelectedElement= (PolemicElement)e.Parameter; |
|
228 |
try |
|
229 |
{ |
|
230 |
ConsultationBookViewContextMenu.SelectedIndex = (SegmentIndex)SelectedElement; |
|
231 |
} |
|
232 |
catch |
|
233 |
{ |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
| 42 | 237 |
public class ConsultationVieVMSelectBookArg : EventArgs |
238 |
{ |
|
239 |
public VideoBook Book {get;private set;} |
|
240 |
public ConsultationVieVMSelectBookArg (VideoBook book) |
|
241 |
{ |
|
242 |
Book=book; |
|
243 |
} |
|
244 |
} |
|
| 0 | 245 |
} |