[gitg/wip/albfan/history-panel-shorcuts: 31/31] Adds history plugins shortcuts dynamically to the shortcuts dialog



commit c4b6b78c7625ff56d14df7fd143bbe73407e57e6
Author: Mahmoud Khalil <mahmoudkhalil11 gmail com>
Date:   Sat Jun 6 02:16:16 2020 +0200

    Adds history plugins shortcuts dynamically to the shortcuts dialog

 gitg/gitg-application.vala          | 38 ++++++++++++++++++++++++++++++++++++-
 gitg/gitg-window.vala               |  7 +++++++
 gitg/history/gitg-history.vala      |  9 +++++++--
 gitg/resources/ui/gitg-shortcuts.ui |  6 ++++++
 4 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/gitg/gitg-application.vala b/gitg/gitg-application.vala
index 527deddc..5b8c8e24 100644
--- a/gitg/gitg-application.vala
+++ b/gitg/gitg-application.vala
@@ -281,7 +281,24 @@ public class Application : Gtk.Application
                // Create shortcuts window if needed
                if (d_shortcuts == null)
                {
-                       d_shortcuts = Builder.load_object<Gtk.ShortcutsWindow>("ui/gitg-shortcuts.ui", 
"shortcuts-gitg");
+                       var shortcuts_ui_objects = GitgExt.UI.from_builder("ui/gitg-shortcuts.ui", 
"shortcuts-gitg", "history-shortcuts-group");
+                       d_shortcuts = (Gtk.ShortcutsWindow) shortcuts_ui_objects["shortcuts-gitg"];
+
+                       if(plugins_accel != null)
+                       {
+                               var history_shortcuts_group = (Gtk.ShortcutsGroup) 
shortcuts_ui_objects["history-shortcuts-group"];
+                               history_shortcuts_group.set_visible(true);
+
+                               foreach(var element in plugins_accel)
+                               {
+                                       var shortcut = (Gtk.ShortcutsShortcut) 
Object.new(typeof(Gtk.ShortcutsShortcut),
+                                                       "title", element.name,
+                                                       "accelerator", "<Alt>" + element.shortcut,
+                                                       null);
+                                       shortcut.set_visible(true);
+                                       history_shortcuts_group.add(shortcut);
+                               }
+                       }
 
                        d_shortcuts.destroy.connect((w) => {
                                d_shortcuts = null;
@@ -336,6 +353,14 @@ public class Application : Gtk.Application
                string[] accels;
        }
 
+       struct PluginAccel
+       {
+               string name;
+               string shortcut;
+       }
+
+       private List<PluginAccel?> plugins_accel;
+
        private void init_error(string msg)
        {
                var dlg = new Gtk.MessageDialog(null,
@@ -570,6 +595,17 @@ public class Application : Gtk.Application
                w.set_environment(app_command_line.get_environ());
                w.present(activity, command_lines);
        }
+
+       public void register_shortcut(string name, uint shortcut)
+       {
+               if(plugins_accel == null)
+               {
+                       plugins_accel = new List<PluginAccel?>();
+               }
+
+               PluginAccel plugin_accel = { name, Gdk.keyval_name(shortcut) };
+               plugins_accel.append(plugin_accel);
+       }
 }
 
 }
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index ca640d5b..6b623945 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -915,6 +915,13 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                                                                             extset,
                                                                             d_stack_activities);
 
+               var history_panels = ((GitgHistory.Activity) builtins[0]).d_panels;
+
+               foreach(var element in history_panels.get_available_elements())
+               {
+                       app.register_shortcut(element.display_name, element.shortcut);
+               };
+
                d_activities.notify["current"].connect(on_current_activity_changed);
 
                // Setup window geometry saving
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 8d063d06..02582e2e 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -58,7 +58,12 @@ namespace GitgHistory
                private string[] d_mainline;
                private bool d_ignore_external;
 
-               private Gitg.UIElements<GitgExt.HistoryPanel> d_panels;
+               private Gitg.UIElements<GitgExt.HistoryPanel> _d_panels;
+
+               public Gitg.UIElements<GitgExt.HistoryPanel> d_panels
+               {
+                       get { return _d_panels; }
+               }
 
                public Activity(GitgExt.Application application)
                {
@@ -600,7 +605,7 @@ namespace GitgHistory
                                                           "application",
                                                           application);
 
-                       d_panels = new Gitg.UIElements<GitgExt.HistoryPanel>(extset,
+                       _d_panels = new Gitg.UIElements<GitgExt.HistoryPanel>(extset,
                                                                             d_main.stack_panel);
 
                        d_refs_list_popup = new Gitg.PopupMenu(d_main.refs_list);
diff --git a/gitg/resources/ui/gitg-shortcuts.ui b/gitg/resources/ui/gitg-shortcuts.ui
index 23e477ef..5a415ab1 100644
--- a/gitg/resources/ui/gitg-shortcuts.ui
+++ b/gitg/resources/ui/gitg-shortcuts.ui
@@ -180,6 +180,12 @@
             </child>
           </object>
         </child>
+        <child>
+          <object class="GtkShortcutsGroup" id="history-shortcuts-group">
+            <property name="visible">false</property>
+            <property name="title" translatable="yes" context="shortcut window">History Activity</property>
+          </object>
+        </child>
       </object>
     </child>
   </object>


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