[devhelp] general: add a shortcut window



commit a75d010ad49012f302a44551cc216e54288cdae8
Author: Frédéric Péters <fpeters 0d be>
Date:   Wed Jan 27 11:19:59 2016 +0100

    general: add a shortcut window
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757877

 po/POTFILES.in       |    1 +
 src/devhelp-menu.ui  |    4 ++
 src/dh-app.c         |   42 ++++++++++++++++++
 src/dh.gresource.xml |    1 +
 src/help-overlay.ui  |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 165 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8fd840a..72ed081 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ data/org.gnome.Devhelp.desktop.in.in
 misc/gedit-plugin/devhelp.plugin.desktop.in
 misc/gedit-plugin/devhelp.py
 [type: gettext/glade]src/devhelp-menu.ui
+[type: gettext/glade]src/help-overlay.ui
 src/dh-app.c
 src/dh-assistant.c
 [type: gettext/glade]src/dh-assistant.ui
diff --git a/src/devhelp-menu.ui b/src/devhelp-menu.ui
index eba5cd6..9cf1ca8 100644
--- a/src/devhelp-menu.ui
+++ b/src/devhelp-menu.ui
@@ -38,6 +38,10 @@
     </section>
     <section>
       <item>
+        <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
+        <attribute name="action">app.shortcuts</attribute>
+      </item>
+      <item>
         <attribute name="label" translatable="yes">_About</attribute>
         <attribute name="action">app.about</attribute>
       </item>
diff --git a/src/dh-app.c b/src/dh-app.c
index 3c7186e..03bc07a 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -186,6 +186,42 @@ preferences_cb (GSimpleAction *action,
 }
 
 static void
+shortcuts_cb (GSimpleAction *action,
+              GVariant      *parameter,
+              gpointer       user_data)
+{
+        DhApp *app = DH_APP (user_data);
+        static GtkWidget *shortcuts_window;
+        GtkWindow *window;
+
+        window = dh_app_peek_first_window (app);
+
+        if (shortcuts_window == NULL)
+        {
+                GtkBuilder *builder;
+
+                builder = gtk_builder_new_from_resource ("/org/gnome/devhelp/help-overlay.ui");
+                shortcuts_window = GTK_WIDGET (gtk_builder_get_object (builder, "help_overlay"));
+
+                g_signal_connect (shortcuts_window,
+                                  "destroy",
+                                  G_CALLBACK (gtk_widget_destroyed),
+                                  &shortcuts_window);
+
+                g_object_unref (builder);
+        }
+
+        if (GTK_WINDOW (window) != gtk_window_get_transient_for (GTK_WINDOW (shortcuts_window)))
+        {
+                gtk_window_set_transient_for (GTK_WINDOW (shortcuts_window), GTK_WINDOW (window));
+        }
+
+        gtk_widget_show_all (shortcuts_window);
+        gtk_window_present (GTK_WINDOW (shortcuts_window));
+}
+
+
+static void
 about_cb (GSimpleAction *action,
           GVariant      *parameter,
           gpointer       user_data)
@@ -300,6 +336,7 @@ static GActionEntry app_entries[] = {
         /* general  actions */
         { "new-window",       new_window_cb,       NULL, NULL, NULL },
         { "preferences",      preferences_cb,      NULL, NULL, NULL },
+        { "shortcuts",        shortcuts_cb,        NULL, NULL, NULL },
         { "about",            about_cb,            NULL, NULL, NULL },
         { "quit",             quit_cb,             NULL, NULL, NULL },
         /* additional commandline-specific actions */
@@ -345,6 +382,9 @@ setup_accelerators (DhApp *self)
         accels[0] = "F10";
         gtk_application_set_accels_for_action (GTK_APPLICATION (self), "win.gear-menu", accels);
 
+        accels[0] = "<Primary>F1";
+        gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.shortcuts", accels);
+
         accels[0] = "<Alt>Right";
         accels[1] = "Forward";
         gtk_application_set_accels_for_action (GTK_APPLICATION (self), "win.go-forward", accels);
@@ -367,6 +407,8 @@ dh_app_startup (GApplication *application)
         DhApp *app = DH_APP (application);
         DhAppPrivate *priv = dh_app_get_instance_private (app);
 
+        g_application_set_resource_base_path (application, "/org/gnome/devhelp");
+
         /* Chain up parent's startup */
         G_APPLICATION_CLASS (dh_app_parent_class)->startup (application);
 
diff --git a/src/dh.gresource.xml b/src/dh.gresource.xml
index b2360eb..269ffd7 100644
--- a/src/dh.gresource.xml
+++ b/src/dh.gresource.xml
@@ -5,5 +5,6 @@
     <file preprocess="xml-stripblanks">dh-assistant.ui</file>
     <file preprocess="xml-stripblanks">dh-window.ui</file>
     <file preprocess="xml-stripblanks">dh-preferences.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">help-overlay.ui</file>
   </gresource>
 </gresources>
diff --git a/src/help-overlay.ui b/src/help-overlay.ui
new file mode 100644
index 0000000..0c0bb48
--- /dev/null
+++ b/src/help-overlay.ui
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.19"/>
+  <object class="GtkShortcutsWindow" id="help_overlay">
+    <property name="modal">1</property>
+    <child>
+      <object class="GtkShortcutsSection">
+        <property name="visible">1</property>
+        <property name="section-name">shortcuts</property>
+        <property name="max-height">10</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes">General</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;K</property>
+                <property name="title" translatable="yes">Focus global search</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;F</property>
+                <property name="title" translatable="yes">Find in current page</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;N</property>
+                <property name="title" translatable="yes">Open a new window</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;T</property>
+                <property name="title" translatable="yes">Open a new tab</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;F9</property>
+                <property name="title" translatable="yes">Toggle sidebar visibility</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;alt&gt;Left</property>
+                <property name="title" translatable="yes">Go back</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;alt&gt;Right</property>
+                <property name="title" translatable="yes">Go forward</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;P</property>
+                <property name="title" translatable="yes">Print</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;W</property>
+                <property name="title" translatable="yes">Close the current window</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;Primary&gt;Q</property>
+                <property name="title" translatable="yes">Close all windows</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes">Zoom</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;plus</property>
+                <property name="title" translatable="yes">Zoom in</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;minus</property>
+                <property name="title" translatable="yes">Zoom out</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="accelerator">&lt;ctrl&gt;0</property>
+                <property name="title" translatable="yes">Reset Zoom</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>


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