2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Christian Hammond
|
|
|
|
* Copyright (c) 2008-2009 David Trowbridge
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
#include "prop-list.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
#include "prop-editor.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkcelllayout.h"
|
2014-10-11 00:51:54 +00:00
|
|
|
#include "gtktreeview.h"
|
2014-10-31 00:54:04 +00:00
|
|
|
#include "gtktreeselection.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkpopover.h"
|
2014-11-22 16:41:24 +00:00
|
|
|
#include "gtksearchentry.h"
|
|
|
|
#include "gtklabel.h"
|
2018-02-04 08:29:44 +00:00
|
|
|
#include "gtkmain.h"
|
2014-11-22 16:41:24 +00:00
|
|
|
#include "gtkstack.h"
|
2018-02-04 08:29:44 +00:00
|
|
|
#include "gtkeventcontrollerkey.h"
|
2019-04-05 19:15:16 +00:00
|
|
|
#include "gtklayoutmanager.h"
|
2019-04-12 03:42:31 +00:00
|
|
|
#include "gtklistbox.h"
|
|
|
|
#include "gtksizegroup.h"
|
2019-04-12 23:48:23 +00:00
|
|
|
#include "gtkroot.h"
|
2019-05-29 17:10:46 +00:00
|
|
|
#include "gtkgestureclick.h"
|
2019-12-03 02:00:22 +00:00
|
|
|
#include "prop-holder.h"
|
2020-07-06 20:53:54 +00:00
|
|
|
#include "window.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2016-03-07 01:41:28 +00:00
|
|
|
PROP_SEARCH_ENTRY
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
struct _GtkInspectorPropListPrivate
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GObject *object;
|
2014-05-08 22:36:38 +00:00
|
|
|
gulong notify_handler_id;
|
2014-10-31 00:54:04 +00:00
|
|
|
GtkWidget *search_entry;
|
2014-11-22 16:41:24 +00:00
|
|
|
GtkWidget *search_stack;
|
2019-12-03 02:00:22 +00:00
|
|
|
GtkWidget *list;
|
2020-08-03 19:04:33 +00:00
|
|
|
GtkStringFilter *filter;
|
2019-12-03 02:00:22 +00:00
|
|
|
GtkColumnViewColumn *name;
|
|
|
|
GtkColumnViewColumn *type;
|
|
|
|
GtkColumnViewColumn *origin;
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
2014-05-10 03:15:34 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorPropList, gtk_inspector_prop_list, GTK_TYPE_BOX)
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-11-22 16:41:24 +00:00
|
|
|
static void
|
|
|
|
search_close_clicked (GtkWidget *button,
|
|
|
|
GtkInspectorPropList *pl)
|
|
|
|
{
|
2019-02-17 04:58:54 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (pl->priv->search_entry), "");
|
2014-11-22 16:41:24 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title");
|
|
|
|
}
|
|
|
|
|
2018-05-14 17:03:17 +00:00
|
|
|
static void
|
2019-04-03 11:11:44 +00:00
|
|
|
show_search_entry (GtkInspectorPropList *pl)
|
2018-05-14 17:03:17 +00:00
|
|
|
{
|
2019-04-03 11:11:44 +00:00
|
|
|
gtk_stack_set_visible_child (GTK_STACK (pl->priv->search_stack),
|
|
|
|
pl->priv->search_entry);
|
2019-02-23 05:29:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
static char *
|
|
|
|
holder_prop (gpointer item)
|
2019-04-28 21:56:10 +00:00
|
|
|
{
|
2019-12-03 02:00:22 +00:00
|
|
|
GParamSpec *prop = prop_holder_get_pspec (PROP_HOLDER (item));
|
2019-04-28 21:56:10 +00:00
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
return g_strdup (prop->name);
|
2019-04-28 21:56:10 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
static char *
|
|
|
|
holder_type (gpointer item)
|
2019-04-28 21:56:10 +00:00
|
|
|
{
|
2019-12-03 02:00:22 +00:00
|
|
|
GParamSpec *prop = prop_holder_get_pspec (PROP_HOLDER (item));
|
2019-04-28 21:56:10 +00:00
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
return g_strdup (g_type_name (prop->value_type));
|
2019-04-28 21:56:10 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
static char *
|
|
|
|
holder_origin (gpointer item)
|
2019-04-28 21:56:10 +00:00
|
|
|
{
|
2019-12-03 02:00:22 +00:00
|
|
|
GParamSpec *prop = prop_holder_get_pspec (PROP_HOLDER (item));
|
2019-04-28 21:56:10 +00:00
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
return g_strdup (g_type_name (prop->owner_type));
|
2019-04-12 03:42:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2019-12-03 02:00:22 +00:00
|
|
|
GtkSorter *sorter;
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
pl->priv = gtk_inspector_prop_list_get_instance_private (pl);
|
2014-05-05 01:08:36 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (pl));
|
2020-07-12 05:02:04 +00:00
|
|
|
pl->priv->filter = gtk_string_filter_new (NULL);
|
2020-08-03 19:04:33 +00:00
|
|
|
gtk_string_filter_set_match_mode (pl->priv->filter, GTK_STRING_FILTER_MATCH_MODE_SUBSTRING);
|
2019-12-03 02:00:22 +00:00
|
|
|
|
2020-08-03 19:54:42 +00:00
|
|
|
sorter = GTK_SORTER (gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
|
2019-12-03 02:00:22 +00:00
|
|
|
0, NULL,
|
|
|
|
(GCallback)holder_prop,
|
2020-08-03 19:54:42 +00:00
|
|
|
NULL, NULL)));
|
2019-12-03 02:00:22 +00:00
|
|
|
|
2020-08-03 19:04:33 +00:00
|
|
|
gtk_string_filter_set_expression (pl->priv->filter,
|
2019-12-03 02:00:22 +00:00
|
|
|
gtk_string_sorter_get_expression (GTK_STRING_SORTER (sorter)));
|
|
|
|
|
|
|
|
gtk_column_view_column_set_sorter (pl->priv->name, sorter);
|
|
|
|
g_object_unref (sorter);
|
|
|
|
|
2020-08-03 19:54:42 +00:00
|
|
|
sorter = GTK_SORTER (gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
|
2019-12-03 02:00:22 +00:00
|
|
|
0, NULL,
|
|
|
|
(GCallback)holder_type,
|
2020-08-03 19:54:42 +00:00
|
|
|
NULL, NULL)));
|
2019-12-03 02:00:22 +00:00
|
|
|
|
|
|
|
gtk_column_view_column_set_sorter (pl->priv->type, sorter);
|
|
|
|
g_object_unref (sorter);
|
|
|
|
|
2020-08-03 19:54:42 +00:00
|
|
|
sorter = GTK_SORTER (gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
|
2019-12-03 02:00:22 +00:00
|
|
|
0, NULL,
|
|
|
|
(GCallback)holder_origin,
|
2020-08-03 19:54:42 +00:00
|
|
|
NULL, NULL)));
|
2019-12-03 02:00:22 +00:00
|
|
|
|
|
|
|
gtk_column_view_column_set_sorter (pl->priv->origin, sorter);
|
|
|
|
g_object_unref (sorter);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
2014-05-05 01:08:36 +00:00
|
|
|
guint param_id,
|
2014-05-03 01:48:33 +00:00
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2016-03-07 01:41:28 +00:00
|
|
|
case PROP_SEARCH_ENTRY:
|
|
|
|
g_value_take_object (value, pl->priv->search_entry);
|
|
|
|
break;
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
2014-05-05 01:08:36 +00:00
|
|
|
guint param_id,
|
2014-05-03 01:48:33 +00:00
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2014-05-07 03:24:20 +00:00
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2016-03-07 01:41:28 +00:00
|
|
|
case PROP_SEARCH_ENTRY:
|
|
|
|
pl->priv->search_entry = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
|
|
|
show_object (GtkInspectorPropEditor *editor,
|
|
|
|
GObject *object,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
|
|
|
const char *tab,
|
2014-05-18 05:03:24 +00:00
|
|
|
GtkInspectorPropList *pl)
|
|
|
|
{
|
2020-07-06 20:53:54 +00:00
|
|
|
GtkInspectorWindow *iw;
|
|
|
|
|
|
|
|
iw = GTK_INSPECTOR_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (pl), GTK_TYPE_INSPECTOR_WINDOW));
|
|
|
|
gtk_inspector_window_push_object (iw, object, CHILD_KIND_PROPERTY, 0);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
static void cleanup_object (GtkInspectorPropList *pl);
|
|
|
|
|
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
|
|
|
|
|
|
|
cleanup_object (pl);
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
G_OBJECT_CLASS (gtk_inspector_prop_list_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
static void
|
|
|
|
update_filter (GtkInspectorPropList *pl,
|
|
|
|
GtkSearchEntry *entry)
|
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
|
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (entry));
|
2020-08-03 19:04:33 +00:00
|
|
|
gtk_string_filter_set_search (pl->priv->filter, text);
|
2019-12-03 02:00:22 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorPropList *pl = GTK_INSPECTOR_PROP_LIST (object);
|
|
|
|
|
|
|
|
pl->priv->search_stack = gtk_widget_get_parent (pl->priv->search_entry);
|
|
|
|
|
|
|
|
g_signal_connect (pl->priv->search_entry, "stop-search",
|
|
|
|
G_CALLBACK (search_close_clicked), pl);
|
2019-04-03 11:11:44 +00:00
|
|
|
|
|
|
|
g_signal_connect_swapped (pl->priv->search_entry, "search-started",
|
|
|
|
G_CALLBACK (show_search_entry), pl);
|
2019-04-12 03:42:31 +00:00
|
|
|
g_signal_connect_swapped (pl->priv->search_entry, "search-changed",
|
2019-12-03 02:00:22 +00:00
|
|
|
G_CALLBACK (update_filter), pl);
|
2016-03-07 01:41:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
static void
|
2019-04-12 23:48:23 +00:00
|
|
|
update_key_capture (GtkInspectorPropList *pl)
|
2019-04-12 03:42:31 +00:00
|
|
|
{
|
2019-04-12 23:48:23 +00:00
|
|
|
GtkWidget *capture_widget;
|
|
|
|
|
|
|
|
if (gtk_widget_get_mapped (GTK_WIDGET (pl)))
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
GtkWidget *focus;
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (pl)));
|
2019-04-12 23:48:23 +00:00
|
|
|
focus = gtk_root_get_focus (GTK_ROOT (toplevel));
|
|
|
|
|
|
|
|
if (GTK_IS_EDITABLE (focus) &&
|
2019-12-03 02:00:22 +00:00
|
|
|
gtk_widget_is_ancestor (focus, pl->priv->list))
|
2019-04-12 23:48:23 +00:00
|
|
|
capture_widget = NULL;
|
|
|
|
else
|
|
|
|
capture_widget = toplevel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
capture_widget = NULL;
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2019-04-12 23:48:23 +00:00
|
|
|
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (pl->priv->search_entry),
|
|
|
|
capture_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
map (GtkWidget *widget)
|
|
|
|
{
|
2019-04-12 03:42:31 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->map (widget);
|
|
|
|
|
2019-04-12 23:48:23 +00:00
|
|
|
update_key_capture (GTK_INSPECTOR_PROP_LIST (widget));
|
2019-04-12 03:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unmap (GtkWidget *widget)
|
|
|
|
{
|
2019-04-12 23:48:23 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->unmap (widget);
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2019-04-12 23:48:23 +00:00
|
|
|
update_key_capture (GTK_INSPECTOR_PROP_LIST (widget));
|
|
|
|
}
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2019-04-12 23:48:23 +00:00
|
|
|
static void
|
|
|
|
root (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->root (widget);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (gtk_widget_get_root (widget), "notify::focus-widget",
|
|
|
|
G_CALLBACK (update_key_capture), widget);
|
2019-04-12 03:42:31 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 23:48:23 +00:00
|
|
|
static void
|
|
|
|
unroot (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (gtk_widget_get_root (widget),
|
|
|
|
update_key_capture, widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->unroot (widget);
|
|
|
|
}
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
static void
|
|
|
|
setup_name_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
2020-06-30 21:39:37 +00:00
|
|
|
gtk_widget_add_css_class (label, "cell");
|
2019-12-03 02:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_name_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GObject *item;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
item = gtk_list_item_get_item (list_item);
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), prop_holder_get_name (PROP_HOLDER (item)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_type_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
2020-06-30 21:39:37 +00:00
|
|
|
gtk_widget_add_css_class (label, "cell");
|
2019-12-03 02:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_type_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GObject *item;
|
|
|
|
GtkWidget *label;
|
|
|
|
GParamSpec *prop;
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
item = gtk_list_item_get_item (list_item);
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
|
|
|
|
prop = prop_holder_get_pspec (PROP_HOLDER (item));
|
|
|
|
type = g_type_name (G_PARAM_SPEC_VALUE_TYPE (prop));
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_origin_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
2020-06-30 21:39:37 +00:00
|
|
|
gtk_widget_add_css_class (label, "cell");
|
2019-12-03 02:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_origin_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GObject *item;
|
|
|
|
GtkWidget *label;
|
|
|
|
GParamSpec *prop;
|
|
|
|
const char *origin;
|
|
|
|
|
|
|
|
item = gtk_list_item_get_item (list_item);
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
|
|
|
|
prop = prop_holder_get_pspec (PROP_HOLDER (item));
|
|
|
|
origin = g_type_name (prop->owner_type);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), origin);
|
|
|
|
}
|
|
|
|
|
2020-07-07 06:12:30 +00:00
|
|
|
static void
|
|
|
|
setup_value_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_add_css_class (widget, "cell");
|
|
|
|
gtk_list_item_set_child (list_item, widget);
|
|
|
|
}
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
static void
|
|
|
|
bind_value_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GObject *item;
|
2020-07-07 06:12:30 +00:00
|
|
|
GtkWidget *editor;
|
2019-12-03 02:00:22 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GObject *object;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
item = gtk_list_item_get_item (list_item);
|
|
|
|
|
|
|
|
object = prop_holder_get_object (PROP_HOLDER (item));
|
|
|
|
name = prop_holder_get_name (PROP_HOLDER (item));
|
|
|
|
|
2020-07-07 06:12:30 +00:00
|
|
|
editor = gtk_inspector_prop_editor_new (object, name, NULL);
|
|
|
|
g_signal_connect (editor, "show-object", G_CALLBACK (show_object), data);
|
|
|
|
widget = gtk_list_item_get_child (list_item);
|
|
|
|
gtk_box_append (GTK_BOX (widget), editor);
|
2019-12-03 02:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unbind_value_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2020-07-07 06:12:30 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_list_item_get_child (list_item);
|
|
|
|
gtk_box_remove (GTK_BOX (widget), gtk_widget_get_first_child (widget));
|
2019-12-03 02:00:22 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-05 01:08:36 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
object_class->finalize = finalize;
|
2014-05-03 01:48:33 +00:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
object_class->set_property = set_property;
|
2016-03-07 01:41:28 +00:00
|
|
|
object_class->constructed = constructed;
|
2014-05-05 01:08:36 +00:00
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
widget_class->map = map;
|
|
|
|
widget_class->unmap = unmap;
|
2019-04-12 23:48:23 +00:00
|
|
|
widget_class->root = root;
|
|
|
|
widget_class->unroot = unroot;
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2016-03-07 01:41:28 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_SEARCH_ENTRY,
|
|
|
|
g_param_spec_object ("search-entry", "Search Entry", "Search Entry",
|
|
|
|
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/prop-list.ui");
|
2019-12-03 02:00:22 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, list);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, name);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, type);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, origin);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_name_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_name_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_type_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_type_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_origin_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_origin_cb);
|
2020-07-07 06:12:30 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_value_cb);
|
2019-12-03 02:00:22 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_value_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, unbind_value_cb);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 01:55:46 +00:00
|
|
|
/* Like g_strdup_value_contents, but keeps the type name separate */
|
2019-04-12 19:07:01 +00:00
|
|
|
void
|
2016-03-10 01:55:46 +00:00
|
|
|
strdup_value_contents (const GValue *value,
|
2020-07-24 18:40:36 +00:00
|
|
|
char **contents,
|
|
|
|
char **type)
|
2016-03-10 01:55:46 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *src;
|
2016-03-10 01:55:46 +00:00
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (value))
|
|
|
|
{
|
|
|
|
src = g_value_get_string (value);
|
|
|
|
|
|
|
|
*type = g_strdup ("char*");
|
|
|
|
|
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
*contents = g_strdup ("NULL");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *s = g_strescape (src, NULL);
|
2016-03-10 01:55:46 +00:00
|
|
|
*contents = g_strdup_printf ("\"%s\"", s);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
|
|
|
|
{
|
|
|
|
GValue tmp_value = G_VALUE_INIT;
|
|
|
|
|
|
|
|
*type = g_strdup (g_type_name (G_VALUE_TYPE (value)));
|
|
|
|
|
|
|
|
g_value_init (&tmp_value, G_TYPE_STRING);
|
|
|
|
g_value_transform (value, &tmp_value);
|
|
|
|
src = g_value_get_string (&tmp_value);
|
|
|
|
if (!src)
|
|
|
|
*contents = g_strdup ("NULL");
|
|
|
|
else
|
|
|
|
*contents = g_strescape (src, NULL);
|
|
|
|
g_value_unset (&tmp_value);
|
|
|
|
}
|
|
|
|
else if (g_value_fits_pointer (value))
|
|
|
|
{
|
|
|
|
gpointer p = g_value_peek_pointer (value);
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
*type = g_strdup (g_type_name (G_VALUE_TYPE (value)));
|
|
|
|
*contents = g_strdup ("NULL");
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_OBJECT (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup (G_OBJECT_TYPE_NAME (p));
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_PARAM (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup (G_PARAM_SPEC_TYPE_NAME (p));
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
|
|
|
|
{
|
|
|
|
GStrv strv = g_value_get_boxed (value);
|
|
|
|
GString *tmp = g_string_new ("[");
|
|
|
|
|
|
|
|
while (*strv != NULL)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *escaped = g_strescape (*strv, NULL);
|
2016-03-10 01:55:46 +00:00
|
|
|
|
|
|
|
g_string_append_printf (tmp, "\"%s\"", escaped);
|
|
|
|
g_free (escaped);
|
|
|
|
|
|
|
|
if (*++strv != NULL)
|
|
|
|
g_string_append (tmp, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append (tmp, "]");
|
|
|
|
*type = g_strdup ("char**");
|
|
|
|
*contents = g_string_free (tmp, FALSE);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_BOXED (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup (g_type_name (G_VALUE_TYPE (value)));
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else if (G_VALUE_HOLDS_POINTER (value))
|
|
|
|
{
|
|
|
|
*type = g_strdup ("gpointer");
|
|
|
|
*contents = g_strdup_printf ("%p", p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*type = g_strdup ("???");
|
|
|
|
*contents = g_strdup ("???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*type = g_strdup ("???");
|
|
|
|
*contents = g_strdup ("???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
static void
|
|
|
|
cleanup_object (GtkInspectorPropList *pl)
|
|
|
|
{
|
2014-05-21 10:39:11 +00:00
|
|
|
if (pl->priv->object &&
|
|
|
|
g_signal_handler_is_connected (pl->priv->object, pl->priv->notify_handler_id))
|
|
|
|
g_signal_handler_disconnect (pl->priv->object, pl->priv->notify_handler_id);
|
2014-05-09 02:58:43 +00:00
|
|
|
|
|
|
|
pl->priv->object = NULL;
|
2014-05-21 10:39:11 +00:00
|
|
|
pl->priv->notify_handler_id = 0;
|
2014-05-09 02:58:43 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
gboolean
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
|
|
|
|
GObject *object)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GParamSpec **props;
|
|
|
|
guint num_properties;
|
|
|
|
guint i;
|
2019-12-03 02:00:22 +00:00
|
|
|
GListStore *store;
|
|
|
|
GListModel *list;
|
|
|
|
GListModel *filtered;
|
|
|
|
GtkSortListModel *sorted;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
if (!object)
|
2014-05-03 20:43:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
if (pl->priv->object == object)
|
|
|
|
return TRUE;
|
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
cleanup_object (pl);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2019-02-17 04:58:54 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (pl->priv->search_entry), "");
|
2014-11-22 16:41:24 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (pl->priv->search_stack), "title");
|
2016-03-07 01:41:28 +00:00
|
|
|
|
2019-04-02 21:56:26 +00:00
|
|
|
props = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &num_properties);
|
2014-05-03 19:57:16 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
pl->priv->object = object;
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
store = g_list_store_new (PROP_TYPE_HOLDER);
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
for (i = 0; i < num_properties; i++)
|
|
|
|
{
|
|
|
|
GParamSpec *prop = props[i];
|
2019-12-03 02:00:22 +00:00
|
|
|
PropHolder *holder;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
if (! (prop->flags & G_PARAM_READABLE))
|
|
|
|
continue;
|
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
holder = prop_holder_new (object, prop);
|
|
|
|
g_list_store_append (store, holder);
|
|
|
|
g_object_unref (holder);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
2014-05-03 20:43:04 +00:00
|
|
|
|
2014-05-21 10:39:11 +00:00
|
|
|
g_free (props);
|
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (object))
|
2014-09-26 03:05:15 +00:00
|
|
|
g_signal_connect_object (object, "destroy", G_CALLBACK (cleanup_object), pl, G_CONNECT_SWAPPED);
|
2014-05-21 10:39:11 +00:00
|
|
|
|
2020-08-03 19:04:33 +00:00
|
|
|
filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), g_object_ref (GTK_FILTER (pl->priv->filter))));
|
2019-12-03 02:00:22 +00:00
|
|
|
sorted = gtk_sort_list_model_new (filtered, NULL);
|
|
|
|
list = G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (sorted)));
|
|
|
|
|
2020-08-31 21:06:48 +00:00
|
|
|
gtk_column_view_set_model (GTK_COLUMN_VIEW (pl->priv->list), GTK_SELECTION_MODEL (list));
|
2019-12-03 02:00:22 +00:00
|
|
|
gtk_sort_list_model_set_sorter (sorted, gtk_column_view_get_sorter (GTK_COLUMN_VIEW (pl->priv->list)));
|
|
|
|
gtk_column_view_sort_by_column (GTK_COLUMN_VIEW (pl->priv->list), pl->priv->name, GTK_SORT_ASCENDING);
|
|
|
|
|
2014-05-10 03:57:57 +00:00
|
|
|
gtk_widget_show (GTK_WIDGET (pl));
|
2014-05-21 10:39:11 +00:00
|
|
|
|
2019-12-03 02:00:22 +00:00
|
|
|
g_object_unref (list);
|
|
|
|
|
2014-05-03 20:43:04 +00:00
|
|
|
return TRUE;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:15:16 +00:00
|
|
|
void
|
|
|
|
gtk_inspector_prop_list_set_layout_child (GtkInspectorPropList *pl,
|
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
GtkStackPage *page;
|
|
|
|
GtkWidget *parent;
|
|
|
|
GtkLayoutManager *layout_manager;
|
|
|
|
GtkLayoutChild *layout_child;
|
|
|
|
|
|
|
|
stack = gtk_widget_get_parent (GTK_WIDGET (pl));
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (pl));
|
|
|
|
g_object_set (page, "visible", FALSE, NULL);
|
|
|
|
|
|
|
|
if (!GTK_IS_WIDGET (object))
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (object));
|
|
|
|
if (!parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
layout_manager = gtk_widget_get_layout_manager (parent);
|
|
|
|
if (!layout_manager)
|
|
|
|
return;
|
|
|
|
|
2019-04-05 19:44:16 +00:00
|
|
|
if (GTK_LAYOUT_MANAGER_GET_CLASS (layout_manager)->layout_child_type == G_TYPE_INVALID)
|
|
|
|
return;
|
|
|
|
|
2019-04-05 19:15:16 +00:00
|
|
|
layout_child = gtk_layout_manager_get_layout_child (layout_manager, GTK_WIDGET (object));
|
|
|
|
if (!layout_child)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!gtk_inspector_prop_list_set_object (pl, G_OBJECT (layout_child)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_set (page, "visible", TRUE, NULL);
|
|
|
|
}
|
|
|
|
|
2014-05-05 01:08:36 +00:00
|
|
|
// vim: set et sw=2 ts=2:
|