From dffceb1a17cf2c131b48913d1df7744547f6be12 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 10 Oct 2014 22:34:32 -0400 Subject: [PATCH] inspector: Avoid a split pane for objects Like for the resources page, use a separate page for details to gain more room for both the tree and the details. --- gtk/inspector/object-tree.c | 65 +++++-- gtk/inspector/object-tree.h | 6 +- gtk/inspector/object-tree.ui | 5 +- gtk/inspector/window.c | 59 +++--- gtk/inspector/window.h | 3 + gtk/inspector/window.ui | 347 +++++++++++++++++------------------ 6 files changed, 261 insertions(+), 224 deletions(-) diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c index 7b4def0ec8..a88847c43e 100644 --- a/gtk/inspector/object-tree.c +++ b/gtk/inspector/object-tree.c @@ -59,7 +59,8 @@ enum enum { - OBJECT_CHANGED, + OBJECT_SELECTED, + OBJECT_ACTIVATED, LAST_SIGNAL }; @@ -78,25 +79,46 @@ static guint signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorObjectTree, gtk_inspector_object_tree, GTK_TYPE_BOX) static void -on_widget_selected (GtkTreeSelection *selection, - GtkInspectorObjectTree *wt) +on_row_activated (GtkTreeView *tree, + GtkTreePath *path, + GtkTreeViewColumn *col, + GtkInspectorObjectTree *wt) +{ + GtkTreeIter iter; + GObject *object; + gchar *name; + + gtk_tree_model_get_iter (GTK_TREE_MODEL (wt->priv->model), &iter, path); + gtk_tree_model_get (GTK_TREE_MODEL (wt->priv->model), &iter, + OBJECT, &object, + OBJECT_NAME, &name, + -1); + + g_signal_emit (wt, signals[OBJECT_ACTIVATED], 0, object, name); + + g_free (name); +} + +static void +on_selection_changed (GtkTreeSelection *selection, + GtkInspectorObjectTree *wt) { GObject *object; GtkTreeIter iter; GtkTreeSelection *sel; GtkTreeModel *model; - + + object = NULL; sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (wt->priv->tree)); if (gtk_tree_selection_get_selected (sel, &model, &iter)) gtk_tree_model_get (model, &iter, OBJECT, &object, -1); - else - object = NULL; - - g_signal_emit (wt, signals[OBJECT_CHANGED], 0, object); + if (object) + g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object); } + typedef struct { GtkInspectorObjectTree *wt; @@ -200,19 +222,29 @@ gtk_inspector_object_tree_class_init (GtkInspectorObjectTreeClass *klass) object_class->finalize = gtk_inspector_object_tree_finalize; - signals[OBJECT_CHANGED] = - g_signal_new ("object-changed", + signals[OBJECT_ACTIVATED] = + g_signal_new ("object-activated", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE, - G_STRUCT_OFFSET (GtkInspectorObjectTreeClass, object_changed), + G_STRUCT_OFFSET (GtkInspectorObjectTreeClass, object_activated), NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, + NULL, + G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_STRING); + + signals[OBJECT_SELECTED] = + g_signal_new ("object-selected", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE, + G_STRUCT_OFFSET (GtkInspectorObjectTreeClass, object_selected), + NULL, NULL, + NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT); gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/object-tree.ui"); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, model); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, tree); - gtk_widget_class_bind_template_callback (widget_class, on_widget_selected); + gtk_widget_class_bind_template_callback (widget_class, on_selection_changed); + gtk_widget_class_bind_template_callback (widget_class, on_row_activated); } typedef struct @@ -486,7 +518,6 @@ gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt, g_list_free (list); } } - } void @@ -550,10 +581,14 @@ gtk_inspector_object_tree_select_object (GtkInspectorObjectTree *wt, if (gtk_inspector_object_tree_find_object (wt, object, &iter)) { - GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (wt->priv->model), &iter); + GtkTreePath *path; + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (wt->priv->model), &iter); gtk_tree_view_expand_to_path (GTK_TREE_VIEW (wt->priv->tree), path); gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (wt->priv->tree)), &iter); gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (wt->priv->tree), path, NULL, FALSE, 0, 0); + gtk_tree_view_row_activated (GTK_TREE_VIEW (wt->priv->tree), path, NULL); + gtk_tree_path_free (path); } } diff --git a/gtk/inspector/object-tree.h b/gtk/inspector/object-tree.h index a90efa6afa..33482305a5 100644 --- a/gtk/inspector/object-tree.h +++ b/gtk/inspector/object-tree.h @@ -46,8 +46,10 @@ typedef struct _GtkInspectorObjectTreeClass { GtkBoxClass parent; - void (*object_changed) (GtkInspectorObjectTree *wt, - GObject *object); + void (*object_selected) (GtkInspectorObjectTree *wt, + GObject *object); + void (*object_activated) (GtkInspectorObjectTree *wt, + GObject *object); } GtkInspectorObjectTreeClass; diff --git a/gtk/inspector/object-tree.ui b/gtk/inspector/object-tree.ui index 6d0fc69fb4..65f74c9b0d 100644 --- a/gtk/inspector/object-tree.ui +++ b/gtk/inspector/object-tree.ui @@ -27,9 +27,12 @@ model True 2 + True + - + single + diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c index 63d04d8919..c6aa52ac3c 100644 --- a/gtk/inspector/window.c +++ b/gtk/inspector/window.c @@ -42,23 +42,31 @@ #include "misc-info.h" #include "gestures.h" -#include "gtknotebook.h" +#include "gtklabel.h" +#include "gtkbutton.h" +#include "gtkstack.h" +#include "gtktreeviewcolumn.h" +#include "gtkwindow.h" #include "gtkwindowgroup.h" G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW) static void -on_object_tree_selection_changed (GtkInspectorObjectTree *wt, - GObject *selected, - GtkInspectorWindow *iw) +on_object_activated (GtkInspectorObjectTree *wt, + GObject *selected, + const gchar *name, + GtkInspectorWindow *iw) { - GtkWidget *notebook; const gchar *tab; - gint page_num; + gchar *id; if (!gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->prop_list), selected)) return; + id = g_strconcat (g_type_name_from_instance ((GTypeInstance*)selected), name[0] ? " : " : NULL, name, NULL); + gtk_label_set_label (GTK_LABEL (iw->object_id), id); + g_free (id); + gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->child_prop_list), selected); gtk_inspector_style_prop_list_set_object (GTK_INSPECTOR_STYLE_PROP_LIST (iw->style_prop_list), selected); gtk_inspector_signals_list_set_object (GTK_INSPECTOR_SIGNALS_LIST (iw->signals_list), selected); @@ -72,28 +80,28 @@ on_object_tree_selection_changed (GtkInspectorObjectTree *wt, gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected); gtk_inspector_gestures_set_object (GTK_INSPECTOR_GESTURES (iw->gestures), selected); - notebook = gtk_widget_get_parent (iw->prop_list); tab = g_object_get_data (G_OBJECT (wt), "next-tab"); - if (g_strcmp0 (tab, "properties") == 0) - { - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), iw->prop_list); - gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num); - } - else if (g_strcmp0 (tab, "data") == 0) - { - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), iw->data_list); - gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num); - } - else if (g_strcmp0 (tab, "actions") == 0) - { - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), iw->actions); - gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page_num); - } + if (tab) + gtk_stack_set_visible_child_name (GTK_STACK (iw->object_details), tab); + gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-details"); +} + +static void +on_object_selected (GtkInspectorObjectTree *wt, + GObject *selected, + GtkInspectorWindow *iw) +{ if (GTK_IS_WIDGET (selected)) gtk_inspector_flash_widget (iw, GTK_WIDGET (selected)); } +static void +close_details (GtkWidget *button, GtkInspectorWindow *iw) +{ + gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-tree"); +} + static void gtk_inspector_window_init (GtkInspectorWindow *iw) { @@ -123,7 +131,10 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/window.ui"); gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, top_stack); + gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_stack); 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_id); gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, prop_list); gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, child_prop_list); gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, signals_list); @@ -139,7 +150,9 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass) gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, gestures); gtk_widget_class_bind_template_callback (widget_class, gtk_inspector_on_inspect); - gtk_widget_class_bind_template_callback (widget_class, on_object_tree_selection_changed); + gtk_widget_class_bind_template_callback (widget_class, on_object_activated); + gtk_widget_class_bind_template_callback (widget_class, on_object_selected); + gtk_widget_class_bind_template_callback (widget_class, close_details); } GtkWidget * diff --git a/gtk/inspector/window.h b/gtk/inspector/window.h index 3ae6768045..a0a1a0269c 100644 --- a/gtk/inspector/window.h +++ b/gtk/inspector/window.h @@ -42,7 +42,10 @@ typedef struct GtkWindow parent; GtkWidget *top_stack; + GtkWidget *object_stack; GtkWidget *object_tree; + GtkWidget *object_id; + GtkWidget *object_details; GtkWidget *prop_list; GtkWidget *child_prop_list; GtkWidget *signals_list; diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui index ccd3c731e9..81b9227795 100644 --- a/gtk/inspector/window.ui +++ b/gtk/inspector/window.ui @@ -44,217 +44,198 @@ True - + True - horizontal True - + + - True - True + object-tree - + True - False - True + vertical - + True - object_tree - - - True - True - - - - - True - Miscellaneous - - - - - True - False - object_tree - - - True - True - - - - - True - Properties - - - - - True - - - True - True - - - - - True - Signals - - - - - True - - - True - True - - - - - True - Hierarchy - - - - - True - object_tree - - - True - True - - - - - True - Child Properties - - - - + horizontal + + + True + center + center + 6 + + + + + True + window-close-symbolic + 1 + + - - True - True - - - - - True - CSS Classes - - - - + + + + True + center + center - - True - True - - - - - True - Style Properties + + True + + - - False - - - True - True - - - - + True - Custom CSS + horizontal - + + True + horizontal + + + True + object_details - - True - True - - - - - True - Size Groups + + + + True + + + True + object_tree + + + misc + Miscellaneous + + + + + True + False + object_tree + + + properties + Properties + + + + + True + + + signals + Signals + + + + + True + + + hierarchy + Hierarchy + + + + + True + object_tree + + + child-properties + Child Properties + + + + - - - + + css-classes + CSS Classes + + + + + + + style-properties + Style Properties + + + + + False + + + css + Custom CSS + + + + + + + size-groups + Size Groups + + + + + + + data + Data + + + + + + + actions + Actions + + + + + + + menu + Menu + + + + + object_tree + + + gestures + Gestures + + - - True - True - - - - - True - Data - - - - - - - True - True - - - - - True - Actions - - - - - - - True - True - - - - - True - Menu - - - - - object_tree - - - - - True - Gestures + - True - True + object-details