[longomatch] Show error message adding a link with circular deps



commit 1ad4197a844d47b6b691cdb92cbee6a48b6bbc4a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Apr 14 13:46:16 2015 +0200

    Show error message adding a link with circular deps

 LongoMatch.Core/Handlers/Handlers.cs            |    3 +++
 LongoMatch.Core/Store/DashboardButton.cs        |    6 ++++++
 LongoMatch.Core/Store/Templates/Dashboard.cs    |   17 +++++++++++------
 LongoMatch.Drawing/Widgets/DashboardCanvas.cs   |    4 ++++
 LongoMatch.GUI/Gui/Component/DashboardWidget.cs |   15 +++++++++++++--
 Tests/Core/Store/Templates/TestDashboard.cs     |    6 +++---
 6 files changed, 40 insertions(+), 11 deletions(-)
---
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index aee297f..bba777c 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -64,6 +64,9 @@ namespace LongoMatch.Core.Handlers
        /* Dashboard link selected */
        public delegate void ActionLinksSelectedHandler (List<ActionLink> actionLink);
 
+       /* Dashboard link crated */
+       public delegate void ActionLinkCreatedHandler (ActionLink actionLink);
+
        /* Show dashboard menu */
        public delegate void ShowDashboardMenuHandler (List<DashboardButton> selectedButtons,List<ActionLink> 
selectedLinks);
 
diff --git a/LongoMatch.Core/Store/DashboardButton.cs b/LongoMatch.Core/Store/DashboardButton.cs
index 2540b1d..fe104b1 100644
--- a/LongoMatch.Core/Store/DashboardButton.cs
+++ b/LongoMatch.Core/Store/DashboardButton.cs
@@ -105,6 +105,12 @@ namespace LongoMatch.Core.Store
                                return c.RGBColor ();
                        }
                }
+
+               public void AddActionLink (ActionLink link)
+               {
+                       link.SourceButton = this;
+                       ActionLinks.Add (link);
+               }
        }
 
        [Serializable]
diff --git a/LongoMatch.Core/Store/Templates/Dashboard.cs b/LongoMatch.Core/Store/Templates/Dashboard.cs
index 6513725..fd87d54 100644
--- a/LongoMatch.Core/Store/Templates/Dashboard.cs
+++ b/LongoMatch.Core/Store/Templates/Dashboard.cs
@@ -239,7 +239,9 @@ namespace LongoMatch.Core.Store.Templates
                {
                        foreach (DashboardButton button in List) {
                                try {
-                                       CheckButtonLinks (button, new List<DashboardButton> ());
+                                       foreach (ActionLink link in button.ActionLinks) {
+                                               CheckLinks (link, new List<DashboardButton> ());
+                                       }
                                } catch (CircularDependencyException) {
                                        return true;
                                }
@@ -389,19 +391,22 @@ namespace LongoMatch.Core.Store.Templates
                                AddDefaultItem (i - 1);
                }
 
-               void CheckButtonLinks (DashboardButton button, List<DashboardButton> traversed = null)
+               void CheckLinks (ActionLink link, List<DashboardButton> traversed = null)
                {
+                       DashboardButton source;
+
                        if (traversed == null)
                                traversed = new List<DashboardButton> ();
 
-                       if (traversed.Contains (button)) {
+                       source = link.SourceButton;
+                       if (traversed.Contains (source)) {
                                throw new CircularDependencyException ();
                        } else {
-                               traversed.Add (button);
+                               traversed.Add (source);
                        }
 
-                       foreach (ActionLink l in button.ActionLinks) {
-                               CheckButtonLinks (l.DestinationButton, traversed);
+                       foreach (ActionLink l in link.DestinationButton.ActionLinks) {
+                               CheckLinks (l, traversed);
                        }
                }
        }
diff --git a/LongoMatch.Drawing/Widgets/DashboardCanvas.cs b/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
index 73ea73a..7424951 100644
--- a/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
+++ b/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
@@ -35,6 +35,7 @@ namespace LongoMatch.Drawing.Widgets
                public event ButtonsSelectedHandler ButtonsSelectedEvent;
                public event ButtonSelectedHandler EditButtonTagsEvent;
                public event ActionLinksSelectedHandler ActionLinksSelectedEvent;
+               public event ActionLinkCreatedHandler ActionLinkCreatedEvent;
                public event ShowDashboardMenuHandler ShowMenuEvent;
                public event NewEventHandler NewTagEvent;
 
@@ -310,6 +311,9 @@ namespace LongoMatch.Drawing.Widgets
                                        link.SourceButton.ActionLinks.Add (link);
                                        movingLink.Destination = destAnchor;
                                        destAnchor.Highlighted = false;
+                                       if (ActionLinkCreatedEvent != null) {
+                                               ActionLinkCreatedEvent (link);
+                                       }
                                        Edited = true;
                                } else {
                                        RemoveObject (movingLink);
diff --git a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
index 7ad486c..4e1158c 100644
--- a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
@@ -72,6 +72,7 @@ namespace LongoMatch.Gui.Component
                        tagger.NewTagEvent += HandleNewTagEvent;
                        tagger.EditButtonTagsEvent += EditEventSubcategories;
                        tagger.ActionLinksSelectedEvent += HandleActionLinksSelectedEvent;
+                       tagger.ActionLinkCreatedEvent += HandleActionLinkCreatedEvent;
                        drawingarea.CanFocus = true;
                        drawingarea.KeyPressEvent += HandleKeyPressEvent;
                        fieldeventbox.ButtonPressEvent += HandleFieldButtonPressEvent;
@@ -266,11 +267,11 @@ namespace LongoMatch.Gui.Component
                        }
                }
 
-               void RemoveLink (ActionLink link)
+               void RemoveLink (ActionLink link, bool force = false)
                {
                        string msg = string.Format ("{0} {1} ?",
                                             Catalog.GetString ("Do you want to delete: "), link);
-                       if (Config.GUIToolkit.QuestionMessage (msg, null, this)) {
+                       if (force || Config.GUIToolkit.QuestionMessage (msg, null, this)) {
                                link.SourceButton.ActionLinks.Remove (link);
                                Edited = true;
                                Refresh ();
@@ -544,5 +545,15 @@ namespace LongoMatch.Gui.Component
                                Config.GUIToolkit.ErrorMessage (Catalog.GetString ("Could not parse game 
periods."));
                        }
                }
+
+               void HandleActionLinkCreatedEvent (ActionLink actionLink)
+               {
+                       if (template.HasCircularDependencies ()) {
+                               Config.GUIToolkit.ErrorMessage (Catalog.GetString (
+                                       "This link has circular depdencie and will not be added."));
+                               RemoveLink (actionLink, true);
+                       }
+               }
+
        }
 }
diff --git a/Tests/Core/Store/Templates/TestDashboard.cs b/Tests/Core/Store/Templates/TestDashboard.cs
index 0a6278d..ce81132 100644
--- a/Tests/Core/Store/Templates/TestDashboard.cs
+++ b/Tests/Core/Store/Templates/TestDashboard.cs
@@ -64,11 +64,11 @@ namespace Tests.Core.Store.Templates
                        dashboard.List.Add (b2);
                        dashboard.List.Add (b3);
 
-                       b1.ActionLinks.Add (new ActionLink { DestinationButton = b2 });
+                       b1.AddActionLink (new ActionLink { DestinationButton = b2 });
                        Assert.IsFalse (dashboard.HasCircularDependencies ());
-                       b2.ActionLinks.Add (new ActionLink { DestinationButton = b3 });
+                       b2.AddActionLink (new ActionLink { DestinationButton = b3 });
                        Assert.IsFalse (dashboard.HasCircularDependencies ());
-                       b3.ActionLinks.Add (new ActionLink { DestinationButton = b1 });
+                       b3.AddActionLink (new ActionLink { DestinationButton = b1 });
                        Assert.IsTrue (dashboard.HasCircularDependencies ());
                }
 


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