Commit 70c3241b authored by Matthias Clasen's avatar Matthias Clasen

inspector: Improve tab switching

Switch the object and resource trees away from activate-on-single-click
and add a 'view details' button.
parent 32326f82
......@@ -99,21 +99,31 @@ on_row_activated (GtkTreeView *tree,
g_free (name);
}
static void
on_selection_changed (GtkTreeSelection *selection,
GtkInspectorObjectTree *wt)
GObject *
gtk_inspector_object_tree_get_selected (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);
return object;
}
static void
on_selection_changed (GtkTreeSelection *selection,
GtkInspectorObjectTree *wt)
{
GObject *object;
object = gtk_inspector_object_tree_get_selected (wt);
if (object)
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
}
......
......@@ -70,6 +70,8 @@ gboolean gtk_inspector_object_tree_find_object (GtkInspectorObjectTree
GObject *object,
GtkTreeIter *iter);
GObject *gtk_inspector_object_tree_get_selected (GtkInspectorObjectTree *wt);
G_END_DECLS
......
......@@ -25,7 +25,6 @@
<property name="model">model</property>
<property name="enable-search">True</property>
<property name="search-column">2</property>
<property name="activate-on-single-click">True</property>
<signal name="row-activated" handler="on_row_activated"/>
<child internal-child="selection">
<object class="GtkTreeSelection">
......
......@@ -335,9 +335,12 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
guint num_properties;
guint i;
if (pl->priv->object == object || !object)
if (!object)
return FALSE;
if (pl->priv->object == object)
return TRUE;
cleanup_object (pl);
if (!object)
......
......@@ -29,7 +29,7 @@
enum
{
PROP_0,
PROP_CLOSE_DETAILS_BUTTON
PROP_BUTTONS
};
enum
......@@ -53,6 +53,8 @@ struct _GtkInspectorResourceListPrivate
GtkWidget *info_grid;
GtkWidget *stack;
GtkWidget *tree;
GtkWidget *buttons;
GtkWidget *open_details_button;
GtkWidget *close_details_button;
GtkTreeViewColumn *count_column;
GtkCellRenderer *count_renderer;
......@@ -215,8 +217,34 @@ row_activated (GtkTreeView *treeview,
GtkTreeViewColumn *column,
GtkInspectorResourceList *sl)
{
if (populate_details (sl, path))
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->stack), "details");
if (!populate_details (sl, path))
return;
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->stack), "details");
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->buttons), "details");
}
static void
open_details (GtkWidget *button,
GtkInspectorResourceList *sl)
{
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreePath *path;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sl->priv->tree));
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return;
path = gtk_tree_model_get_path (model, &iter);
if (populate_details (sl, path))
{
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->stack), "details");
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->buttons), "details");
}
gtk_tree_path_free (path);
}
static void
......@@ -224,6 +252,7 @@ close_details (GtkWidget *button,
GtkInspectorResourceList *sl)
{
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->stack), "list");
gtk_stack_set_visible_child_name (GTK_STACK (sl->priv->buttons), "list");
}
static void
......@@ -231,14 +260,11 @@ visible_child_name_changed (GObject *obj, GParamSpec *pspec, GtkInspectorResourc
{
const gchar *child;
gboolean resources_visible;
gboolean resource_details_visible;
child = gtk_stack_get_visible_child_name (GTK_STACK (gtk_widget_get_parent (GTK_WIDGET (sl))));
resources_visible = g_strcmp0 (child, "resources") == 0;
child = gtk_stack_get_visible_child_name (GTK_STACK (sl->priv->stack));
resource_details_visible = g_strcmp0 (child, "details") == 0;
gtk_widget_set_visible (sl->priv->close_details_button, resources_visible && resource_details_visible);
gtk_widget_set_visible (sl->priv->buttons, resources_visible);
}
static void
......@@ -329,6 +355,8 @@ constructed (GObject *object)
{
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
g_signal_connect (rl->priv->open_details_button, "clicked",
G_CALLBACK (open_details), rl);
g_signal_connect (rl->priv->close_details_button, "clicked",
G_CALLBACK (close_details), rl);
......@@ -345,8 +373,8 @@ get_property (GObject *object,
switch (param_id)
{
case PROP_CLOSE_DETAILS_BUTTON:
g_value_take_object (value, rl->priv->close_details_button);
case PROP_BUTTONS:
g_value_take_object (value, rl->priv->buttons);
break;
default:
......@@ -365,8 +393,10 @@ set_property (GObject *object,
switch (param_id)
{
case PROP_CLOSE_DETAILS_BUTTON:
rl->priv->close_details_button = g_value_get_object (value);
case PROP_BUTTONS:
rl->priv->buttons = g_value_get_object (value);
rl->priv->open_details_button = gtk_stack_get_child_by_name (GTK_STACK (rl->priv->buttons), "list");
rl->priv->close_details_button = gtk_stack_get_child_by_name (GTK_STACK (rl->priv->buttons), "details");
break;
default:
......@@ -387,8 +417,8 @@ gtk_inspector_resource_list_class_init (GtkInspectorResourceListClass *klass)
widget_class->parent_set = parent_set;
g_object_class_install_property (object_class, PROP_CLOSE_DETAILS_BUTTON,
g_param_spec_object ("close-details-button", NULL, NULL,
g_object_class_install_property (object_class, PROP_BUTTONS,
g_param_spec_object ("buttons", NULL, NULL,
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/resource-list.ui");
......
......@@ -27,11 +27,10 @@
<object class="GtkTreeView" id="tree">
<property name="visible">True</property>
<property name="model">model</property>
<property name="activate-on-single-click">True</property>
<signal name="row-activated" handler="row_activated"/>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
<property name="mode">single</property>
</object>
</child>
<child>
......
......@@ -52,16 +52,12 @@
G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
static void
on_object_activated (GtkInspectorObjectTree *wt,
GObject *selected,
const gchar *name,
GtkInspectorWindow *iw)
static gboolean
set_selected_object (GtkInspectorWindow *iw,
GObject *selected)
{
const gchar *tab;
if (!gtk_inspector_prop_list_set_object (GTK_INSPECTOR_PROP_LIST (iw->prop_list), selected))
return;
return FALSE;
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);
......@@ -77,11 +73,26 @@ on_object_activated (GtkInspectorObjectTree *wt,
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
gtk_inspector_gestures_set_object (GTK_INSPECTOR_GESTURES (iw->gestures), selected);
return TRUE;
}
static void
on_object_activated (GtkInspectorObjectTree *wt,
GObject *selected,
const gchar *name,
GtkInspectorWindow *iw)
{
const gchar *tab;
if (!set_selected_object (iw, selected))
return;
tab = g_object_get_data (G_OBJECT (wt), "next-tab");
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");
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_buttons), "details");
}
static void
......@@ -94,9 +105,24 @@ on_object_selected (GtkInspectorObjectTree *wt,
}
static void
close_details (GtkWidget *button, GtkInspectorWindow *iw)
close_object_details (GtkWidget *button, GtkInspectorWindow *iw)
{
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-tree");
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_buttons), "list");
}
static void
open_object_details (GtkWidget *button, GtkInspectorWindow *iw)
{
GObject *selected;
selected = gtk_inspector_object_tree_get_selected (GTK_INSPECTOR_OBJECT_TREE (iw->object_tree));
if (!set_selected_object (iw, selected))
return;
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_stack), "object-details");
gtk_stack_set_visible_child_name (GTK_STACK (iw->object_buttons), "details");
}
static void
......@@ -104,15 +130,12 @@ visible_child_name_changed (GObject *obj, GParamSpec *pspec, GtkInspectorWindow
{
const gchar *child;
gboolean objects_visible;
gboolean object_details_visible;
child = gtk_stack_get_visible_child_name (GTK_STACK (iw->top_stack));
objects_visible = g_strcmp0 (child, "objects") == 0;
child = gtk_stack_get_visible_child_name (GTK_STACK (iw->object_stack));
object_details_visible = g_strcmp0 (child, "object-details") == 0;
gtk_widget_set_visible (iw->select_object, objects_visible);
gtk_widget_set_visible (iw->close_object_details, objects_visible && object_details_visible);
gtk_widget_set_visible (iw->object_buttons, objects_visible);
}
static void
......@@ -152,7 +175,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
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, close_object_details);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, object_buttons);
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);
......@@ -172,7 +195,8 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, gtk_inspector_on_inspect);
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);
gtk_widget_class_bind_template_callback (widget_class, open_object_details);
gtk_widget_class_bind_template_callback (widget_class, close_object_details);
}
static GdkScreen *
......
......@@ -46,7 +46,7 @@ typedef struct
GtkWidget *object_tree;
GtkWidget *object_id;
GtkWidget *object_details;
GtkWidget *close_object_details;
GtkWidget *object_buttons;
GtkWidget *select_object;
GtkWidget *prop_list;
GtkWidget *child_prop_list;
......
......@@ -31,20 +31,51 @@
</packing>
</child>
<child>
<object class="GtkButton" id="close_object_details">
<property name="tooltip-text" translatable="yes">Show all Objects</property>
<property name="halign">center</property>
<property name="valign">center</property>
<signal name="clicked" handler="close_details"/>
<style>
<class name="image-button"/>
</style>
<object class="GtkStack" id="object_buttons">
<property name="visible">True</property>
<child>
<object class="GtkImage">
<object class="GtkButton">
<property name="visible">True</property>
<property name="icon-name">view-list-symbolic</property>
<property name="icon-size">1</property>
<property name="tooltip-text" translatable="yes">Show Details</property>
<property name="halign">center</property>
<property name="valign">center</property>
<signal name="clicked" handler="open_object_details"/>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-name">dialog-information-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
<packing>
<property name="name">list</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="tooltip-text" translatable="yes">Show all Objects</property>
<property name="halign">center</property>
<property name="valign">center</property>
<signal name="clicked" handler="close_object_details"/>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-name">view-list-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
<packing>
<property name="name">details</property>
</packing>
</child>
</object>
<packing>
......@@ -52,20 +83,48 @@
</packing>
</child>
<child>
<object class="GtkButton" id="close_resource_details">
<property name="tooltip-text" translatable="yes">Show all Resources</property>
<property name="halign">center</property>
<property name="valign">center</property>
<signal name="clicked" handler="close_details"/>
<style>
<class name="image-button"/>
</style>
<object class="GtkStack" id="resource_buttons">
<child>
<object class="GtkImage">
<object class="GtkButton">
<property name="visible">True</property>
<property name="icon-name">view-list-symbolic</property>
<property name="icon-size">1</property>
<property name="tooltip-text" translatable="yes">Show Details</property>
<property name="halign">center</property>
<property name="valign">center</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-name">dialog-information-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
<packing>
<property name="name">list</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="tooltip-text" translatable="yes">Show all Resources</property>
<property name="halign">center</property>
<property name="valign">center</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-name">view-list-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
<packing>
<property name="name">details</property>
</packing>
</child>
</object>
<packing>
......@@ -266,7 +325,7 @@
<child>
<object class="GtkInspectorResourceList">
<property name="visible">True</property>
<property name="close-details-button">close_resource_details</property>
<property name="buttons">resource_buttons</property>
</object>
<packing>
<property name="name">resources</property>
......
N_("Select an Object");
N_("Show Details");
N_("Show all Objects");
N_("Show Details");
N_("Show all Resources");
N_("Miscellaneous");
N_("Properties");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment