[gitg] Keep preferences and shorcuts after AppMenu removal



commit f73f7f57a9c28150752fa97f419bacaa9e43f431
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Thu Dec 20 00:52:56 2018 +0100

    Keep preferences and shorcuts after AppMenu removal

 gitg/gitg-application.vala          |  1 +
 gitg/gitg-window.vala               | 63 +++++++++++++++++++++++++++++++++++++
 gitg/resources/ui/gitg-menus.ui     | 12 +++++++
 gitg/resources/ui/gitg-shortcuts.ui |  7 +++++
 4 files changed, 83 insertions(+)
---
diff --git a/gitg/gitg-application.vala b/gitg/gitg-application.vala
index 6a37ceec..38d331b9 100644
--- a/gitg/gitg-application.vala
+++ b/gitg/gitg-application.vala
@@ -387,6 +387,7 @@ public class Application : Gtk.Application
                const Accel[] single_accels = {
                        {"app.new", "<Primary>N",},
                        {"app.quit", "<Primary>Q"},
+                       {"app.shortcuts", "<Shift><Primary>question"},
                        {"app.help", "F1"},
 
                        {"win.search", "<Primary>F"},
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 32be080b..36899c40 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -46,6 +46,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
        private RemoteManager d_remote_manager;
        private Notifications d_notifications;
+       private PreferencesDialog d_preferences;
+
+#if GTK_SHORTCUTS_WINDOW
+       private Gtk.ShortcutsWindow d_shortcuts;
+#endif
 
        // Widgets
        [GtkChild]
@@ -157,9 +162,16 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                {"close", on_close_activated},
                {"reload", on_reload_activated},
                {"author-details-repo", on_repo_author_details_activated},
+               {"preferences", on_preferences_activated},
                {"select", on_select_activated, null, "false", null}
        };
 
+#if GTK_SHORTCUTS_WINDOW
+       private const ActionEntry[] shortcut_window_entries = {
+               {"shortcuts", on_shortcuts_activated}
+       };
+#endif
+
        [GtkCallback]
        private void dash_button_clicked(Gtk.Button dash)
        {
@@ -269,6 +281,10 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
 
                add_action_entries(win_entries, this);
 
+#if GTK_SHORTCUTS_WINDOW
+               add_action_entries(shortcut_window_entries, this);
+#endif
+
                d_notifications = new Notifications(d_overlay);
 
                var selact = lookup_action("select");
@@ -695,6 +711,53 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                author_details.show();
        }
 
+       private void on_preferences_activated()
+       {
+               unowned List<Gtk.Window> wnds = application.get_windows();
+
+               // Create preferences dialog if needed
+               if (d_preferences == null)
+               {
+                       d_preferences = Builder.load_object<PreferencesDialog>("ui/gitg-preferences.ui", 
"preferences");
+
+                       d_preferences.destroy.connect((w) => {
+                               d_preferences = null;
+                       });
+               }
+
+               if (wnds != null)
+               {
+                       d_preferences.set_transient_for(wnds.data);
+               }
+
+               d_preferences.present();
+       }
+
+       private void on_shortcuts_activated()
+       {
+#if GTK_SHORTCUTS_WINDOW
+
+               unowned List<Gtk.Window> wnds = application.get_windows();
+
+               // Create shortcuts window if needed
+               if (d_shortcuts == null)
+               {
+                       d_shortcuts = Builder.load_object<Gtk.ShortcutsWindow>("ui/gitg-shortcuts.ui", 
"shortcuts-gitg");
+
+                       d_shortcuts.destroy.connect((w) => {
+                               d_shortcuts = null;
+                       });
+               }
+
+               if (wnds != null)
+               {
+                       d_shortcuts.set_transient_for(wnds.data);
+               }
+
+               d_shortcuts.present();
+#endif
+       }
+
        private void on_current_activity_changed()
        {
                notify_property("current_activity");
diff --git a/gitg/resources/ui/gitg-menus.ui b/gitg/resources/ui/gitg-menus.ui
index 5e6e8f4e..23bb77fe 100644
--- a/gitg/resources/ui/gitg-menus.ui
+++ b/gitg/resources/ui/gitg-menus.ui
@@ -8,12 +8,24 @@
         <attribute name="action">win.reload</attribute>
       </item>
     </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Preferences</attribute>
+        <attribute name="action">win.preferences</attribute>
+      </item>
+    </section>
     <section>
       <item>
         <attribute name="label" translatable="yes">_Author Details</attribute>
         <attribute name="action">win.author-details-repo</attribute>
       </item>
     </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
+        <attribute name="action">app.shortcuts</attribute>
+      </item>
+    </section>
   </menu>
    <menu id="win-menu-dash">
     <section>
diff --git a/gitg/resources/ui/gitg-shortcuts.ui b/gitg/resources/ui/gitg-shortcuts.ui
index 825bc162..48574bf1 100644
--- a/gitg/resources/ui/gitg-shortcuts.ui
+++ b/gitg/resources/ui/gitg-shortcuts.ui
@@ -12,6 +12,13 @@
           <object class="GtkShortcutsGroup">
             <property name="visible">1</property>
             <property name="title" translatable="yes" context="shortcut window">Windows</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;primary&gt;&lt;shift&gt;question</property>
+                <property name="title" translatable="yes" context="shortcut window">Open shortcut 
window</property>
+              </object>
+            </child>
             <child>
               <object class="GtkShortcutsShortcut">
                 <property name="visible">1</property>


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