2014-10-12 02:04:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
|
|
|
#include "selector.h"
|
|
|
|
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
#include "gtktreestore.h"
|
|
|
|
#include "gtktreeview.h"
|
|
|
|
#include "gtkwidgetpath.h"
|
2014-11-22 21:21:17 +00:00
|
|
|
#include "gtklabel.h"
|
2014-10-12 02:04:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_SELECTOR
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkInspectorSelectorPrivate
|
|
|
|
{
|
|
|
|
GtkTreeStore *model;
|
|
|
|
GtkTreeView *tree;
|
2014-11-22 21:21:17 +00:00
|
|
|
GtkWidget *object_title;
|
2014-10-12 02:04:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorSelector, gtk_inspector_selector, GTK_TYPE_BOX)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_selector_init (GtkInspectorSelector *oh)
|
|
|
|
{
|
|
|
|
oh->priv = gtk_inspector_selector_get_instance_private (oh);
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (oh));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_selector_class_init (GtkInspectorSelectorClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/selector.ui");
|
2014-10-12 02:04:57 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorSelector, model);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorSelector, tree);
|
2014-11-22 21:21:17 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorSelector, object_title);
|
2014-10-12 02:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_selector_set_object (GtkInspectorSelector *oh,
|
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter, parent;
|
2015-07-17 03:42:55 +00:00
|
|
|
gint i;
|
2014-10-12 02:04:57 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
gchar *path, **words;
|
2014-11-22 21:21:17 +00:00
|
|
|
const gchar *title;
|
2014-10-12 02:04:57 +00:00
|
|
|
|
|
|
|
gtk_tree_store_clear (oh->priv->model);
|
|
|
|
|
|
|
|
if (!GTK_IS_WIDGET (object))
|
2014-11-09 02:43:26 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (GTK_WIDGET (oh));
|
|
|
|
return;
|
|
|
|
}
|
2014-10-12 02:04:57 +00:00
|
|
|
|
2014-11-22 21:21:17 +00:00
|
|
|
title = (const gchar *)g_object_get_data (object, "gtk-inspector-object-title");
|
|
|
|
gtk_label_set_label (GTK_LABEL (oh->priv->object_title), title);
|
|
|
|
|
2014-10-12 02:04:57 +00:00
|
|
|
widget = GTK_WIDGET (object);
|
|
|
|
|
|
|
|
path = gtk_widget_path_to_string (gtk_widget_get_path (widget));
|
|
|
|
words = g_strsplit (path, " ", 0);
|
|
|
|
|
2015-07-17 03:42:55 +00:00
|
|
|
for (i = 0; words[i]; i++)
|
2014-10-12 02:04:57 +00:00
|
|
|
{
|
|
|
|
gtk_tree_store_append (oh->priv->model, &iter, i ? &parent : NULL);
|
|
|
|
gtk_tree_store_set (oh->priv->model, &iter,
|
|
|
|
COLUMN_SELECTOR, words[i],
|
|
|
|
-1);
|
|
|
|
parent = iter;
|
|
|
|
}
|
|
|
|
|
2014-10-25 14:00:57 +00:00
|
|
|
g_strfreev (words);
|
|
|
|
g_free (path);
|
|
|
|
|
2014-10-12 02:04:57 +00:00
|
|
|
gtk_tree_view_expand_all (oh->priv->tree);
|
|
|
|
gtk_tree_selection_select_iter (gtk_tree_view_get_selection (oh->priv->tree), &iter);
|
2014-11-09 02:43:26 +00:00
|
|
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (oh));
|
2014-10-12 02:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|