[sysprof/wip/visualizers] help-overlay: add help overlay to SpWindow and app menu



commit 527f95fa77ca782e180e3bf725b4608544711566
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 8 15:09:38 2016 -0700

    help-overlay: add help overlay to SpWindow and app menu
    
    This adds an app menu and window action to activate the keyboard
    shortcuts overlay.

 src/resources/gtk/help-overlay.ui   |   82 +++++++++++++++++++++++++++++++++++
 src/resources/gtk/menus.ui          |    4 ++
 src/resources/sysprof.gresource.xml |    1 +
 src/sp-application.c                |   47 ++++++++++++++++++--
 4 files changed, 129 insertions(+), 5 deletions(-)
---
diff --git a/src/resources/gtk/help-overlay.ui b/src/resources/gtk/help-overlay.ui
new file mode 100644
index 0000000..a08fa8e
--- /dev/null
+++ b/src/resources/gtk/help-overlay.ui
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkShortcutsWindow" id="help_overlay">
+    <child>
+      <object class="GtkShortcutsSection">
+        <property name="visible">1</property>
+        <property name="section-name">sysprof</property>
+        <property name="title" translatable="yes" context="shortcut window">Sysprof Shortcuts</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes" context="shortcut window">Recording</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="title" translatable="yes" context="shortcut window">Stop recording</property>
+                <property name="accelerator">Escape</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes" context="shortcut window">Callgraph</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="title" translatable="yes" context="shortcut window">Expand 
function</property>
+                <property name="subtitle" translatable="yes" context="shortcut window">Shows the direct 
descendants of the callgraph function</property>
+                <property name="accelerator">Right</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="title" translatable="yes" context="shortcut window">Collapse 
function</property>
+                <property name="subtitle" translatable="yes" context="shortcut window">Hides all callgraph 
descendants below the selected function</property>
+                <property name="accelerator">Left</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="title" translatable="yes" context="shortcut window">Jump into 
function</property>
+                <property name="subtitle" translatable="yes" context="shortcut window">Selects the function 
or file as the top of the callgraph</property>
+                <property name="accelerator">Return</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">1</property>
+            <property name="title" translatable="yes" context="shortcut window">Visualizers</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="title" translatable="yes" context="shortcut window">Zoom in</property>
+                <property name="accelerator">&lt;primary&gt;plus</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="title" translatable="yes" context="shortcut window">Zoom out</property>
+                <property name="accelerator">&lt;primary&gt;minus</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">1</property>
+                <property name="title" translatable="yes" context="shortcut window">Reset zoom</property>
+                <property name="accelerator">&lt;primary&gt;0</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index 095f4d3..ccdbb94 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -23,6 +23,10 @@
         <attribute name="action">app.help</attribute>
       </item>
       <item>
+        <attribute name="label" translatable="yes">Keyboard Shortcuts</attribute>
+        <attribute name="action">app.show-help-overlay</attribute>
+      </item>
+      <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
       </item>
diff --git a/src/resources/sysprof.gresource.xml b/src/resources/sysprof.gresource.xml
index b6735f3..644667b 100644
--- a/src/resources/sysprof.gresource.xml
+++ b/src/resources/sysprof.gresource.xml
@@ -3,6 +3,7 @@
   <gresource prefix="/org/gnome/sysprof">
     <!-- Automatic GTK resources -->
     <file>gtk/menus.ui</file>
+    <file>gtk/help-overlay.ui</file>
 
     <!-- Application icons -->
     <file alias="icons/16x16/apps/sysprof.png">../../data/icons/16x16/apps/sysprof.png</file>
diff --git a/src/sp-application.c b/src/sp-application.c
index 4efe88e..17b1d0d 100644
--- a/src/sp-application.c
+++ b/src/sp-application.c
@@ -264,14 +264,51 @@ sysprof_open_capture (GSimpleAction *action,
 }
 
 static void
+sysprof_show_help_overlay (GSimpleAction *action,
+                           GVariant      *variant,
+                           gpointer       user_data)
+{
+  GtkApplication *app = user_data;
+  SpWindow *window = NULL;
+
+  g_assert (G_IS_APPLICATION (app));
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (variant == NULL);
+
+  for (GList *list = gtk_application_get_windows (app); list; list = list->next)
+    {
+      GtkWindow *element = list->data;
+
+      if (SP_IS_WINDOW (element))
+        {
+          window = SP_WINDOW (element);
+          break;
+        }
+    }
+
+  if (window == NULL)
+    {
+      window = g_object_new (SP_TYPE_WINDOW,
+                             "application", app,
+                             NULL);
+      gtk_window_present (GTK_WINDOW (window));
+    }
+
+  g_assert (g_action_group_has_action (G_ACTION_GROUP (window), "show-help-overlay"));
+
+  g_action_group_activate_action (G_ACTION_GROUP (window), "show-help-overlay", NULL);
+}
+
+static void
 sp_application_init (SpApplication *self)
 {
   static const GActionEntry actions[] = {
-    { "about",        sysprof_about },
-    { "new-window",   sysprof_new_window },
-    { "open-capture", sysprof_open_capture },
-    { "help",         sysprof_help },
-    { "quit",         sysprof_quit },
+    { "about",             sysprof_about },
+    { "new-window",        sysprof_new_window },
+    { "open-capture",      sysprof_open_capture },
+    { "help",              sysprof_help },
+    { "show-help-overlay", sysprof_show_help_overlay },
+    { "quit",              sysprof_quit },
   };
 
   g_action_map_add_action_entries (G_ACTION_MAP (self), actions, G_N_ELEMENTS (actions), self);


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