diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-10-24 21:52:23 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-10-24 21:52:23 -0400 |
commit | a46d4e51f783ef23f92728daf3a3c29c2e3c4805 (patch) | |
tree | 987840ad29749aec2414a166f492a14188783a88 | |
parent | 70c3241bd3a4fe15c7cf9bd86a21d753f4ef1b35 (diff) | |
download | gtk+-a46d4e51f783ef23f92728daf3a3c29c2e3c4805.tar.gz |
inspector: Improve details buttons
Ensure that the details buttons are only sensitive when
we actually have details to show.
-rw-r--r-- | gtk/inspector/object-tree.c | 3 | ||||
-rw-r--r-- | gtk/inspector/resource-list.c | 35 | ||||
-rw-r--r-- | gtk/inspector/resource-list.ui | 1 | ||||
-rw-r--r-- | gtk/inspector/window.c | 2 | ||||
-rw-r--r-- | gtk/inspector/window.h | 1 | ||||
-rw-r--r-- | gtk/inspector/window.ui | 2 |
6 files changed, 41 insertions, 3 deletions
diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c index 4bd5f9b769..da920550d6 100644 --- a/gtk/inspector/object-tree.c +++ b/gtk/inspector/object-tree.c @@ -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); } diff --git a/gtk/inspector/resource-list.c b/gtk/inspector/resource-list.c index 5a14448ca2..3869144575 100644 --- a/gtk/inspector/resource-list.c +++ b/gtk/inspector/resource-list.c @@ -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: diff --git a/gtk/inspector/resource-list.ui b/gtk/inspector/resource-list.ui index 56d5a098c5..9d2eaf5749 100644 --- a/gtk/inspector/resource-list.ui +++ b/gtk/inspector/resource-list.ui @@ -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> diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c index 0cd597bfda..da54753ae7 100644 --- a/gtk/inspector/window.c +++ b/gtk/inspector/window.c @@ -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); diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h index 06863d3087..c06cd16376 100644 --- a/gtk/inspector/window.h +++ b/gtk/inspector/window.h @@ -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; diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui index d6c8a69a25..1072c3fd33 100644 --- a/gtk/inspector/window.ui +++ b/gtk/inspector/window.ui @@ -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> |