[sysprof/wip/chergert/sysprof-3] sysprof: make escape stop the current profiler



commit a99af4c1a581299f78b69f6f939adfe9d33ee04e
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 20 18:26:25 2019 -0700

    sysprof: make escape stop the current profiler

 src/libsysprof-ui/sysprof-display.c | 15 ++++++++++++---
 src/libsysprof-ui/sysprof-display.h | 18 ++++++++++--------
 src/sysprof/sysprof-window.c        | 24 ++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 11 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c
index c6ebd18..9776b04 100644
--- a/src/libsysprof-ui/sysprof-display.c
+++ b/src/libsysprof-ui/sysprof-display.c
@@ -254,13 +254,11 @@ stop_recording_cb (GSimpleAction *action,
                    gpointer       user_data)
 {
   SysprofDisplay *self = user_data;
-  SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
 
   g_assert (G_IS_SIMPLE_ACTION (action));
   g_assert (SYSPROF_IS_DISPLAY (self));
 
-  if (priv->profiler != NULL)
-    sysprof_profiler_stop (priv->profiler);
+  sysprof_display_stop_recording (self);
 }
 
 static void
@@ -572,3 +570,14 @@ sysprof_display_get_can_save (SysprofDisplay *self)
 
   return sysprof_capture_view_get_reader (priv->capture_view) != NULL;
 }
+
+void
+sysprof_display_stop_recording (SysprofDisplay *self)
+{
+  SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
+
+  g_return_if_fail (SYSPROF_IS_DISPLAY (self));
+
+  if (priv->profiler != NULL)
+    sysprof_profiler_stop (priv->profiler);
+}
diff --git a/src/libsysprof-ui/sysprof-display.h b/src/libsysprof-ui/sysprof-display.h
index ce59db8..fbfc697 100644
--- a/src/libsysprof-ui/sysprof-display.h
+++ b/src/libsysprof-ui/sysprof-display.h
@@ -41,19 +41,21 @@ struct _SysprofDisplayClass
 } __attribute__((aligned(8)));
 
 SYSPROF_AVAILABLE_IN_ALL
-GtkWidget       *sysprof_display_new          (void);
+GtkWidget       *sysprof_display_new            (void);
 SYSPROF_AVAILABLE_IN_ALL
-gchar           *sysprof_display_dup_title    (SysprofDisplay *self);
+gchar           *sysprof_display_dup_title      (SysprofDisplay *self);
 SYSPROF_AVAILABLE_IN_ALL
-SysprofProfiler *sysprof_display_get_profiler (SysprofDisplay *self);
+SysprofProfiler *sysprof_display_get_profiler   (SysprofDisplay *self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean         sysprof_display_is_empty     (SysprofDisplay *self);
+gboolean         sysprof_display_is_empty       (SysprofDisplay *self);
 SYSPROF_AVAILABLE_IN_ALL
-void             sysprof_display_open         (SysprofDisplay *self,
-                                               GFile          *file);
+void             sysprof_display_open           (SysprofDisplay *self,
+                                                 GFile          *file);
 SYSPROF_AVAILABLE_IN_ALL
-void             sysprof_display_save         (SysprofDisplay *self);
+void             sysprof_display_save           (SysprofDisplay *self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean         sysprof_display_get_can_save (SysprofDisplay *self);
+gboolean         sysprof_display_get_can_save   (SysprofDisplay *self);
+SYSPROF_AVAILABLE_IN_ALL
+void             sysprof_display_stop_recording (SysprofDisplay *self);
 
 G_END_DECLS
diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c
index 04a44fb..85cf4be 100644
--- a/src/sysprof/sysprof-window.c
+++ b/src/sysprof/sysprof-window.c
@@ -133,6 +133,21 @@ save_capture_cb (GSimpleAction *action,
   sysprof_notebook_save (self->notebook);
 }
 
+static void
+stop_recording_cb (GSimpleAction *action,
+                   GVariant      *param,
+                   gpointer       user_data)
+{
+  SysprofWindow *self = user_data;
+  SysprofDisplay *current;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (SYSPROF_IS_WINDOW (self));
+
+  if ((current = sysprof_notebook_get_current (self->notebook)))
+    sysprof_display_stop_recording (current);
+}
+
 static void
 sysprof_window_finalize (GObject *object)
 {
@@ -164,11 +179,13 @@ sysprof_window_class_init (SysprofWindowClass *klass)
 static void
 sysprof_window_init (SysprofWindow *self)
 {
+  DzlShortcutController *controller;
   static GActionEntry actions[] = {
     { "close-tab", close_tab_cb },
     { "new-tab", new_tab_cb },
     { "switch-tab", switch_tab_cb, "i" },
     { "save-capture", save_capture_cb },
+    { "stop-recording", stop_recording_cb },
   };
 
   gtk_widget_init_template (GTK_WIDGET (self));
@@ -189,6 +206,13 @@ sysprof_window_init (SysprofWindow *self)
   g_object_bind_property (self->notebook, "current", self->bindings, "source",
                           G_BINDING_SYNC_CREATE);
 
+  controller = dzl_shortcut_controller_find (GTK_WIDGET (self));
+  dzl_shortcut_controller_add_command_action (controller,
+                                              "org.gnome.sysprof3.stop-recording",
+                                              "Escape",
+                                              DZL_SHORTCUT_PHASE_BUBBLE,
+                                              "win.stop-recording");
+
   dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "save-capture",
                              "enabled", FALSE,
                              NULL);


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