diff -r 8a25a85f2656 -r 11083c390ce4 src/FingersDance.Control.Screen/UserControlScreen.xaml.cs --- a/src/FingersDance.Control.Screen/UserControlScreen.xaml.cs Tue Nov 10 13:47:58 2009 +0100 +++ b/src/FingersDance.Control.Screen/UserControlScreen.xaml.cs Thu Nov 12 16:15:19 2009 +0100 @@ -8,6 +8,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; +using System.Xml.Linq; using FingersDance.Control.ListVideo; using FingersDance.Control.SessionInput; using FingersDance.ViewModels; @@ -22,7 +23,10 @@ public event EventHandler UC_Screen_NewCutting; private MainViewModel _mainViewModel; public Cutting Cutting; - private List existingProjects = new List(); + + private String videoName; + private String videoPath; + User User = new User(); public UserControlScreen(int id, MainViewModel mvmodel) @@ -69,7 +73,9 @@ try { //1 renseigner la video choisie au screen et créer un nouveau projet à partir de ce chemin vidéo - _mainViewModel.CreateProject(((UserControlListVideo)sender).VideoName, ((UserControlListVideo)sender).path); + videoName = ((UserControlListVideo)sender).VideoName; + videoPath = ((UserControlListVideo)sender).path; + _mainViewModel.CreateProject(videoName, videoPath); //2-Supression du UC List Video LayoutRoot.Children.Remove((UserControlListVideo)sender); OpenProjectList(); @@ -86,7 +92,14 @@ { try { - existingProjects = LoadProjects(_mainViewModel.Project.VideoPath); + // We get all the ldt/project files from the current directory... + List existingProjects = new List(); + foreach (String filename in Directory.GetFiles("./")) + { + if (filename.Substring(filename.Length-4).ToLower()==".ldt") + existingProjects.Add(filename.Substring(2, filename.Length - 6)); + } + // ... and display them the the select box UserControlListProject UserControlListProject listProject = new UserControlListProject(existingProjects); listProject.Name = "ListProject"; LayoutRoot.Children.Add(listProject); @@ -100,25 +113,6 @@ } } - private List LoadProjects(string name) - { - // Does nothing because for the moment we do not load sessions when we know the video path, we just create a new session - try - { - List lp = new List(); - foreach (String filename in Directory.GetFiles("./")) - { - if (filename.Substring(filename.Length-4).ToLower()==".ldt") - lp.Add(new Project(filename.Substring(2,filename.Length - 6), "", "")); - } - return lp; - } - catch (Exception) - { - return new List(); - } - } - void listProject_EH_ListProject_ContactDown(object sender, EventArgs e) { try @@ -133,15 +127,35 @@ } else { - foreach (Project elt in existingProjects) + // ((UserControlListProject)sender).SelectedItem is the name of the selected project + // Now we load the xml/ldt file to load all its datas (cuttings, annotations...) + XDocument loadedLdt = XDocument.Load(((UserControlListProject)sender).SelectedItem + ".ldt"); + Project loadedProject = new Project(videoName, videoPath); + loadedProject.Name = loadedLdt.Root.Element("project").Attribute("title").Value; + loadedProject.Description = loadedLdt.Root.Element("project").Attribute("abstract").Value; + loadedProject.Cuttings = new List(); + XElement cuttingsParentNode = loadedLdt.Root.Element("annotations").Element("content"); + foreach (XElement cuttingNode in cuttingsParentNode.Elements()) { - if (elt.Name.Equals(((UserControlListProject)sender).SelectedItem)) + List la = new List(); + foreach (XElement annotNode in cuttingNode.Element("elements").Elements()) { - _mainViewModel.Project.Project = elt; - OpenProject(); - return; + String aId = annotNode.Attribute("id").Value; + float begin = (float)annotNode.Attribute("begin"); + float dur = (float)annotNode.Attribute("dur"); + String gt = annotNode.Element("gestureType").Value; + String colorString = annotNode.Attribute("color").Value; // is type 0xRRGGBB + Byte r = Convert.ToByte(colorString.Substring(2, 2), 16); + Byte g = Convert.ToByte(colorString.Substring(4, 2), 16); + Byte b = Convert.ToByte(colorString.Substring(6, 2), 16); + Color c = Color.FromRgb(r, g, b); + la.Add(new Annotation(aId, begin, dur, gt, c)); } + loadedProject.Cuttings.Add(new Cutting(cuttingNode.Attribute("id").Value,cuttingNode.Element("title").Value,la)); } + // We define the loaded project as the current session's project. + _mainViewModel.Project = new ProjectViewModel(loadedProject); + OpenProject(); } } catch (Exception) @@ -159,7 +173,7 @@ //MainViewModel.Project.Alias = ((UserControlNewProjectForm)sender).Alias; //MainViewModel.Project.Email = ((UserControlNewProjectForm)sender).Email; _mainViewModel.Project.Description = ((UserControlNewProjectForm)sender).Description; - _mainViewModel.Project.Name = ((UserControlNewProjectForm)sender).SessionName.Trim(); + _mainViewModel.Project.Name = ((UserControlNewProjectForm)sender).ProjectName.Trim(); //2-Suppression UCSession Input @@ -178,6 +192,7 @@ { try { + // We display the list of cuttings available for the current project UserControlListCutting listCuttings = new UserControlListCutting(_mainViewModel.Project.CuttingsDict); listCuttings.Name = "listCuttings"; LayoutRoot.Children.Add(listCuttings); @@ -198,6 +213,7 @@ LayoutRoot.Children.Remove((UserControlListCutting)sender); if (((UserControlListCutting)sender).SelectedItem.Equals("New Cutting")) { + // "New Uutting" was was selected -> we display the form UserControlNewCuttingForm newCutting = new UserControlNewCuttingForm(User); newCutting.Name = "newCutting"; LayoutRoot.Children.Add(newCutting); @@ -205,14 +221,11 @@ } else { - foreach(KeyValuePair elt in _mainViewModel.Project.CuttingsDict) - if (elt.Key.Equals(((UserControlListCutting)sender).SelectedItem)) - { - Cutting = elt.Value; - if (UC_Screen_NewCutting != null) - UC_Screen_NewCutting(this, new EventArgs()); - return; - } + // An already existing project was clicked -> we load the selected project from the dictionnary + Cutting = _mainViewModel.Project.CuttingsDict[((UserControlListCutting)sender).SelectedItem]; + if (UC_Screen_NewCutting != null) + UC_Screen_NewCutting(this, new EventArgs()); + return; } } catch (Exception) @@ -228,6 +241,7 @@ try { LayoutRoot.Children.Remove((UserControlNewCuttingForm)sender); + // The new cutting form sent the cutting instance so we can dispatch the event UC_Screen_NewCutting Cutting = ((UserControlNewCuttingForm)sender).Cutting; if (UC_Screen_NewCutting != null) UC_Screen_NewCutting(this, new EventArgs());