[longomatch] Resync timeline events after syncing periods



commit 3da3c6c2b2ae14b92a17e7b7ee06768e8a7f4bf9
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Oct 28 09:04:17 2014 +0100

    Resync timeline events after syncing periods

 LongoMatch.Core/Store/TimeNode.cs              |   13 ++++++++
 LongoMatch.GUI/Gui/Component/ProjectPeriods.cs |   36 ++++++++++++++++++++++-
 LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs    |    1 +
 3 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/LongoMatch.Core/Store/TimeNode.cs b/LongoMatch.Core/Store/TimeNode.cs
index b75a7e1..345c453 100644
--- a/LongoMatch.Core/Store/TimeNode.cs
+++ b/LongoMatch.Core/Store/TimeNode.cs
@@ -110,6 +110,19 @@ namespace LongoMatch.Core.Store
                        set;
                }
 
+               public void Move (Time diff)
+               {
+                       if (start != null) {
+                               start += diff;
+                       }
+                       if (stop != null) {
+                               stop += diff;
+                       }
+                       if (eventTime != null) {
+                               eventTime += diff;
+                       }
+               }
+
                public TimeNode Join (TimeNode tn) {
                        if (tn.Stop < Start || tn.Start > Stop)
                                return null;
diff --git a/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs b/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs
index 71e99a5..ab4c5fa 100644
--- a/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs
+++ b/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs
@@ -16,6 +16,7 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
+using System.Linq;
 using LongoMatch.Core.Store;
 using System.Collections.Generic;
 using LongoMatch.Drawing.Widgets;
@@ -34,6 +35,8 @@ namespace LongoMatch.Gui.Component
                Time duration;
                Project project;
                PeriodsMenu menu;
+               Dictionary<Period, Period> periodsDict;
+               bool projectHasPeriods;
 
                public ProjectPeriods ()
                {
@@ -64,10 +67,29 @@ namespace LongoMatch.Gui.Component
                        base.OnDestroyed ();
                }
 
+               public void SaveChanges ()
+               {
+                       if (!projectHasPeriods)
+                               return;
+                       foreach (Period p in periodsDict.Keys) {
+                               Period newp = periodsDict [p];
+                               TimeNode tn = p.PeriodNode;
+                               Time diff = newp.PeriodNode.Start - tn.Start;
+                               foreach (TimelineEvent evt in project.Timeline.Where
+                                        (e=>e.EventTime > tn.Start && e.EventTime < tn.Stop)) {
+                                       evt.Move (diff);
+                               }
+                               foreach (TimeNode t in p.Nodes) {
+                                       t.Move (diff);
+                               }
+                       }
+               }
+
                public Project Project {
                        set {
                                Time start, pDuration;
                                List<string> gamePeriods;
+                               List<Period> periods;
                                MediaFile file;
                                
                                playerbin2.ShowControls = false;
@@ -79,7 +101,7 @@ namespace LongoMatch.Gui.Component
                                duration = file.Duration;
                                pDuration = new Time (duration.MSeconds / gamePeriods.Count);
                                if (project.Periods == null || project.Periods.Count == 0) {
-                                       List<Period> periods = new List<Period> ();
+                                       periods = new List<Period> ();
                                        gamePeriods = value.Dashboard.GamePeriods;
                                        foreach (string s in gamePeriods) {
                                                Period period = new Period { Name = s };
@@ -89,8 +111,18 @@ namespace LongoMatch.Gui.Component
                                                start += pDuration;
                                        }
                                        value.Periods = periods;
+                                       projectHasPeriods = false;
+                               } else {
+                                       periodsDict = new Dictionary <Period, Period> ();
+                                       foreach (Period p in project.Periods) {
+                                               Period newp = new Period {Name = p.Name};
+                                               newp.Nodes.Add (p.PeriodNode);
+                                               periodsDict.Add (p, newp);
+                                       }
+                                       projectHasPeriods = true;
+                                       periods = periodsDict.Values.ToList ();
                                }
-                               timersTimeline.LoadPeriods (value.Periods, duration);
+                               timersTimeline.LoadPeriods (periods, duration);
                                timerule.Duration = duration;
                                SetZoom ();
                                playerbin2.Open (value.Description.FileSet);
diff --git a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
index 2e7a994..8f00738 100644
--- a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
@@ -442,6 +442,7 @@ namespace LongoMatch.Gui.Panel
                                        return;
                                }
                        } else if (notebook1.Page == PROJECT_PERIODS) {
+                               projectperiods1.SaveChanges ();
                                StartProject ();
                                return;
                        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]