libsysprof-ui: wire up can-save propagation

This commit is contained in:
Christian Hergert
2019-05-19 11:26:07 -07:00
parent a7b18281e6
commit 688b6a2189
3 changed files with 73 additions and 0 deletions

View File

@ -52,6 +52,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (SysprofDisplay, sysprof_display, GTK_TYPE_BIN)
enum {
PROP_0,
PROP_CAN_SAVE,
PROP_RECORDING,
PROP_TITLE,
N_PROPS
@ -124,6 +125,7 @@ sysprof_display_profiler_stopped_cb (SysprofDisplay *self,
}
notify:
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_SAVE]);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RECORDING]);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
}
@ -274,6 +276,10 @@ sysprof_display_get_property (GObject *object,
switch (prop_id)
{
case PROP_CAN_SAVE:
g_value_set_boolean (value, sysprof_display_get_can_save (self));
break;
case PROP_RECORDING:
g_value_set_boolean (value, sysprof_display_get_is_recording (self));
break;
@ -312,6 +318,13 @@ sysprof_display_class_init (SysprofDisplayClass *klass)
widget_class->parent_set = sysprof_display_parent_set;
properties [PROP_CAN_SAVE] =
g_param_spec_boolean ("can-save",
"Can Save",
"If the display can save a recording",
FALSE,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_RECORDING] =
g_param_spec_boolean ("recording",
"Recording",
@ -536,3 +549,13 @@ sysprof_display_save (SysprofDisplay *self)
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
}
gboolean
sysprof_display_get_can_save (SysprofDisplay *self)
{
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE);
return sysprof_capture_view_get_reader (priv->capture_view) != NULL;
}

View File

@ -53,5 +53,7 @@ void sysprof_display_open (SysprofDisplay *self,
GFile *file);
SYSPROF_AVAILABLE_IN_ALL
void sysprof_display_save (SysprofDisplay *self);
SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_display_get_can_save (SysprofDisplay *self);
G_END_DECLS

View File

@ -22,6 +22,7 @@
#include "config.h"
#include <dazzle.h>
#include <glib/gi18n.h>
#include <sysprof-ui.h>
@ -30,6 +31,9 @@
struct _SysprofWindow
{
GtkApplicationWindow parent_instance;
DzlBindingGroup *display_bindings;
SysprofNotebook *notebook;
GtkMenuButton *menu_button;
};
@ -117,11 +121,40 @@ save_capture_cb (GSimpleAction *action,
sysprof_notebook_save (self->notebook);
}
static void
sysprof_window_switch_page_cb (SysprofWindow *self,
GtkWidget *widget,
guint page_num,
SysprofNotebook *notebook)
{
SysprofDisplay *current;
g_assert (SYSPROF_IS_WINDOW (self));
g_assert (SYSPROF_IS_NOTEBOOK (notebook));
current = sysprof_notebook_get_current (notebook);
dzl_binding_group_set_source (self->display_bindings, current);
}
static void
sysprof_window_finalize (GObject *object)
{
SysprofWindow *self = SYSPROF_WINDOW (object);
dzl_binding_group_set_source (self->display_bindings, NULL);
g_clear_object (&self->display_bindings);
G_OBJECT_CLASS (sysprof_window_parent_class)->finalize (object);
}
static void
sysprof_window_class_init (SysprofWindowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = sysprof_window_finalize;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-window.ui");
gtk_widget_class_bind_template_child (widget_class, SysprofWindow, menu_button);
gtk_widget_class_bind_template_child (widget_class, SysprofWindow, notebook);
@ -134,6 +167,7 @@ sysprof_window_class_init (SysprofWindowClass *klass)
static void
sysprof_window_init (SysprofWindow *self)
{
GAction *action;
static GActionEntry actions[] = {
{ "close-tab", close_tab_cb },
{ "new-tab", new_tab_cb },
@ -147,6 +181,20 @@ sysprof_window_init (SysprofWindow *self)
actions,
G_N_ELEMENTS (actions),
self);
action = g_action_map_lookup_action (G_ACTION_MAP (self), "save-capture");
self->display_bindings = dzl_binding_group_new ();
dzl_binding_group_bind (self->display_bindings, "can-save", action, "enabled", G_BINDING_SYNC_CREATE);
g_signal_connect_object (self->notebook,
"switch-page",
G_CALLBACK (sysprof_window_switch_page_cb),
self,
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "save-capture",
"enabled", FALSE,
NULL);
}
void