[longomatch] Make dashboard hotkeys work except for Event buttons



commit fe3f63cfd289dbc0a0c97b8ae6854c4e44bb7bfc
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Oct 24 15:12:48 2014 +0200

    Make dashboard hotkeys work except for Event buttons

 LongoMatch.Core/Interfaces/GUI/IAnalysisWindow.cs  |    1 +
 LongoMatch.Drawing/CanvasObjects/ButtonObject.cs   |   15 ----
 LongoMatch.Drawing/CanvasObjects/CanvasObject.cs   |   22 ++++++
 LongoMatch.Drawing/Widgets/DashboardCanvas.cs      |    6 ++
 LongoMatch.GUI/Gui/Component/AnalysisComponent.cs  |    5 ++
 LongoMatch.GUI/Gui/Component/CategoryProperties.cs |   32 +++------
 LongoMatch.GUI/Gui/Component/CodingWidget.cs       |    5 ++
 LongoMatch.GUI/Gui/Component/DashboardWidget.cs    |    6 ++
 LongoMatch.GUI/Gui/Dialog/EditCategoryDialog.cs    |   30 +--------
 LongoMatch.GUI/Gui/Panel/WelcomePanel.cs           |    9 ++-
 .../LongoMatch.Gui.Component.CategoryProperties.cs |    1 -
 .../gtk-gui/LongoMatch.Gui.Component.Timeline.cs   |   13 ----
 .../LongoMatch.Gui.Dialog.EditCategoryDialog.cs    |    2 +-
 .../LongoMatch.Gui.Panel.ProjectsManagerPanel.cs   |    1 +
 .../gtk-gui/LongoMatch.Gui.Panel.WelcomePanel.cs   |    1 -
 LongoMatch.GUI/gtk-gui/gui.stetic                  |    2 -
 LongoMatch.Services/Services/HotKeysManager.cs     |   72 ++++++++++++++------
 17 files changed, 118 insertions(+), 105 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/GUI/IAnalysisWindow.cs 
b/LongoMatch.Core/Interfaces/GUI/IAnalysisWindow.cs
index bbf2c70..7ad8eb2 100644
--- a/LongoMatch.Core/Interfaces/GUI/IAnalysisWindow.cs
+++ b/LongoMatch.Core/Interfaces/GUI/IAnalysisWindow.cs
@@ -40,6 +40,7 @@ namespace LongoMatch.Core.Interfaces.GUI
                void ShowDashboard ();
                void ShowTimeline ();
                void ShowZonalTags ();
+               void ClickButton (DashboardButton button);
                
                IPlayerBin Player{get;}
                ICapturerBin Capturer{get;}
diff --git a/LongoMatch.Drawing/CanvasObjects/ButtonObject.cs 
b/LongoMatch.Drawing/CanvasObjects/ButtonObject.cs
index a673fac..f322f10 100644
--- a/LongoMatch.Drawing/CanvasObjects/ButtonObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/ButtonObject.cs
@@ -43,21 +43,6 @@ namespace LongoMatch.Drawing.CanvasObjects
                        base.Dispose (disposing);
                }
 
-               public virtual Point Position {
-                       get;
-                       set;
-               }
-
-               public virtual double Width {
-                       get;
-                       set;
-               }
-
-               public virtual double Height {
-                       get;
-                       set;
-               }
-
                public virtual string Text {
                        get;
                        set;
diff --git a/LongoMatch.Drawing/CanvasObjects/CanvasObject.cs 
b/LongoMatch.Drawing/CanvasObjects/CanvasObject.cs
index c1da506..b87c1cc 100644
--- a/LongoMatch.Drawing/CanvasObjects/CanvasObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/CanvasObject.cs
@@ -169,6 +169,28 @@ namespace LongoMatch.Drawing.CanvasObjects
                        }
                }
 
+               public virtual Point Position {
+                       get;
+                       set;
+               }
+
+               public virtual double Width {
+                       get;
+                       set;
+               }
+
+               public virtual double Height {
+                       get;
+                       set;
+               }
+
+               public void Click () {
+                       ClickPressed (new Point (Position.X + Width / 2, Position.Y + Height / 2),
+                                     ButtonModifier.None);
+                       
+                       ClickReleased ();
+               }
+
                public override void ClickPressed (Point p, ButtonModifier modif)
                {
                        Active = !Active;
diff --git a/LongoMatch.Drawing/Widgets/DashboardCanvas.cs b/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
index e081b38..625d53e 100644
--- a/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
+++ b/LongoMatch.Drawing/Widgets/DashboardCanvas.cs
@@ -122,6 +122,12 @@ namespace LongoMatch.Drawing.Widgets
                        }
                }
 
+               public void Click (DashboardButton b)
+               {
+                       TaggerObject co = Objects.OfType<TaggerObject>().FirstOrDefault (o => o.Tagger == b);
+                       co.Click ();
+               }
+
                public void RedrawButton (DashboardButton b)
                {
                        TaggerObject co = Objects.OfType<TaggerObject>().FirstOrDefault (o => o.Tagger == b);
diff --git a/LongoMatch.GUI/Gui/Component/AnalysisComponent.cs 
b/LongoMatch.GUI/Gui/Component/AnalysisComponent.cs
index 6bf1a28..23c1ddb 100644
--- a/LongoMatch.GUI/Gui/Component/AnalysisComponent.cs
+++ b/LongoMatch.GUI/Gui/Component/AnalysisComponent.cs
@@ -100,6 +100,11 @@ namespace LongoMatch.Gui.Component
                        codingwidget.ShowZonalTags ();
                }
 
+               public void ClickButton (DashboardButton button)
+               {
+                       codingwidget.ClickButton (button);
+               }
+
                public void DetachPlayer ()
                {
                        bool isPlaying = playercapturer.Playing;
diff --git a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs 
b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
index 2cdfa5e..ecc7d1d 100644
--- a/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
+++ b/LongoMatch.GUI/Gui/Component/CategoryProperties.cs
@@ -25,17 +25,16 @@ using LongoMatch.Core.Common;
 using LongoMatch.Core.Store;
 using LongoMatch.Gui.Dialog;
 using Point = LongoMatch.Core.Common.Point;
+using LongoMatch.Core.Store.Templates;
 
 
 namespace LongoMatch.Gui.Component
 {
-       public delegate void HotKeyChangeHandler (HotKey prevHotKey,DashboardButton button);
        [System.ComponentModel.Category("LongoMatch")]
        [System.ComponentModel.ToolboxItem(true)]
        public partial  class CategoryProperties : Gtk.Bin
        {
 
-               public event HotKeyChangeHandler HotKeyChanged;
                public event EventHandler EditedEvent;
 
                SizeGroup sizegroupLeft, sizegroupRight;
@@ -96,7 +95,6 @@ namespace LongoMatch.Gui.Component
                                }
                        }
 
-                       CanChangeHotkey = true;
                        Tagger = null;
 
                        UpdateGui ();
@@ -114,13 +112,6 @@ namespace LongoMatch.Gui.Component
                        }
                }
 
-               public bool CanChangeHotkey {
-                       set {
-                               if (value == true)
-                                       changebuton.Sensitive = true;
-                       }
-               }
-
                public EventType EventType {
                        set {
                                EventButton button = new EventButton { EventType = value };
@@ -147,7 +138,7 @@ namespace LongoMatch.Gui.Component
                        }
                }
 
-               public Project Project {
+               public Dashboard Dashboard {
                        set;
                        get;
                }
@@ -248,17 +239,16 @@ namespace LongoMatch.Gui.Component
                        if (ignore)
                                return;
 
-                       HotKeySelectorDialog dialog = new HotKeySelectorDialog ();
-                       dialog.TransientFor = (Gtk.Window)this.Toplevel;
-                       HotKey prevHotKey = button.HotKey;
-                       if (dialog.Run () == (int)ResponseType.Ok) {
-                               button.HotKey = dialog.HotKey;
-                               UpdateGui ();
+                       HotKey hotkey = Config.GUIToolkit.SelectHotkey (button.HotKey);
+                       if (hotkey != null) {
+                               try {
+                                       Dashboard.ChangeHotkey (button, hotkey);
+                                       UpdateGui ();
+                                       Edited = true;
+                               } catch (HotkeyAlreadyInUse ex) {
+                                       Config.GUIToolkit.ErrorMessage (ex.Message, this);
+                               }
                        }
-                       dialog.Destroy ();
-                       if (HotKeyChanged != null)
-                               HotKeyChanged (prevHotKey, button);
-                       Edited = true;
                }
 
                void HandlePositionChanged (object sender, EventArgs e)
diff --git a/LongoMatch.GUI/Gui/Component/CodingWidget.cs b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
index 4157125..7bbd4c5 100644
--- a/LongoMatch.GUI/Gui/Component/CodingWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
@@ -130,6 +130,11 @@ namespace LongoMatch.Gui.Component
                public void ShowZonalTags () {
                }
 
+               public void ClickButton (DashboardButton button)
+               {
+                       buttonswidget.ClickButton (button);
+               }
+
                public void SetProject (Project project, ProjectType projectType, EventsFilter filter)
                {
                        this.projectType = projectType;
diff --git a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
index 5e1e341..698e317 100644
--- a/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/DashboardWidget.cs
@@ -160,6 +160,7 @@ namespace LongoMatch.Gui.Component
                                // Start with disabled widget until something get selected
                                tagproperties.Tagger = null;
                                tagproperties.Sensitive = false;
+                               tagproperties.Dashboard = value;
                        }
                }
 
@@ -203,6 +204,11 @@ namespace LongoMatch.Gui.Component
                                Mode = tagMode;
                        }
                }
+
+               public void ClickButton (DashboardButton button)
+               {
+                       tagger.Click (button);
+               }
                
                public void Refresh (DashboardButton b = null) {
                        tagger.Refresh (b);
diff --git a/LongoMatch.GUI/Gui/Dialog/EditCategoryDialog.cs b/LongoMatch.GUI/Gui/Dialog/EditCategoryDialog.cs
index 743b320..bfd885c 100644
--- a/LongoMatch.GUI/Gui/Dialog/EditCategoryDialog.cs
+++ b/LongoMatch.GUI/Gui/Dialog/EditCategoryDialog.cs
@@ -17,54 +17,28 @@
 //
 
 using System;
-using System.Collections.Generic;
-using LongoMatch.Gui.Helpers;
 using LongoMatch.Core.Store;
-using Mono.Unix;
 
 namespace LongoMatch.Gui.Dialog
 {
 
        public partial class EditCategoryDialog : Gtk.Dialog
        {
-               List<HotKey> hkList;
 
                public EditCategoryDialog(Project project, DashboardButton tagger)
                {
                        this.Build();
                        timenodeproperties2.Tagger = tagger;
-                       timenodeproperties2.Project = project;
-                       timenodeproperties2.HotKeyChanged += OnHotKeyChanged;
+                       timenodeproperties2.Dashboard = project.Dashboard;
                }
 
                public EditCategoryDialog(Project project, EventType eventType)
                {
                        this.Build();
                        timenodeproperties2.EventType = eventType;
-                       timenodeproperties2.Project = project;
-                       timenodeproperties2.HotKeyChanged += OnHotKeyChanged;
+                       timenodeproperties2.Dashboard = project.Dashboard;
                }
 
-               public List<HotKey> HotKeysList {
-                       set {
-                               hkList = value;
-                               timenodeproperties2.CanChangeHotkey = hkList != null;
-                       }
-               }
-
-               protected virtual void OnHotKeyChanged(HotKey prevHotKey, DashboardButton button) {
-                       if(hkList.Contains(button.HotKey)) {
-                               MessagesHelpers.WarningMessage(this,
-                                                              Catalog.GetString("This hotkey is already in 
use."));
-                               button.HotKey=prevHotKey;
-                               timenodeproperties2.Tagger = button; //Update Gui
-                       }
-                       else if(button.HotKey.Defined) {
-                               hkList.Remove(prevHotKey);
-                               hkList.Add(button.HotKey);
-                       }
-               }
-               
                protected override void OnRealized ()
                {
                        base.OnRealized ();
diff --git a/LongoMatch.GUI/Gui/Panel/WelcomePanel.cs b/LongoMatch.GUI/Gui/Panel/WelcomePanel.cs
index 5c0b8c5..06bd569 100644
--- a/LongoMatch.GUI/Gui/Panel/WelcomePanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/WelcomePanel.cs
@@ -89,7 +89,9 @@ namespace LongoMatch.Gui.Panel
                        logoImage.WidthRequest = StyleConf.WelcomeLogoWidth;
                        logoImage.HeightRequest = StyleConf.WelcomeLogoHeight;
                        tablewidget.Attach (logoImage, 0, StyleConf.WelcomeIconsPerRow, 0, 1,
-                                           AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | 
AttachOptions.Fill, 0, StyleConf.WelcomeIconsVSpacing / 2);
+                                           AttachOptions.Expand | AttachOptions.Fill,
+                                           AttachOptions.Expand | AttachOptions.Fill,
+                                           0, StyleConf.WelcomeIconsVSpacing / 2);
 
                        for (uint i=0; i < buttons.Length; i++) {
                                Widget b;
@@ -100,9 +102,12 @@ namespace LongoMatch.Gui.Panel
 
                                b = CreateButton (buttons[i]);
                                tablewidget.Attach (b, c, c + 1, l, l + 1,
-                                                   AttachOptions.Expand | AttachOptions.Fill, 
AttachOptions.Expand | AttachOptions.Fill, 0, StyleConf.WelcomeIconsVSpacing / 2);
+                                                   AttachOptions.Expand | AttachOptions.Fill,
+                                                   AttachOptions.Expand | AttachOptions.Fill,
+                                                   0, StyleConf.WelcomeIconsVSpacing / 2);
                                buttonWidgets.Add (b);
                        }
+                       
                }
                
                Widget CreateButton (WelcomeButton b) {
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CategoryProperties.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CategoryProperties.cs
index 0f01fa4..6685693 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CategoryProperties.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CategoryProperties.cs
@@ -136,7 +136,6 @@ namespace LongoMatch.Gui.Component
                        w6.Fill = false;
                        // Container child hbox5.Gtk.Box+BoxChild
                        this.changebuton = new global::Gtk.Button ();
-                       this.changebuton.Sensitive = false;
                        this.changebuton.CanFocus = true;
                        this.changebuton.Name = "changebuton";
                        this.changebuton.UseUnderline = true;
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Timeline.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Timeline.cs
index 6208f8f..6c8f664 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Timeline.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.Timeline.cs
@@ -5,31 +5,18 @@ namespace LongoMatch.Gui.Component
        public partial class Timeline
        {
                private global::Gtk.HBox hbox1;
-               
                private global::Gtk.VBox leftbox;
-               
                private global::Gtk.HBox hbox2;
-               
                private global::Gtk.Button focusbutton;
-               
                private global::Gtk.Image focusbuttonimage;
-               
                private global::Gtk.DrawingArea labelsarea;
-               
                private global::Gtk.HBox zoomhbox;
-               
                private global::Gtk.Image zoominimage;
-               
                private global::Gtk.HScale focusscale;
-               
                private global::Gtk.Image zoomoutimage;
-               
                private global::Gtk.VBox vbox1;
-               
                private global::Gtk.DrawingArea timerulearea;
-               
                private global::Gtk.ScrolledWindow scrolledwindow1;
-               
                private global::Gtk.DrawingArea timelinearea;
 
                protected virtual void Build ()
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs
index dd91601..2eb5c83 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.EditCategoryDialog.cs
@@ -51,7 +51,7 @@ namespace LongoMatch.Gui.Dialog
                                this.Child.ShowAll ();
                        }
                        this.DefaultWidth = 324;
-                       this.DefaultHeight = 619;
+                       this.DefaultHeight = 668;
                        this.Show ();
                }
        }
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.ProjectsManagerPanel.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.ProjectsManagerPanel.cs
index ed56cf5..1feb359 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.ProjectsManagerPanel.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.ProjectsManagerPanel.cs
@@ -613,6 +613,7 @@ namespace LongoMatch.Gui.Panel
                        w60.Position = 0;
                        // Container child rbox.Gtk.Box+BoxChild
                        this.hbuttonbox1 = new global::Gtk.HButtonBox ();
+                       this.hbuttonbox1.Name = "hbuttonbox1";
                        // Container child hbuttonbox1.Gtk.ButtonBox+ButtonBoxChild
                        this.savebutton = new global::Gtk.Button ();
                        this.savebutton.TooltipMarkup = "Save";
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.WelcomePanel.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.WelcomePanel.cs
index 3fedf95..a827fc3 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.WelcomePanel.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Panel.WelcomePanel.cs
@@ -35,7 +35,6 @@ namespace LongoMatch.Gui.Panel
                        w1.Position = 0;
                        // Container child hbox1.Gtk.Box+BoxChild
                        this.preferencesbutton = new global::Gtk.Button ();
-                       this.preferencesbutton.CanFocus = true;
                        this.preferencesbutton.Name = "preferencesbutton";
                        this.preferencesbutton.Label = null;
                        this.hbox1.Add (this.preferencesbutton);
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index e1693d6..47e6181 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -1090,7 +1090,6 @@ Sort by competition</property>
                 <child>
                   <widget class="Gtk.Button" id="changebuton">
                     <property name="MemberName" />
-                    <property name="Sensitive">False</property>
                     <property name="CanFocus">True</property>
                     <property name="Type">TextOnly</property>
                     <property name="Label" translatable="yes">Change</property>
@@ -6472,7 +6471,6 @@ You can continue with the current capture, cancel it or save your project.
             <child>
               <widget class="Gtk.Button" id="preferencesbutton">
                 <property name="MemberName" />
-                <property name="CanFocus">True</property>
                 <property name="Type">Custom</property>
                 <child>
                   <placeholder />
diff --git a/LongoMatch.Services/Services/HotKeysManager.cs b/LongoMatch.Services/Services/HotKeysManager.cs
index 81855f1..689a25b 100644
--- a/LongoMatch.Services/Services/HotKeysManager.cs
+++ b/LongoMatch.Services/Services/HotKeysManager.cs
@@ -23,25 +23,40 @@ using LongoMatch.Core.Common;
 using LongoMatch.Core.Interfaces.GUI;
 using LongoMatch.Core.Store;
 using System;
+using LongoMatch.Core.Store.Templates;
 
-#if HAVE_GTK
-using Gdk;
-using Gtk;
-
-#endif
 namespace LongoMatch.Services
 {
        public class HotKeysManager
        {
-               Dictionary<HotKey, DashboardButton> dic;
+               Dictionary<HotKey, DashboardButton> dashboardHotkeys;
                IAnalysisWindow analysisWindow;
-               bool ignoreKeys;
+               Dashboard dashboard;
 
                public HotKeysManager ()
                {
-                       dic = new Dictionary<HotKey,DashboardButton> ();
+                       dashboardHotkeys = new Dictionary<HotKey,DashboardButton> ();
                        Config.EventsBroker.OpenedProjectChanged += HandleOpenedProjectChanged;
-                       Config.EventsBroker.KeyPressed += KeyListener;
+                       Config.EventsBroker.KeyPressed += UIKeyListener;
+                       Config.EventsBroker.KeyPressed += DashboardKeyListener;
+                       Config.EventsBroker.DashboardEditedEvent += HandleDashboardEditedEvent;
+               }
+
+               void ReloadHotkeys ()
+               {
+                       dashboardHotkeys.Clear ();
+                       if (dashboard == null) {
+                               return;
+                       }
+                       foreach (DashboardButton button in dashboard.List) {
+                               if (button.HotKey.Defined && !dashboardHotkeys.ContainsKey (button.HotKey))
+                                       dashboardHotkeys.Add (button.HotKey, button);
+                       }
+               }
+
+               void HandleDashboardEditedEvent ()
+               {
+                       ReloadHotkeys ();
                }
 
                void HandleOpenedProjectChanged (Project project, ProjectType projectType,
@@ -49,20 +64,14 @@ namespace LongoMatch.Services
                {
                        this.analysisWindow = analysisWindow;
                        if (project == null) {
-                               ignoreKeys = true;
-                               return;
-                       }
-                       
-                       dic.Clear ();
-                       ignoreKeys = false;
-                       foreach (DashboardButton cat in project.Dashboard.List) {
-                               if (cat.HotKey.Defined &&
-                                       !dic.ContainsKey (cat.HotKey))
-                                       dic.Add (cat.HotKey, cat);
+                               dashboard = null;
+                       } else {
+                               dashboard = project.Dashboard;
                        }
+                       ReloadHotkeys ();
                }
 
-               public void KeyListener (object sender, HotKey key)
+               public void UIKeyListener (object sender, HotKey key)
                {
                        KeyAction action;
 
@@ -96,8 +105,29 @@ namespace LongoMatch.Services
                                        return;
                                }
                        }
-                       if (ignoreKeys)
+               }
+               
+               public void DashboardKeyListener (object sender, HotKey key)
+               {
+                       KeyAction action;
+                       DashboardButton button;
+
+                       try {
+                               action = Config.Hotkeys.ActionsHotkeys.GetKeyByValue (key);
+                       } catch (Exception ex) {
                                return;
+                       }
+                       if (action != KeyAction.None) {
+                               /* Keep prevalence of general hotkeys over the dashboard ones */
+                               return;
+                       }
+                       
+                       if (!dashboardHotkeys.TryGetValue (key, out button)) {
+                               return;
+                       }
+                       if (! (button is AnalysisEventButton)) {
+                               analysisWindow.ClickButton (button);
+                       }
                }
        }
 }


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