[gitg/wip/albfan/history-panel-shorcuts-bindingset] Add shortcuts for history panels



commit 5327c161e73b37f461ea317eeb41e96baf218e66
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Wed Feb 5 01:44:42 2020 +0100

    Add shortcuts for history panels

 gitg/gitg-window.vala                   |  6 +++---
 gitg/history/gitg-history.vala          | 27 +++++++++++++++++++++++++++
 libgitg-ext/gitg-ext-history-panel.vala | 11 +++++++++++
 plugins/diff/gitg-diff.vala             |  5 +++++
 plugins/files/gitg-files.vala           |  5 +++++
 5 files changed, 51 insertions(+), 3 deletions(-)
---
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index ca640d5b..9aa80e71 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -357,11 +357,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                        d_infobar.hide();
                });
 
-               unowned Gtk.BindingSet bset = Gtk.BindingSet.by_class(get_class());
+               unowned Gtk.BindingSet binding_set = Gtk.BindingSet.by_class(get_class());
 
                for (int i = 0; i < 10; i++)
                {
-                       Gtk.BindingEntry.add_signal(bset,
+                       Gtk.BindingEntry.add_signal(binding_set,
                                                    (Gdk.Key.@0 + i),
                                                    Gdk.ModifierType.MOD1_MASK,
                                                    "change-to-activity",
@@ -370,7 +370,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                                                    i);
                }
 
-               Gtk.BindingEntry.add_signal(bset,
+               Gtk.BindingEntry.add_signal(binding_set,
                                            Gdk.Key.Escape,
                                            0,
                                            "cancel",
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index fc5d93cb..7fa18936 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -584,6 +584,22 @@ namespace GitgHistory
                        d_panels = new Gitg.UIElements<GitgExt.HistoryPanel>(extset,
                                                                             d_main.stack_panel);
 
+                       unowned Gtk.BindingSet binding_set = Gtk.BindingSet.by_class(get_class());
+
+                       foreach(var element in d_panels.get_available_elements()) {
+                               GitgExt.HistoryPanel panel = (GitgExt.HistoryPanel)element;
+                               uint? key = panel.shortcut;
+                               if (key != null) {
+                                       Gtk.BindingEntry.add_signal(binding_set,
+                                                                   key,
+                                                                   Gdk.ModifierType.MOD1_MASK,
+                                                                   "change-to-panel",
+                                                                   1,
+                                                                   typeof(string),
+                                                                   element.id);
+                               }
+                       };
+
                        d_refs_list_popup = new Gitg.PopupMenu(d_main.refs_list);
                        d_refs_list_popup.populate_menu.connect(on_refs_list_populate_menu);
 
@@ -605,6 +621,17 @@ namespace GitgHistory
                        d_commit_list_model.end_clear.connect(on_commit_model_end_clear);
                }
 
+               [Signal(action = true)]
+               public virtual signal bool change_to_panel(string id)
+               {
+                       var panel = d_panels.lookup(id);
+                       if (panel != null) {
+                               panel.activate();
+                       }
+                       return true;
+               }
+
+
                private void update_walker_idle()
                {
                        if (d_repository == null)
diff --git a/libgitg-ext/gitg-ext-history-panel.vala b/libgitg-ext/gitg-ext-history-panel.vala
index baeb084f..5a12ddf4 100644
--- a/libgitg-ext/gitg-ext-history-panel.vala
+++ b/libgitg-ext/gitg-ext-history-panel.vala
@@ -42,6 +42,17 @@ public interface HistoryPanel : Object, UIElement
         * is created.
         */
        public abstract GitgExt.History? history { owned get; construct set; }
+
+       /**
+        * The ui element shortcut.
+        *
+        * If provided, the key to mix with Gdk.ModifierType.MOD1_MASK to enable
+        * this element
+        */
+       public virtual uint? shortcut
+       {
+               owned get { return null; }
+       }
 }
 
 }
diff --git a/plugins/diff/gitg-diff.vala b/plugins/diff/gitg-diff.vala
index 51d18706..324780fb 100644
--- a/plugins/diff/gitg-diff.vala
+++ b/plugins/diff/gitg-diff.vala
@@ -32,6 +32,11 @@ namespace GitgDiff
 
                private ulong d_selection_changed_id;
 
+               public virtual uint? shortcut
+               {
+                       owned get { return Gdk.Key.d; }
+               }
+
                protected override void constructed()
                {
                        base.constructed();
diff --git a/plugins/files/gitg-files.vala b/plugins/files/gitg-files.vala
index 9adb63d2..b878fc7a 100644
--- a/plugins/files/gitg-files.vala
+++ b/plugins/files/gitg-files.vala
@@ -48,6 +48,11 @@ namespace GitgFiles
                        history.selection_changed.connect(on_selection_changed);
                }
 
+               public virtual uint? shortcut
+               {
+                       owned get { return Gdk.Key.f; }
+               }
+
                public string id
                {
                        owned get { return "/org/gnome/gitg/Panels/Files"; }


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