[gnome-builder/wip/chergert/visualizers] sysprof: wire up zoom controls to workbench header
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/visualizers] sysprof: wire up zoom controls to workbench header
- Date: Mon, 10 Oct 2016 00:37:47 +0000 (UTC)
commit d5cd19efe2bb54bf3af36616bcf8de7711527ea0
Author: Christian Hergert <chergert redhat com>
Date: Sun Oct 9 17:37:22 2016 -0700
sysprof: wire up zoom controls to workbench header
plugins/sysprof/gbp-sysprof-perspective.c | 10 +++
plugins/sysprof/gbp-sysprof-perspective.h | 11 ++--
plugins/sysprof/gbp-sysprof-perspective.ui | 3 +
plugins/sysprof/gbp-sysprof-workbench-addin.c | 84 ++++++++++++++++++++++++-
4 files changed, 100 insertions(+), 8 deletions(-)
---
diff --git a/plugins/sysprof/gbp-sysprof-perspective.c b/plugins/sysprof/gbp-sysprof-perspective.c
index bbe51f0..84f1f58 100644
--- a/plugins/sysprof/gbp-sysprof-perspective.c
+++ b/plugins/sysprof/gbp-sysprof-perspective.c
@@ -32,6 +32,7 @@ struct _GbpSysprofPerspective
SpCallgraphView *callgraph_view;
SpVisualizerView *visualizers;
SpRecordingStateView *recording_view;
+ SpZoomManager *zoom_manager;
};
static void perspective_iface_init (IdePerspectiveInterface *iface);
@@ -49,6 +50,7 @@ gbp_sysprof_perspective_class_init (GbpSysprofPerspectiveClass *klass)
gtk_widget_class_bind_template_child (widget_class, GbpSysprofPerspective, stack);
gtk_widget_class_bind_template_child (widget_class, GbpSysprofPerspective, recording_view);
gtk_widget_class_bind_template_child (widget_class, GbpSysprofPerspective, visualizers);
+ gtk_widget_class_bind_template_child (widget_class, GbpSysprofPerspective, zoom_manager);
g_type_ensure (SP_TYPE_CALLGRAPH_VIEW);
g_type_ensure (SP_TYPE_CPU_VISUALIZER_ROW);
@@ -164,3 +166,11 @@ gbp_sysprof_perspective_set_profiler (GbpSysprofPerspective *self,
/* TODO: Wire up failure state */
}
}
+
+SpZoomManager *
+gbp_sysprof_perspective_get_zoom_manager (GbpSysprofPerspective *self)
+{
+ g_return_val_if_fail (GBP_IS_SYSPROF_PERSPECTIVE (self), NULL);
+
+ return self->zoom_manager;
+}
diff --git a/plugins/sysprof/gbp-sysprof-perspective.h b/plugins/sysprof/gbp-sysprof-perspective.h
index 7aff7ab..b61272b 100644
--- a/plugins/sysprof/gbp-sysprof-perspective.h
+++ b/plugins/sysprof/gbp-sysprof-perspective.h
@@ -20,7 +20,7 @@
#define GBP_SYSPROF_PERSPECTIVE_H
#include <ide.h>
-#include <sysprof.h>
+#include <sysprof-ui.h>
G_BEGIN_DECLS
@@ -28,10 +28,11 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpSysprofPerspective, gbp_sysprof_perspective, GBP, SYSPROF_PERSPECTIVE, GtkBin)
-void gbp_sysprof_perspective_set_profiler (GbpSysprofPerspective *self,
- SpProfiler *profiler);
-void gbp_sysprof_perspective_set_reader (GbpSysprofPerspective *self,
- SpCaptureReader *reader);
+SpZoomManager *gbp_sysprof_perspective_get_zoom_manager (GbpSysprofPerspective *self);
+void gbp_sysprof_perspective_set_profiler (GbpSysprofPerspective *self,
+ SpProfiler *profiler);
+void gbp_sysprof_perspective_set_reader (GbpSysprofPerspective *self,
+ SpCaptureReader *reader);
G_END_DECLS
diff --git a/plugins/sysprof/gbp-sysprof-perspective.ui b/plugins/sysprof/gbp-sysprof-perspective.ui
index 1b7afc0..6d1ac2b 100644
--- a/plugins/sysprof/gbp-sysprof-perspective.ui
+++ b/plugins/sysprof/gbp-sysprof-perspective.ui
@@ -28,6 +28,7 @@
<child>
<object class="SpVisualizerView" id="visualizers">
<property name="visible">true</property>
+ <property name="zoom-manager">zoom_manager</property>
<child type="visualizer">
<object class="SpCpuVisualizerRow" id="cpu_visualizer">
<property name="title" translatable="yes">CPU</property>
@@ -54,4 +55,6 @@
</object>
</child>
</template>
+ <object class="SpZoomManager" id="zoom_manager">
+ </object>
</interface>
diff --git a/plugins/sysprof/gbp-sysprof-workbench-addin.c b/plugins/sysprof/gbp-sysprof-workbench-addin.c
index 1788d8d..8dfe35a 100644
--- a/plugins/sysprof/gbp-sysprof-workbench-addin.c
+++ b/plugins/sysprof/gbp-sysprof-workbench-addin.c
@@ -31,6 +31,8 @@ struct _GbpSysprofWorkbenchAddin
GbpSysprofPerspective *perspective;
IdeWorkbench *workbench;
+
+ GtkBox *zoom_controls;
};
static void workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface);
@@ -344,13 +346,27 @@ run_manager_stopped (GbpSysprofWorkbenchAddin *self,
sp_profiler_stop (self->profiler);
}
+static gboolean
+zoom_level_to_string (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ gdouble level = g_value_get_double (from_value);
+ g_value_take_string (to_value, g_strdup_printf ("%d%%", (gint)(level * 100.0)));
+ return TRUE;
+}
+
static void
gbp_sysprof_workbench_addin_load (IdeWorkbenchAddin *addin,
IdeWorkbench *workbench)
{
GbpSysprofWorkbenchAddin *self = (GbpSysprofWorkbenchAddin *)addin;
+ IdeWorkbenchHeaderBar *header;
+ SpZoomManager *zoom_manager;
IdeRunManager *run_manager;
IdeContext *context;
+ GtkLabel *label;
g_assert (GBP_IS_SYSPROF_WORKBENCH_ADDIN (self));
g_assert (IDE_IS_WORKBENCH (workbench));
@@ -385,14 +401,57 @@ gbp_sysprof_workbench_addin_load (IdeWorkbenchAddin *addin,
NULL);
ide_workbench_add_perspective (workbench, IDE_PERSPECTIVE (self->perspective));
+ zoom_manager = gbp_sysprof_perspective_get_zoom_manager (self->perspective);
/*
* Add our actions to the workbench so they can be activated via the
* headerbar or the perspective.
*/
- gtk_widget_insert_action_group (GTK_WIDGET (workbench),
- "profiler",
- G_ACTION_GROUP (self->actions));
+ gtk_widget_insert_action_group (GTK_WIDGET (workbench), "profiler", G_ACTION_GROUP (self->actions));
+ gtk_widget_insert_action_group (GTK_WIDGET (workbench), "profiler-zoom", G_ACTION_GROUP (zoom_manager));
+
+ /*
+ * Add our buttons to the header.
+ */
+ header = ide_workbench_get_headerbar (workbench);
+ self->zoom_controls = g_object_new (GTK_TYPE_BOX,
+ "orientation", GTK_ORIENTATION_HORIZONTAL,
+ NULL);
+ ide_widget_add_style_class (GTK_WIDGET (self->zoom_controls), "linked");
+ gtk_container_add (GTK_CONTAINER (self->zoom_controls),
+ g_object_new (GTK_TYPE_BUTTON,
+ "action-name", "profiler-zoom.zoom-out",
+ "can-focus", FALSE,
+ "child", g_object_new (GTK_TYPE_IMAGE,
+ "icon-name", "zoom-out-symbolic",
+ "visible", TRUE,
+ NULL),
+ "visible", TRUE,
+ NULL));
+ label = g_object_new (GTK_TYPE_LABEL,
+ "width-chars", 5,
+ "visible", TRUE,
+ NULL);
+ g_object_bind_property_full (zoom_manager, "zoom", label, "label", G_BINDING_SYNC_CREATE,
+ zoom_level_to_string, NULL, NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (self->zoom_controls),
+ g_object_new (GTK_TYPE_BUTTON,
+ "action-name", "profiler-zoom.zoom-one",
+ "can-focus", FALSE,
+ "child", label,
+ "visible", TRUE,
+ NULL));
+ gtk_container_add (GTK_CONTAINER (self->zoom_controls),
+ g_object_new (GTK_TYPE_BUTTON,
+ "action-name", "profiler-zoom.zoom-in",
+ "can-focus", FALSE,
+ "child", g_object_new (GTK_TYPE_IMAGE,
+ "icon-name", "zoom-in-symbolic",
+ "visible", TRUE,
+ NULL),
+ "visible", TRUE,
+ NULL));
+ ide_workbench_header_bar_insert_left (header, GTK_WIDGET (self->zoom_controls), GTK_PACK_START, 100);
}
static void
@@ -413,13 +472,32 @@ gbp_sysprof_workbench_addin_unload (IdeWorkbenchAddin *addin,
ide_workbench_remove_perspective (workbench, IDE_PERSPECTIVE (self->perspective));
+ gtk_widget_destroy (GTK_WIDGET (self->zoom_controls));
+
+ self->zoom_controls = NULL;
self->perspective = NULL;
self->workbench = NULL;
}
static void
+gbp_sysprof_workbench_addin_perspective_set (IdeWorkbenchAddin *addin,
+ IdePerspective *perspective)
+{
+ GbpSysprofWorkbenchAddin *self = (GbpSysprofWorkbenchAddin *)addin;
+ gboolean visible;
+
+ g_assert (IDE_IS_WORKBENCH_ADDIN (addin));
+ g_assert (IDE_IS_PERSPECTIVE (perspective));
+
+ visible = GBP_IS_SYSPROF_PERSPECTIVE (perspective);
+
+ gtk_widget_set_visible (GTK_WIDGET (self->zoom_controls), visible);
+}
+
+static void
workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
{
iface->load = gbp_sysprof_workbench_addin_load;
iface->unload = gbp_sysprof_workbench_addin_unload;
+ iface->perspective_set = gbp_sysprof_workbench_addin_perspective_set;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]