[longomatch] Add a new configuration panel for global hotkeys



commit 222ff160b7d20151a6b2e5bae75c632b90dfbf54
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Oct 24 12:34:30 2014 +0200

    Add a new configuration panel for global hotkeys

 LongoMatch.Core/Common/Exceptions.cs               |    8 ++
 LongoMatch.Core/Common/Hotkeys.cs                  |    2 +-
 LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs      |    2 +
 LongoMatch.Core/Store/Templates/Dashboard.cs       |    9 ++
 .../Gui/Component/HotkeysConfiguration.cs          |   90 ++++++++++++++++++++
 LongoMatch.GUI/Gui/Dialog/HotKeySelectorDialog.cs  |   61 +++++++-------
 LongoMatch.GUI/Gui/GUIToolkit.cs                   |   17 ++++
 LongoMatch.GUI/Gui/Panel/PreferencesPanel.cs       |    3 +
 LongoMatch.GUI/LongoMatch.GUI.csproj               |    2 +
 LongoMatch.GUI/Makefile.am                         |    2 +
 ...ongoMatch.Gui.Component.HotkeysConfiguration.cs |   28 ++++++
 .../LongoMatch.Gui.Dialog.HotKeySelectorDialog.cs  |    2 +-
 LongoMatch.GUI/gtk-gui/gui.stetic                  |   32 ++++++-
 LongoMatch.GUI/gtk-gui/objects.xml                 |    5 +-
 14 files changed, 227 insertions(+), 36 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Exceptions.cs b/LongoMatch.Core/Common/Exceptions.cs
index 979fbc4..abcfbca 100644
--- a/LongoMatch.Core/Common/Exceptions.cs
+++ b/LongoMatch.Core/Common/Exceptions.cs
@@ -18,6 +18,7 @@
 using System;
 using Mono.Unix;
 using System.Collections.Generic;
+using LongoMatch.Core.Store;
 
 namespace LongoMatch.Core.Common
 {
@@ -70,5 +71,12 @@ namespace LongoMatch.Core.Common
                }
        }
        
+       public class HotkeyAlreadyInUse: Exception
+       {
+               public HotkeyAlreadyInUse (HotKey hotkey):
+                       base (Catalog.GetString("Hotkey already in use: " + hotkey))
+               {
+               }
+       }
 }
 
diff --git a/LongoMatch.Core/Common/Hotkeys.cs b/LongoMatch.Core/Common/Hotkeys.cs
index 7b7eb87..e63775a 100644
--- a/LongoMatch.Core/Common/Hotkeys.cs
+++ b/LongoMatch.Core/Common/Hotkeys.cs
@@ -65,7 +65,6 @@ namespace LongoMatch.Core.Common
                        ActionsDescriptions [KeyAction.VisitorPlayer] = Catalog.GetString ("Start tagging 
away player");
                        ActionsDescriptions [KeyAction.Next] = Catalog.GetString ("Jump to next event");
                        ActionsDescriptions [KeyAction.Prev] = Catalog.GetString ("Jump to prev event");
-                       ActionsDescriptions [KeyAction.PauseClock] = Catalog.GetString ("Pause clock");
                        ActionsDescriptions [KeyAction.ShowDashboard] = Catalog.GetString ("Show dashboard");
                        ActionsDescriptions [KeyAction.ShowPositions] = Catalog.GetString ("Show zonal tags");
                        ActionsDescriptions [KeyAction.ShowTimeline] = Catalog.GetString ("Show timeline");
@@ -73,6 +72,7 @@ namespace LongoMatch.Core.Common
                        ActionsDescriptions [KeyAction.VisitorPlayer] = Catalog.GetString ("Start tagging 
away player");
                        ActionsDescriptions [KeyAction.SpeedDown] = Catalog.GetString ("Increase playback 
speed");
                        ActionsDescriptions [KeyAction.SpeedUp] = Catalog.GetString ("Decrease playback 
speed");
+                       ActionsDescriptions [KeyAction.PauseClock] = Catalog.GetString ("Pause clock");
                        ActionsDescriptions [KeyAction.StartPeriod] = Catalog.GetString ("Start recording 
period");
                        ActionsDescriptions [KeyAction.StopPeriod] = Catalog.GetString ("Stop recording 
period");
                        ActionsDescriptions [KeyAction.Substitution] = Catalog.GetString ("Toggle 
substitutions mode");
diff --git a/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs b/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
index 07e1180..26568b1 100644
--- a/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
+++ b/LongoMatch.Core/Interfaces/GUI/IGUIToolkit.cs
@@ -91,6 +91,8 @@ namespace LongoMatch.Core.Interfaces.GUI
 
                bool SelectMediaFiles (Project project);
 
+               HotKey SelectHotkey (HotKey hotkey, object parent = null);
+
        }
 }
 
diff --git a/LongoMatch.Core/Store/Templates/Dashboard.cs b/LongoMatch.Core/Store/Templates/Dashboard.cs
index 8941e78..7d83d2b 100644
--- a/LongoMatch.Core/Store/Templates/Dashboard.cs
+++ b/LongoMatch.Core/Store/Templates/Dashboard.cs
@@ -144,6 +144,15 @@ namespace LongoMatch.Core.Store.Templates
                public void Save(string filePath) {
                        Serializer.Save(this, filePath);
                }
+
+               public void ChangeHotkey (DashboardButton button, HotKey hotkey)
+               {
+                       if (List.Count (d => d.HotKey == hotkey) > 0) {
+                               throw new HotkeyAlreadyInUse (hotkey);
+                       } else {
+                               button.HotKey = hotkey;
+                       }
+               }
        
                public void AddDefaultTags (AnalysisEventType ev) {
                        ev.Tags.Add (new Tag (Catalog.GetString ("Success"),
diff --git a/LongoMatch.GUI/Gui/Component/HotkeysConfiguration.cs 
b/LongoMatch.GUI/Gui/Component/HotkeysConfiguration.cs
new file mode 100644
index 0000000..d8f0621
--- /dev/null
+++ b/LongoMatch.GUI/Gui/Component/HotkeysConfiguration.cs
@@ -0,0 +1,90 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using Gtk;
+using LongoMatch.Core.Common;
+using LongoMatch.Core.Store;
+using Mono.Unix;
+
+namespace LongoMatch.Gui.Component
+{
+       [System.ComponentModel.ToolboxItem(true)]
+       public partial class HotkeysConfiguration : Gtk.Bin
+       {
+               SizeGroup sgroup;
+
+               public HotkeysConfiguration ()
+               {
+                       int i = 0;
+                       this.Build ();
+
+                       sgroup = new SizeGroup (SizeGroupMode.Horizontal);
+                       foreach (KeyAction action in Config.Hotkeys.ActionsDescriptions.Keys) {
+                               AddWidget (action, Config.Hotkeys.ActionsDescriptions [action],
+                                          Config.Hotkeys.ActionsHotkeys [action], i);
+                               i++;
+                       }
+               }
+
+               public void AddWidget (KeyAction action, string desc, HotKey key, int position)
+               {
+                       uint row_top, row_bottom, col_left, col_right;
+                       HBox box;
+                       Label descLabel, keyLabel;
+                       Button edit;
+                       Gtk.Image editImage;
+
+                       box = new HBox ();
+                       box.Spacing = 5;
+                       descLabel = new Label ();
+                       descLabel.Markup = String.Format ("<b>{0}</b>", desc); 
+                       keyLabel = new Label (); 
+                       keyLabel.Markup = GLib.Markup.EscapeText (key.ToString());
+                       edit = new Button ();
+                       editImage = new Gtk.Image (LongoMatch.Gui.Helpers.Misc.LoadIcon ("longomatch-pencil", 
24));
+                       edit.Add (editImage);
+                       box.PackStart (descLabel, true, true, 0);
+                       box.PackStart (keyLabel, false, true, 0);
+                       box.PackStart (edit, false, true, 0);
+                       box.ShowAll ();
+
+                       sgroup.AddWidget (keyLabel);
+                       descLabel.Justify = Justification.Left;
+                       descLabel.SetAlignment (0f, 0.5f);
+                       edit.Clicked += (sender, e) => {
+                               HotKey hotkey = Config.GUIToolkit.SelectHotkey (key);
+                               if (hotkey != null) {
+                                       if (Config.Hotkeys.ActionsHotkeys.ContainsValue (hotkey)) {
+                                               Config.GUIToolkit.ErrorMessage (Catalog.GetString ("Hotkey 
already in use: ") +
+                                                                               GLib.Markup.EscapeText 
(hotkey.ToString()), this);
+                                       } else {
+                                               Config.Hotkeys.ActionsHotkeys[action] = hotkey;
+                                               keyLabel.Markup = GLib.Markup.EscapeText (key.ToString());
+                                       }
+                               }
+                       };
+
+                       row_top = (uint)(position / table.NColumns);
+                       row_bottom = (uint)row_top + 1;
+                       col_left = (uint)position % table.NColumns;
+                       col_right = (uint)col_left + 1;
+                       table.Attach (box, col_left, col_right, row_top, row_bottom);
+               }
+       }
+}
+
diff --git a/LongoMatch.GUI/Gui/Dialog/HotKeySelectorDialog.cs 
b/LongoMatch.GUI/Gui/Dialog/HotKeySelectorDialog.cs
index 424cfb8..0a8dac6 100644
--- a/LongoMatch.GUI/Gui/Dialog/HotKeySelectorDialog.cs
+++ b/LongoMatch.GUI/Gui/Dialog/HotKeySelectorDialog.cs
@@ -16,64 +16,65 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 //
-
 using System;
 using Gtk;
 using Gdk;
 using LongoMatch.Core.Store;
+using Keyboard = LongoMatch.Core.Common.Keyboard;
+using Mono.Unix;
 
 namespace LongoMatch.Gui.Dialog
 {
-
-
        public partial class HotKeySelectorDialog : Gtk.Dialog
        {
                HotKey hotKey;
-
                #region Constructors
-
-               public HotKeySelectorDialog()
+               public HotKeySelectorDialog ()
                {
-                       hotKey = new HotKey();
-                       this.Build();
+                       hotKey = new HotKey ();
+                       this.Build ();
                }
                #endregion
-
                #region Properties
-
                public HotKey HotKey {
                        get {
                                return this.hotKey;
                        }
                }
                #endregion
-
                #region Overrides
+               bool IsSupportedModifier (Gdk.Key key)
+               {
+                       return key == Gdk.Key.Shift_L ||
+                               key == Gdk.Key.Shift_R ||
+                               key == Gdk.Key.Alt_L ||
+                               key == Gdk.Key.Alt_R ||
+                               key == Gdk.Key.Control_L ||
+                               key == Gdk.Key.Control_R ||
+                               key == (Gdk.Key) ModifierType.None;
+               }
 
-               protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
+               protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
                {
-                       Gdk.Key key = evnt.Key;
-                       ModifierType modifier = evnt.State;
+                       if (evnt.Key == Gdk.Key.Escape || evnt.Key == Gdk.Key.Return) {
+                               return base.OnKeyPressEvent (evnt);
+                       }
 
-                       // Only react to {Shift|Alt|Ctrl}+key
-                       // Ctrl is a modifier to select single keys
-                       // Combination are allowed with Alt and Shift (Ctrl is not allowed to avoid
-                       // conflicts with menus shortcuts)
-                       if((modifier & (ModifierType.Mod1Mask | ModifierType.ShiftMask | 
ModifierType.ControlMask)) != 0
-                                       && key != Gdk.Key.Shift_L
-                                       && key != Gdk.Key.Shift_R
-                                       && key != Gdk.Key.Alt_L
-                                       && key != Gdk.Key.Control_L
-                                       && key != Gdk.Key.Control_R)
-                       {
-                               hotKey.Key = (int)key;
-                               hotKey.Modifier = (int) (modifier & (ModifierType.Mod1Mask | 
ModifierType.ShiftMask));
-                               this.Respond(ResponseType.Ok);
+                       if (IsSupportedModifier (evnt.Key)) {
+                               return true;
                        }
 
-                       return base.OnKeyPressEvent(evnt);
+                       hotKey = Keyboard.ParseEvent (evnt);
+                       if (hotKey.Modifier != -1 && !IsSupportedModifier ((Gdk.Key)hotKey.Modifier)) {
+                               string msg = Keyboard.NameFromKeyval ((uint) hotKey.Modifier) +
+                                       Catalog.GetString ("is not a valid key modifier: Alt, Shift or Ctrl");
+                               Config.GUIToolkit.WarningMessage (msg, this);
+                               hotKey = null;
+                               return true;
+                       }
+                       Respond (ResponseType.Ok);
+                       return true;
                }
                #endregion
-
        }
 }
diff --git a/LongoMatch.GUI/Gui/GUIToolkit.cs b/LongoMatch.GUI/Gui/GUIToolkit.cs
index 49707a4..a0afbc0 100644
--- a/LongoMatch.GUI/Gui/GUIToolkit.cs
+++ b/LongoMatch.GUI/Gui/GUIToolkit.cs
@@ -406,6 +406,23 @@ namespace LongoMatch.Gui
                        Log.Information ("Quit application");
                        Gtk.Application.Quit ();
                }
+               
+               public HotKey SelectHotkey (HotKey hotkey, object parent = null)
+               {
+                       HotKeySelectorDialog dialog;
+                       Window w;
+                       
+                       w = parent != null ? (parent as Widget).Toplevel as Window : mainWindow;
+                       dialog = new HotKeySelectorDialog ();
+                       dialog.TransientFor = w;
+                       if (dialog.Run () == (int)ResponseType.Ok) {
+                               hotkey = dialog.HotKey;
+                       } else {
+                               hotkey = null;
+                       }
+                       dialog.Destroy ();
+                       return hotkey;
+               }
        }
 }
 
diff --git a/LongoMatch.GUI/Gui/Panel/PreferencesPanel.cs b/LongoMatch.GUI/Gui/Panel/PreferencesPanel.cs
index 4bd8fda..42ea770 100644
--- a/LongoMatch.GUI/Gui/Panel/PreferencesPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/PreferencesPanel.cs
@@ -58,6 +58,9 @@ namespace LongoMatch.Gui.Panel
                        AddPane (Catalog.GetString ("General"),
                                 Helpers.Misc.LoadIcon ("longomatch-preferences", IconSize.Dialog, 0),
                                 new GeneralPreferencesPanel());
+                       AddPane (Catalog.GetString ("Keyboard shortcuts"),
+                                Helpers.Misc.LoadIcon ("longomatch-video-device", IconSize.Dialog, 0),
+                                new HotkeysConfiguration ());
                        AddPane (Catalog.GetString ("Video"),
                                 Helpers.Misc.LoadIcon ("longomatch-control-record", IconSize.Dialog, 0),
                                 new VideoPreferencesPanel());
diff --git a/LongoMatch.GUI/LongoMatch.GUI.csproj b/LongoMatch.GUI/LongoMatch.GUI.csproj
index 9fd8a20..8cf7f03 100644
--- a/LongoMatch.GUI/LongoMatch.GUI.csproj
+++ b/LongoMatch.GUI/LongoMatch.GUI.csproj
@@ -188,6 +188,8 @@
     <Compile Include="Gui\Component\MediaFileSetSelection.cs" />
     <Compile Include="gtk-gui\LongoMatch.Gui.Component.MediaFileSetSelection.cs" />
     <Compile Include="Gui\Menu\PeriodsMenu.cs" />
+    <Compile Include="Gui\Component\HotkeysConfiguration.cs" />
+    <Compile Include="gtk-gui\LongoMatch.Gui.Component.HotkeysConfiguration.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="gtk-gui\gui.stetic">
diff --git a/LongoMatch.GUI/Makefile.am b/LongoMatch.GUI/Makefile.am
index d2b5ea1..f5780f0 100644
--- a/LongoMatch.GUI/Makefile.am
+++ b/LongoMatch.GUI/Makefile.am
@@ -12,6 +12,7 @@ SOURCES = Gui/Cairo.cs \
        Gui/Component/DashboardWidget.cs \
        Gui/Component/DatePicker.cs \
        Gui/Component/GeneralPreferencesPanel.cs \
+       Gui/Component/HotkeysConfiguration.cs \
        Gui/Component/LiveAnalysisPreferences.cs \
        Gui/Component/MediaFileChooser.cs \
        Gui/Component/MediaFileSetSelection.cs \
@@ -90,6 +91,7 @@ SOURCES = Gui/Cairo.cs \
        gtk-gui/LongoMatch.Gui.Component.DatePicker.cs \
        gtk-gui/LongoMatch.Gui.Component.GameViewer.cs \
        gtk-gui/LongoMatch.Gui.Component.GeneralPreferencesPanel.cs \
+       gtk-gui/LongoMatch.Gui.Component.HotkeysConfiguration.cs \
        gtk-gui/LongoMatch.Gui.Component.LiveAnalysisPreferences.cs \
        gtk-gui/LongoMatch.Gui.Component.MediaFileChooser.cs \
        gtk-gui/LongoMatch.Gui.Component.MediaFileSetSelection.cs \
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.HotkeysConfiguration.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.HotkeysConfiguration.cs
new file mode 100644
index 0000000..53b8cfe
--- /dev/null
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.HotkeysConfiguration.cs
@@ -0,0 +1,28 @@
+
+// This file has been generated by the GUI designer. Do not modify.
+namespace LongoMatch.Gui.Component
+{
+       public partial class HotkeysConfiguration
+       {
+               private global::Gtk.Table table;
+
+               protected virtual void Build ()
+               {
+                       global::Stetic.Gui.Initialize (this);
+                       // Widget LongoMatch.Gui.Component.HotkeysConfiguration
+                       global::Stetic.BinContainer.Attach (this);
+                       this.Name = "LongoMatch.Gui.Component.HotkeysConfiguration";
+                       // Container child 
LongoMatch.Gui.Component.HotkeysConfiguration.Gtk.Container+ContainerChild
+                       this.table = new global::Gtk.Table (((uint)(2)), ((uint)(2)), true);
+                       this.table.Name = "table";
+                       this.table.RowSpacing = ((uint)(6));
+                       this.table.ColumnSpacing = ((uint)(30));
+                       this.table.BorderWidth = ((uint)(20));
+                       this.Add (this.table);
+                       if ((this.Child != null)) {
+                               this.Child.ShowAll ();
+                       }
+                       this.Hide ();
+               }
+       }
+}
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.HotKeySelectorDialog.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.HotKeySelectorDialog.cs
index 15a2665..a4b208e 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.HotKeySelectorDialog.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Dialog.HotKeySelectorDialog.cs
@@ -25,7 +25,7 @@ namespace LongoMatch.Gui.Dialog
                        // Container child dialog1_VBox.Gtk.Box+BoxChild
                        this.label1 = new global::Gtk.Label ();
                        this.label1.Name = "label1";
-                       this.label1.LabelProp = global::Mono.Unix.Catalog.GetString ("Press a key combination 
using  Shift+key or Alt+key.\nHotkeys with a single key are also allowed with Ctrl+key.");
+                       this.label1.LabelProp = global::Mono.Unix.Catalog.GetString ("Press a key 
combination...");
                        w1.Add (this.label1);
                        global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(w1 [this.label1]));
                        w2.Position = 0;
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index 82031d3..e1693d6 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -2872,8 +2872,7 @@ You can download it using this direct link:</property>
         <child>
           <widget class="Gtk.Label" id="label1">
             <property name="MemberName" />
-            <property name="LabelProp" translatable="yes">Press a key combination using  Shift+key or 
Alt+key.
-Hotkeys with a single key are also allowed with Ctrl+key.</property>
+            <property name="LabelProp" translatable="yes">Press a key combination...</property>
           </widget>
           <packing>
             <property name="Position">0</property>
@@ -11504,4 +11503,31 @@ You can continue with the current capture, cancel it or save your project.
       </widget>
     </child>
   </widget>
-</stetic-interface>
+  <widget class="Gtk.Bin" id="LongoMatch.Gui.Component.HotkeysConfiguration" design-size="388 300">
+    <property name="MemberName" />
+    <property name="Visible">False</property>
+    <child>
+      <widget class="Gtk.Table" id="table">
+        <property name="MemberName" />
+        <property name="NRows">2</property>
+        <property name="NColumns">2</property>
+        <property name="Homogeneous">True</property>
+        <property name="RowSpacing">6</property>
+        <property name="ColumnSpacing">30</property>
+        <property name="BorderWidth">20</property>
+        <child>
+          <placeholder />
+        </child>
+        <child>
+          <placeholder />
+        </child>
+        <child>
+          <placeholder />
+        </child>
+        <child>
+          <placeholder />
+        </child>
+      </widget>
+    </child>
+  </widget>
+</stetic-interface>
\ No newline at end of file
diff --git a/LongoMatch.GUI/gtk-gui/objects.xml b/LongoMatch.GUI/gtk-gui/objects.xml
index 50bb478..d594818 100644
--- a/LongoMatch.GUI/gtk-gui/objects.xml
+++ b/LongoMatch.GUI/gtk-gui/objects.xml
@@ -7,7 +7,6 @@
     </itemgroups>
     <signals>
       <itemgroup label="CategoryProperties Signals">
-        <signal name="HotKeyChanged" />
         <signal name="EditedEvent" />
       </itemgroup>
     </signals>
@@ -311,6 +310,10 @@
     <itemgroups />
     <signals />
   </object>
+  <object type="LongoMatch.Gui.Component.HotkeysConfiguration" palette-category="General" 
allow-children="false" base-type="Gtk.Bin">
+    <itemgroups />
+    <signals />
+  </object>
   <object type="LongoMatch.Gui.CapturerBin" palette-category="General" allow-children="false" 
base-type="Gtk.Bin">
     <itemgroups>
       <itemgroup label="CapturerBin Properties">


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