[longomatch] Add a function to remove dead links



commit 977fb2ff3f0111b9006e86b998dfb38f2ce2ef14
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Apr 14 01:42:11 2015 +0200

    Add a function to remove dead links

 LongoMatch.Core/Store/Templates/Dashboard.cs    |   14 ++++++++++++++
 LongoMatch.GUI/Gui/Component/DashboardWidget.cs |    7 ++++---
 Tests/Core/Store/Templates/TestDashboard.cs     |   16 ++++++++++++++++
 3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/LongoMatch.Core/Store/Templates/Dashboard.cs b/LongoMatch.Core/Store/Templates/Dashboard.cs
index 0dbd9bc..5a8bbd6 100644
--- a/LongoMatch.Core/Store/Templates/Dashboard.cs
+++ b/LongoMatch.Core/Store/Templates/Dashboard.cs
@@ -260,6 +260,20 @@ namespace LongoMatch.Core.Store.Templates
                }
 
                /// <summary>
+               /// Removes dead links for this button, called after the event tags
+               /// have been edited.
+               /// </summary>
+               /// <param name="button">Dashboard button.</param>
+               public void RemoveDeadLinks (AnalysisEventButton button)
+               {
+
+                       foreach (DashboardButton b in List) {
+                               b.ActionLinks.RemoveAll (l => l.DestinationButton == button &&
+                               l.DestinationTags.Intersect (button.AnalysisEventType.Tags).Any ());
+                       }
+               }
+
+               /// <summary>
                /// Adds a new <see cref="AnalysisEventButton"/> with the default values
                /// </summary>
                /// <returns>A new button.</returns>
diff --git a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
index 22e21ae..2c68113 100644
--- a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
@@ -66,7 +66,7 @@ namespace LongoMatch.Gui.Component
                        tagger.ButtonsSelectedEvent += HandleTaggersSelectedEvent;
                        tagger.ShowMenuEvent += HandleShowMenuEvent;
                        tagger.NewTagEvent += HandleNewTagEvent;
-                       tagger.EditButtonTagsEvent += HandleAddNewTagEvent;
+                       tagger.EditButtonTagsEvent += EditEventSubcategories;
                        drawingarea.CanFocus = true;
                        drawingarea.KeyPressEvent += HandleKeyPressEvent;
                        fieldeventbox.ButtonPressEvent += HandleFieldButtonPressEvent;
@@ -462,13 +462,14 @@ namespace LongoMatch.Gui.Component
                        //Config.EventsBroker.EmitNewTag (button, players, tags, start, stop);
                }
 
-               void HandleAddNewTagEvent (DashboardButton taggerbutton)
+               void EditEventSubcategories (DashboardButton dashboardButton)
                {
-                       AnalysisEventType evt = (taggerbutton as AnalysisEventButton).AnalysisEventType;
+                       AnalysisEventType evt = (dashboardButton as AnalysisEventButton).AnalysisEventType;
                        EventTypeTagsEditor dialog = new EventTypeTagsEditor ();
                        dialog.EventType = evt;
                        dialog.Run ();
                        dialog.Destroy ();
+                       template.RemoveDeadLinks (dashboardButton);
                        Edited = true;
                }
 
diff --git a/Tests/Core/Store/Templates/TestDashboard.cs b/Tests/Core/Store/Templates/TestDashboard.cs
index f3b2b96..25a9e0b 100644
--- a/Tests/Core/Store/Templates/TestDashboard.cs
+++ b/Tests/Core/Store/Templates/TestDashboard.cs
@@ -92,6 +92,22 @@ namespace Tests.Core.Store.Templates
                        dashboard.RemoveButton (b2);
                        Assert.AreEqual (0, b1.ActionLinks.Count);
                }
+
+               [Test ()]
+               public void RemoveDeadLinks ()
+               {
+                       Dashboard dashboard = new Dashboard ();
+                       AnalysisEventButton b1 = dashboard.AddDefaultItem (0);
+                       AnalysisEventButton b2 = dashboard.AddDefaultItem (1);
+
+                       b1.ActionLinks.Add (new ActionLink { DestinationButton = b2 });
+                       dashboard.RemoveDeadLinks (b2);
+                       Assert.AreEqual (1, b1.ActionLinks.Count);
+
+                       b1.ActionLinks [0].DestinationTags = new List<Tag> { b1.AnalysisEventType.Tags [0] };
+                       dashboard.RemoveDeadLinks (b2);
+                       Assert.AreEqual (0, b1.ActionLinks.Count);
+               }
        }
 }
 


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