inspector: Improve details buttons

Ensure that the details buttons are only sensitive when
we actually have details to show.
This commit is contained in:
Matthias Clasen 2014-10-24 21:52:23 -04:00
parent 70c3241bd3
commit a46d4e51f7
6 changed files with 41 additions and 3 deletions

View File

@ -124,8 +124,7 @@ on_selection_changed (GtkTreeSelection *selection,
GObject *object;
object = gtk_inspector_object_tree_get_selected (wt);
if (object)
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
}

View File

@ -224,6 +224,39 @@ row_activated (GtkTreeView *treeview,
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->buttons), "details");
}
static gboolean
can_show_details (GtkInspectorResourceList *rl)
{
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
gchar *path;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (rl->priv->tree));
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return FALSE;
gtk_tree_model_get (GTK_TREE_MODEL (rl->priv->model), &iter,
COLUMN_PATH, &path,
-1);
if (g_str_has_suffix (path, "/"))
{
g_free (path);
return FALSE;
}
g_free (path);
return TRUE;
}
static void
on_selection_changed (GtkTreeSelection *selection,
GtkInspectorResourceList *rl)
{
gtk_widget_set_sensitive (rl->priv->open_details_button, can_show_details (rl));
}
static void
open_details (GtkWidget *button,
GtkInspectorResourceList *sl)
@ -265,6 +298,7 @@ visible_child_name_changed (GObject *obj, GParamSpec *pspec, GtkInspectorResourc
resources_visible = g_strcmp0 (child, "resources") == 0;
gtk_widget_set_visible (sl->priv->buttons, resources_visible);
gtk_widget_set_sensitive (sl->priv->open_details_button, can_show_details (sl));
}
static void
@ -439,6 +473,7 @@ gtk_inspector_resource_list_class_init (GtkInspectorResourceListClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorResourceList, tree);
gtk_widget_class_bind_template_callback (widget_class, row_activated);
gtk_widget_class_bind_template_callback (widget_class, on_selection_changed);
}
// vim: set et sw=2 ts=2:

View File

@ -31,6 +31,7 @@
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">single</property>
<signal name="changed" handler="on_selection_changed"/>
</object>
</child>
<child>

View File

@ -100,6 +100,7 @@ on_object_selected (GtkInspectorObjectTree *wt,
GObject *selected,
GtkInspectorWindow *iw)
{
gtk_widget_set_sensitive (iw->object_details_button, selected != NULL);
if (GTK_IS_WIDGET (selected))
gtk_inspector_flash_widget (iw, GTK_WIDGET (selected));
}
@ -176,6 +177,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_tree);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_details);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_buttons);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_details_button);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, select_object);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, prop_list);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, child_prop_list);

View File

@ -47,6 +47,7 @@ typedef struct
GtkWidget *object_id;
GtkWidget *object_details;
GtkWidget *object_buttons;
GtkWidget *object_details_button;
GtkWidget *select_object;
GtkWidget *prop_list;
GtkWidget *child_prop_list;

View File

@ -34,7 +34,7 @@
<object class="GtkStack" id="object_buttons">
<property name="visible">True</property>
<child>
<object class="GtkButton">
<object class="GtkButton" id="object_details_button">
<property name="visible">True</property>
<property name="tooltip-text" translatable="yes">Show Details</property>
<property name="halign">center</property>