2020-06-30 18:50:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 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 "list-data.h"
|
|
|
|
|
|
|
|
#include "gtkcolumnview.h"
|
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkstack.h"
|
|
|
|
#include "gtkboxlayout.h"
|
|
|
|
#include "gtkorientable.h"
|
|
|
|
#include "gtknoselection.h"
|
|
|
|
#include "gtksignallistitemfactory.h"
|
|
|
|
#include "gtklistitem.h"
|
2020-07-06 20:53:54 +00:00
|
|
|
#include "window.h"
|
2020-06-30 18:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct _GtkInspectorListData
|
|
|
|
{
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
|
|
|
GListModel *object;
|
|
|
|
GtkColumnView *view;
|
|
|
|
GtkWidget *items_label;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkInspectorListDataClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkInspectorListData, gtk_inspector_list_data, GTK_TYPE_WIDGET)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_list_data_init (GtkInspectorListData *sl)
|
|
|
|
{
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (sl));
|
|
|
|
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (gtk_widget_get_layout_manager (GTK_WIDGET (sl))),
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
|
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
GtkStackPage *page;
|
|
|
|
char *text;
|
|
|
|
GtkNoSelection *selection;
|
|
|
|
|
|
|
|
stack = gtk_widget_get_parent (GTK_WIDGET (sl));
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
|
|
|
|
|
|
|
|
gtk_column_view_set_model (sl->view, NULL);
|
|
|
|
sl->object = NULL;
|
|
|
|
|
|
|
|
if (!G_IS_LIST_MODEL (object))
|
|
|
|
{
|
|
|
|
g_object_set (page, "visible", FALSE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text = g_strdup_printf ("%u items", g_list_model_get_n_items (G_LIST_MODEL (object)));
|
|
|
|
gtk_label_set_label (GTK_LABEL (sl->items_label), text);
|
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
g_object_set (page, "visible", TRUE, NULL);
|
|
|
|
|
|
|
|
sl->object = G_LIST_MODEL (object);
|
|
|
|
selection = gtk_no_selection_new (sl->object);
|
|
|
|
gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection));
|
|
|
|
g_object_unref (selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_object (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
|
|
|
gtk_widget_add_css_class (label, "cell");
|
|
|
|
gtk_list_item_set_child (item, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_object (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gpointer obj;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
obj = gtk_list_item_get_item (item);
|
|
|
|
|
|
|
|
text = g_strdup_printf ("%p", obj);
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_type (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
|
|
|
gtk_widget_add_css_class (label, "cell");
|
|
|
|
gtk_list_item_set_child (item, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_type (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gpointer obj;
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
obj = gtk_list_item_get_item (item);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), G_OBJECT_TYPE_NAME (obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_props (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Properties");
|
|
|
|
gtk_widget_add_css_class (button, "cell");
|
|
|
|
gtk_widget_set_halign (button, GTK_ALIGN_START);
|
|
|
|
gtk_list_item_set_child (item, button);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
object_properties (GtkWidget *button,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
2020-07-06 20:53:54 +00:00
|
|
|
GtkInspectorWindow *iw;
|
|
|
|
GObject *obj;
|
|
|
|
guint pos;
|
|
|
|
|
|
|
|
iw = GTK_INSPECTOR_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_INSPECTOR_WINDOW));
|
2020-06-30 18:50:01 +00:00
|
|
|
|
|
|
|
obj = gtk_list_item_get_item (item);
|
2020-07-06 20:53:54 +00:00
|
|
|
pos = gtk_list_item_get_position (item);
|
|
|
|
gtk_inspector_window_push_object (iw, obj, CHILD_KIND_LISTITEM, pos);
|
2020-06-30 18:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_props (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item,
|
|
|
|
GtkInspectorListData *sl)
|
|
|
|
{
|
|
|
|
g_signal_connect (gtk_list_item_get_child (item), "clicked",
|
|
|
|
G_CALLBACK (object_properties), item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unbind_props (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (gtk_list_item_get_child (item), object_properties, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-07-18 03:05:07 +00:00
|
|
|
dispose (GObject *object)
|
2020-06-30 18:50:01 +00:00
|
|
|
{
|
|
|
|
GtkInspectorListData *sl = GTK_INSPECTOR_LIST_DATA (object);
|
2020-07-18 03:05:07 +00:00
|
|
|
GtkWidget *child;
|
2020-06-30 18:50:01 +00:00
|
|
|
|
2020-07-18 03:05:07 +00:00
|
|
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (sl))))
|
|
|
|
gtk_widget_unparent (child);
|
2020-06-30 18:50:01 +00:00
|
|
|
|
2020-07-18 03:05:07 +00:00
|
|
|
G_OBJECT_CLASS (gtk_inspector_list_data_parent_class)->dispose (object);
|
2020-06-30 18:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_list_data_class_init (GtkInspectorListDataClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2020-07-18 03:05:07 +00:00
|
|
|
object_class->dispose = dispose;
|
2020-06-30 18:50:01 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/list-data.ui");
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorListData, view);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorListData, items_label);
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_object);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_object);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_type);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_type);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_props);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_props);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, unbind_props);
|
|
|
|
|
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|