[longomatch] Fix moving events to other event types



commit c9c81e1e0c5217b1e6c064dc38f54cbb0a5a9778
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Oct 9 18:06:24 2014 +0200

    Fix moving events to other event types

 LongoMatch.Services/Services/EventsManager.cs |   36 ++++++++++++++----------
 1 files changed, 21 insertions(+), 15 deletions(-)
---
diff --git a/LongoMatch.Services/Services/EventsManager.cs b/LongoMatch.Services/Services/EventsManager.cs
index 16f2d0b..2fc4249 100644
--- a/LongoMatch.Services/Services/EventsManager.cs
+++ b/LongoMatch.Services/Services/EventsManager.cs
@@ -18,6 +18,7 @@
 //
 //
 using System;
+using System.Linq;
 using System.Collections.Generic;
 using LongoMatch.Core.Common;
 using LongoMatch.Core.Interfaces;
@@ -107,6 +108,17 @@ namespace LongoMatch.Services
                        Config.EventsBroker.ShowFullScreenEvent += HandleShowFullScreenEvent;
                }
 
+               void DeletePlays (List<TimelineEvent> plays, bool update=true)
+               {
+                       Log.Debug (plays.Count + " plays deleted");
+                       analysisWindow.DeletePlays (plays);
+                       openedProject.RemovePlays (plays);
+                       if (projectType == ProjectType.FileProject) {
+                               Save (openedProject);
+                       }
+                       filter.Update ();
+               }
+
                void HandlePlayerSubstitutionEvent (TeamTemplate team, Player p1, Player p2, 
SubstitutionReason reason, Time time)
                {
                        if (openedProject != null) {
@@ -302,14 +314,7 @@ namespace LongoMatch.Services
 
                protected virtual void OnPlaysDeleted (List<TimelineEvent> plays)
                {
-                       Log.Debug (plays.Count + " plays deleted");
-                       analysisWindow.DeletePlays (plays);
-                       openedProject.RemovePlays (plays);
-
-                       if (projectType == ProjectType.FileProject) {
-                               Save (openedProject);
-                       }
-                       filter.Update ();
+                       DeletePlays (plays);
                }
 
                void OnDuplicatePlays (List<TimelineEvent> plays)
@@ -319,6 +324,7 @@ namespace LongoMatch.Services
                                copy.ID = Guid.NewGuid ();
                                /* The category is also serialized and desarialized */
                                copy.EventType = play.EventType;
+                               copy.Players = play.Players.ToList ();
                                openedProject.AddEvent (copy);
                                analysisWindow.AddPlay (copy);
                        }
@@ -333,15 +339,15 @@ namespace LongoMatch.Services
 
                protected virtual void OnPlayCategoryChanged (TimelineEvent play, EventType evType)
                {
-                       List<TimelineEvent> plays = new List<TimelineEvent> ();
-                       plays.Add (play);
-                       OnPlaysDeleted (plays);
-                       var newplay = openedProject.AddEvent (evType, play.Start, play.Stop, play.EventTime, 
play.Miniature, null, null);
-                       newplay.Name = play.Name;
-                       newplay.Notes = play.Notes;
-                       newplay.Drawings = play.Drawings;
+                       var newplay = Cloner.Clone (play);
+                       newplay.ID = Guid.NewGuid ();
+                       newplay.EventType = evType;
+                       newplay.Players = play.Players;
+                       DeletePlays (new List<TimelineEvent> {play}, false);
+                       openedProject.AddEvent (newplay);
                        analysisWindow.AddPlay (newplay);
                        Save (openedProject);
+                       filter.Update ();
                }
 
                void HandleDashboardEditedEvent ()


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