Merge branch 'columnview-1' into 'master'

Convert the inspector to column views

See merge request GNOME/gtk!1994
This commit is contained in:
Matthias Clasen 2020-05-31 14:06:31 +00:00
commit 93353888ca
16 changed files with 1452 additions and 867 deletions

View File

@ -96,12 +96,14 @@ variant_editor_new (const GVariantType *type,
else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
{
editor = gtk_entry_new ();
gtk_editable_set_width_chars (GTK_EDITABLE (editor), 10);
g_signal_connect (editor, "notify::text", G_CALLBACK (variant_editor_changed_cb), d);
}
else
{
editor = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
entry = gtk_entry_new ();
gtk_editable_set_width_chars (GTK_EDITABLE (entry), 10);
gtk_box_append (GTK_BOX (editor), entry);
label = gtk_label_new (g_variant_type_peek_string (type));
gtk_box_append (GTK_BOX (editor), label);
@ -284,7 +286,8 @@ constructed (GObject *object)
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
activate = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_box_append (GTK_BOX (row), activate);
gtk_size_group_add_widget (r->priv->sg, activate);
if (r->priv->sg)
gtk_size_group_add_widget (r->priv->sg, activate);
r->priv->activate_button = gtk_button_new_with_label (_("Activate"));
g_signal_connect (r->priv->activate_button, "clicked", G_CALLBACK (activate_action), r);
@ -307,7 +310,8 @@ constructed (GObject *object)
r->priv->state_type = g_variant_type_copy (g_variant_get_type (state));
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
label = gtk_label_new (_("Set State"));
gtk_size_group_add_widget (r->priv->sg, label);
if (r->priv->sg)
gtk_size_group_add_widget (r->priv->sg, label);
gtk_box_append (GTK_BOX (row), label);
r->priv->state_entry = variant_editor_new (r->priv->state_type, state_changed, r);
variant_editor_set_value (r->priv->state_entry, state);
@ -327,7 +331,7 @@ finalize (GObject *object)
GtkInspectorActionEditor *r = GTK_INSPECTOR_ACTION_EDITOR (object);
g_free (r->priv->name);
g_object_unref (r->priv->sg);
g_clear_object (&r->priv->sg);
if (r->priv->state_type)
g_variant_type_free (r->priv->state_type);
g_signal_handlers_disconnect_by_func (r->priv->group, action_enabled_changed_cb, r);

View File

@ -0,0 +1,61 @@
#include "action-holder.h"
struct _ActionHolder {
GObject instance;
GActionGroup *group;
char *name;
};
G_DEFINE_TYPE (ActionHolder, action_holder, G_TYPE_OBJECT)
static void
action_holder_init (ActionHolder *holder)
{
}
static void
action_holder_finalize (GObject *object)
{
ActionHolder *holder = ACTION_HOLDER (object);
g_object_unref (holder->group);
g_free (holder->name);
G_OBJECT_CLASS (action_holder_parent_class)->finalize (object);
}
static void
action_holder_class_init (ActionHolderClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = action_holder_finalize;
}
ActionHolder *
action_holder_new (GActionGroup *group,
const char *name)
{
ActionHolder *holder;
holder = g_object_new (ACTION_TYPE_HOLDER, NULL);
holder->group = g_object_ref (group);
holder->name = g_strdup (name);
return holder;
}
GActionGroup *
action_holder_get_group (ActionHolder *holder)
{
return holder->group;
}
const char *
action_holder_get_name (ActionHolder *holder)
{
return holder->name;
}

View File

@ -0,0 +1,17 @@
#ifndef __ACTION_HOLDER_H__
#define __ACTION_HOLDER_H__
#include <gtk/gtk.h>
#define ACTION_TYPE_HOLDER (action_holder_get_type ())
G_DECLARE_FINAL_TYPE (ActionHolder, action_holder, ACTION, HOLDER, GObject)
ActionHolder * action_holder_new (GActionGroup *group,
const char *name);
GActionGroup *action_holder_get_group (ActionHolder *holder);
const char *action_holder_get_name (ActionHolder *holder);
#endif /* __ACTION_HOLDER_H__ */

View File

@ -20,6 +20,7 @@
#include "actions.h"
#include "action-editor.h"
#include "action-holder.h"
#include "gtkapplication.h"
#include "gtkapplicationwindow.h"
@ -37,13 +38,11 @@
struct _GtkInspectorActionsPrivate
{
GtkWidget *list;
GtkSizeGroup *name;
GtkSizeGroup *enabled;
GtkSizeGroup *parameter;
GtkSizeGroup *state;
GtkSizeGroup *activate;
GActionGroup *group;
GtkWidget *button;
GActionGroup *group;
GListModel *actions;
GtkColumnViewColumn *name;
};
enum {
@ -61,105 +60,170 @@ gtk_inspector_actions_init (GtkInspectorActions *sl)
}
static void
add_action (GtkInspectorActions *sl,
GActionGroup *group,
const gchar *name)
action_added_cb (GActionGroup *group,
const gchar *action_name,
GtkInspectorActions *sl)
{
gboolean enabled;
const gchar *parameter;
GVariant *state;
gchar *state_string;
GtkWidget *row;
GtkWidget *label;
GtkWidget *box;
char *key = g_strdup (name);
GtkWidget *editor;
ActionHolder *holder = action_holder_new (group, action_name);
g_list_store_append (G_LIST_STORE (sl->priv->actions), holder);
g_object_unref (holder);
}
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);
}
static void
bind_name_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
gpointer 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), action_holder_get_name (ACTION_HOLDER (item)));
}
static void
setup_enabled_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *label;
label = gtk_label_new (NULL);
gtk_label_set_xalign (GTK_LABEL (label), 0.5);
gtk_list_item_set_child (list_item, label);
}
static void
bind_enabled_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
gpointer item;
GtkWidget *label;
GActionGroup *group;
const char *name;
gboolean enabled;
item = gtk_list_item_get_item (list_item);
label = gtk_list_item_get_child (list_item);
group = action_holder_get_group (ACTION_HOLDER (item));
name = action_holder_get_name (ACTION_HOLDER (item));
enabled = g_action_group_get_action_enabled (group, name);
gtk_label_set_label (GTK_LABEL (label), enabled ? "+" : "-");
}
static void
setup_parameter_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *label;
label = gtk_label_new (NULL);
gtk_label_set_xalign (GTK_LABEL (label), 0.5);
gtk_list_item_set_child (list_item, label);
gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
}
static void
bind_parameter_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
gpointer item;
GtkWidget *label;
GActionGroup *group;
const char *name;
const char *parameter;
item = gtk_list_item_get_item (list_item);
label = gtk_list_item_get_child (list_item);
group = action_holder_get_group (ACTION_HOLDER (item));
name = action_holder_get_name (ACTION_HOLDER (item));
parameter = (const gchar *)g_action_group_get_action_parameter_type (group, name);
gtk_label_set_label (GTK_LABEL (label), parameter);
}
static void
setup_state_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *label;
label = gtk_label_new (NULL);
gtk_widget_set_margin_start (label, 5);
gtk_widget_set_margin_end (label, 5);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_list_item_set_child (list_item, label);
gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
}
static void
bind_state_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
gpointer item;
GtkWidget *label;
GActionGroup *group;
const char *name;
GVariant *state;
char *state_string;
item = gtk_list_item_get_item (list_item);
label = gtk_list_item_get_child (list_item);
group = action_holder_get_group (ACTION_HOLDER (item));
name = action_holder_get_name (ACTION_HOLDER (item));
state = g_action_group_get_action_state (group, name);
if (state)
state_string = g_variant_print (state, FALSE);
else
state_string = g_strdup ("");
row = gtk_list_box_row_new ();
g_object_set_data_full (G_OBJECT (row), "key", key, g_free);
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box);
label = gtk_label_new (name);
gtk_widget_add_css_class (label, "cell");
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_size_group_add_widget (sl->priv->name, label);
gtk_box_append (GTK_BOX (box), label);
label = gtk_label_new (enabled ? "+" : "-");
gtk_widget_add_css_class (label, "cell");
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
gtk_size_group_add_widget (sl->priv->enabled, label);
gtk_box_append (GTK_BOX (box), label);
g_object_set_data (G_OBJECT (row), "enabled", label);
label = gtk_label_new (parameter);
gtk_widget_add_css_class (label, "cell");
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_size_group_add_widget (sl->priv->parameter, label);
gtk_box_append (GTK_BOX (box), label);
label = gtk_label_new (state_string);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_widget_add_css_class (label, "cell");
gtk_size_group_add_widget (sl->priv->state, label);
gtk_box_append (GTK_BOX (box), label);
g_object_set_data (G_OBJECT (row), "state", label);
editor = gtk_inspector_action_editor_new (group, name, sl->priv->activate);
gtk_widget_add_css_class (editor, "cell");
gtk_box_append (GTK_BOX (box), editor);
g_object_set_data (G_OBJECT (row), "editor", editor);
gtk_list_box_insert (GTK_LIST_BOX (sl->priv->list), row, -1);
gtk_label_set_label (GTK_LABEL (label), state_string);
g_free (state_string);
}
static GtkWidget *
find_row (GtkInspectorActions *sl,
const char *action_name)
{
GtkWidget *row = NULL;
GtkWidget *widget;
const char *key;
for (widget = gtk_widget_get_first_child (sl->priv->list);
widget;
widget = gtk_widget_get_next_sibling (widget))
{
if (!GTK_IS_LIST_BOX_ROW (widget))
continue;
key = g_object_get_data (G_OBJECT (widget), "key");
if (g_str_equal (key, action_name))
{
row = widget;
break;
}
}
return row;
if (state)
g_variant_unref (state);
}
static void
action_added_cb (GActionGroup *group,
const gchar *action_name,
GtkInspectorActions *sl)
bind_changes_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
add_action (sl, group, action_name);
gpointer item;
GActionGroup *group;
const char *name;
GtkWidget *editor;
item = gtk_list_item_get_item (list_item);
group = action_holder_get_group (ACTION_HOLDER (item));
name = action_holder_get_name (ACTION_HOLDER (item));
editor = gtk_inspector_action_editor_new (group, name, NULL);
gtk_style_context_add_class (gtk_widget_get_style_context (editor), "cell");
gtk_list_item_set_child (list_item, editor);
}
static void
unbind_changes_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item)
{
gtk_list_item_set_child (list_item, NULL);
}
static void
@ -167,21 +231,37 @@ action_removed_cb (GActionGroup *group,
const gchar *action_name,
GtkInspectorActions *sl)
{
GtkWidget *row;
int i;
row = find_row (sl, action_name);
if (row)
gtk_list_box_remove (GTK_LIST_BOX (sl->priv->list), row);
for (i = 0; i < g_list_model_get_n_items (sl->priv->actions); i++)
{
ActionHolder *holder = g_list_model_get_item (sl->priv->actions, i);
if (group == action_holder_get_group (holder) &&
strcmp (action_name, action_holder_get_name (holder)) == 0)
g_list_store_remove (G_LIST_STORE (sl->priv->actions), i);
g_object_unref (holder);
}
}
static void
set_row_enabled (GtkWidget *row,
gboolean enabled)
notify_action_changed (GtkInspectorActions *sl,
GActionGroup *group,
const char *action_name)
{
GtkWidget *label;
int i;
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "enabled"));
gtk_label_set_label (GTK_LABEL (label), enabled ? "+" : "-" );
for (i = 0; i < g_list_model_get_n_items (sl->priv->actions); i++)
{
ActionHolder *holder = g_list_model_get_item (sl->priv->actions, i);
if (group == action_holder_get_group (holder) &&
strcmp (action_name, action_holder_get_name (holder)) == 0)
g_list_model_items_changed (sl->priv->actions, i, 1, 1);
g_object_unref (holder);
}
}
static void
@ -190,26 +270,7 @@ action_enabled_changed_cb (GActionGroup *group,
gboolean enabled,
GtkInspectorActions *sl)
{
GtkWidget *row;
row = find_row (sl, action_name);
set_row_enabled (row, enabled);
}
static void
set_row_state (GtkWidget *row,
GVariant *state)
{
gchar *state_string;
GtkWidget *label;
if (state)
state_string = g_variant_print (state, FALSE);
else
state_string = g_strdup ("");
label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "state"));
gtk_label_set_label (GTK_LABEL (label), state_string);
g_free (state_string);
notify_action_changed (sl, group, action_name);
}
static void
@ -218,35 +279,14 @@ action_state_changed_cb (GActionGroup *group,
GVariant *state,
GtkInspectorActions *sl)
{
GtkWidget *row;
row = find_row (sl, action_name);
set_row_state (row, state);
notify_action_changed (sl, group, action_name);
}
static void
refresh_all (GtkInspectorActions *sl)
{
GtkWidget *widget;
for (widget = gtk_widget_get_first_child (sl->priv->list);
widget;
widget = gtk_widget_get_next_sibling (widget))
{
const char *name = g_object_get_data (G_OBJECT (widget), "key");
gboolean enabled;
GVariant *state;
GtkInspectorActionEditor *r;
enabled = g_action_group_get_action_enabled (sl->priv->group, name);
state = g_action_group_get_action_state (sl->priv->group, name);
set_row_enabled (widget, enabled);
set_row_state (widget, state);
r = (GtkInspectorActionEditor*)g_object_get_data (G_OBJECT (widget), "editor");
gtk_inspector_action_editor_update (r, enabled, state);
}
guint n = g_list_model_get_n_items (sl->priv->actions);
g_list_model_items_changed (sl->priv->actions, 0, n, n);
}
static void
@ -283,7 +323,7 @@ add_group (GtkInspectorActions *sl,
names = g_action_group_list_actions (group);
for (i = 0; names[i]; i++)
add_action (sl, group, names[i]);
action_added_cb (group, names[i], sl);
g_strfreev (names);
g_set_object (&sl->priv->group, group);
@ -305,7 +345,6 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
{
GtkWidget *stack;
GtkStackPage *page;
GtkWidget *child;
stack = gtk_widget_get_parent (GTK_WIDGET (sl));
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
@ -315,8 +354,7 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
if (sl->priv->group)
remove_group (sl, page, sl->priv->group);
while ((child = gtk_widget_get_first_child (sl->priv->list)))
gtk_list_box_remove (GTK_LIST_BOX (sl->priv->list), child);
g_list_store_remove_all (G_LIST_STORE (sl->priv->actions));
if (GTK_IS_APPLICATION (object))
add_group (sl, page, G_ACTION_GROUP (object));
@ -328,6 +366,8 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
if (muxer)
add_group (sl, page, G_ACTION_GROUP (muxer));
}
gtk_column_view_sort_by_column (GTK_COLUMN_VIEW (sl->priv->list), sl->priv->name, GTK_SORT_ASCENDING);
}
static void
@ -370,13 +410,48 @@ set_property (GObject *object,
}
}
static char *
holder_name (gpointer item)
{
return g_strdup (action_holder_get_name (ACTION_HOLDER (item)));
}
static void
constructed (GObject *object)
{
GtkInspectorActions *sl = GTK_INSPECTOR_ACTIONS (object);
GtkSorter *sorter;
GListModel *sorted;
GListModel *model;
g_signal_connect_swapped (sl->priv->button, "clicked",
G_CALLBACK (refresh_all), sl);
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING,
NULL,
0, NULL,
(GCallback)holder_name,
NULL, NULL));
gtk_column_view_column_set_sorter (sl->priv->name, sorter);
g_object_unref (sorter);
sl->priv->actions = G_LIST_MODEL (g_list_store_new (ACTION_TYPE_HOLDER));
sorted = G_LIST_MODEL (gtk_sort_list_model_new (sl->priv->actions,
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->priv->list))));
model = G_LIST_MODEL (gtk_no_selection_new (sorted));
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->priv->list), model);
g_object_unref (sorted);
g_object_unref (model);
}
static void
finalize (GObject *object)
{
GtkInspectorActions *sl = GTK_INSPECTOR_ACTIONS (object);
g_object_unref (sl->priv->actions);
G_OBJECT_CLASS (gtk_inspector_actions_parent_class)->finalize (object);
}
static void
@ -385,6 +460,7 @@ gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = finalize;
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->constructed = constructed;
@ -396,10 +472,16 @@ gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/actions.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, list);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, name);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, enabled);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, parameter);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, state);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, activate);
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_enabled_cb);
gtk_widget_class_bind_template_callback (widget_class, bind_enabled_cb);
gtk_widget_class_bind_template_callback (widget_class, setup_parameter_cb);
gtk_widget_class_bind_template_callback (widget_class, bind_parameter_cb);
gtk_widget_class_bind_template_callback (widget_class, setup_state_cb);
gtk_widget_class_bind_template_callback (widget_class, bind_state_cb);
gtk_widget_class_bind_template_callback (widget_class, bind_changes_cb);
gtk_widget_class_bind_template_callback (widget_class, unbind_changes_cb);
}
// vim: set et sw=2 ts=2:

View File

@ -1,98 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<object class="GtkListStore" id="model">
<columns>
<column type="gchararray"/>
<column type="gchararray"/>
<column type="gboolean"/>
<column type="gchararray"/>
<column type="gchararray"/>
<column type="gpointer"/>
</columns>
</object>
<template class="GtkInspectorActions" parent="GtkBox">
<property name="orientation">vertical</property>
<style>
<class name="view"/>
</style>
<child>
<object class="GtkBox">
<style>
<class name="header"/>
</style>
<child>
<object class="GtkLabel" id="name_heading">
<property name="label" translatable="yes">Name</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel" id="enabled_heading">
<property name="label" translatable="yes">Enabled</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel" id="parameter_heading">
<property name="label" translatable="yes">Parameter Type</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel" id="state_heading">
<property name="label" translatable="yes">State</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkLabel" id="changes_heading">
<property name="label" translatable="yes"></property>
<property name="xalign">0</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="hscrollbar-policy">never</property>
<child>
<object class="GtkListBox" id="list">
<object class="GtkColumnView" id="list">
<style>
<class name="list"/>
</style>
<property name="selection-mode">none</property>
<child>
<object class="GtkColumnViewColumn" id="name">
<property name="title" translatable="yes">Name</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_name_cb"/>
<signal name="bind" handler="bind_name_cb"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="enabled">
<property name="title" translatable="yes">Enabled</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_enabled_cb"/>
<signal name="bind" handler="bind_enabled_cb"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="parameter">
<property name="title" translatable="yes">Parameter Type</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_parameter_cb"/>
<signal name="bind" handler="bind_parameter_cb"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="state">
<property name="title" translatable="yes">State</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_state_cb"/>
<signal name="bind" handler="bind_state_cb"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="changes">
<property name="title"></property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="bind" handler="bind_changes_cb"/>
<signal name="unbind" handler="unbind_changes_cb"/>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
<object class="GtkSizeGroup" id="name">
<property name="mode">horizontal</property>
<widgets>
<widget name="name_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="enabled">
<property name="mode">horizontal</property>
<widgets>
<widget name="enabled_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="parameter">
<property name="mode">horizontal</property>
<widgets>
<widget name="parameter_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="state">
<property name="mode">horizontal</property>
<widgets>
<widget name="state_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="activate">
<property name="mode">horizontal</property>
</object>
</interface>

View File

@ -1,21 +1,29 @@
/* some style for the inspector */
.header {
background: lightgray;
border: 1px solid gray;
.list header {
background: white;
border: 1px solid lightgray;
}
.header>* {
.list header button {
background: none;
}
.list header button.dnd {
background: gray;
}
.list header>* {
padding: 2px;
font-weight: bold;
}
.header sort_indicator {
.list header sort_indicator {
min-width: 16px;
}
.header>*:not(:last-child) {
border-right: 1px solid gray;
.list header>*:not(:last-child) {
border-right: 1px solid lightgray;
}
.list .cell {

View File

@ -38,4 +38,7 @@ inspector_sources = files(
'updatesoverlay.c',
'visual.c',
'window.c',
'prop-holder.c',
'resource-holder.c',
'action-holder.c'
)

View File

@ -336,6 +336,29 @@ object_tree_tree_view_get_children (GObject *object)
return G_LIST_MODEL (result);
}
static GListModel *
object_tree_column_view_get_children (GObject *object)
{
GtkColumnView *view = GTK_COLUMN_VIEW (object);
GListStore *result_list;
GtkFlattenListModel *result;
GListModel *columns, *sublist;
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
columns = gtk_column_view_get_columns (view);
g_list_store_append (result_list, columns);
sublist = object_tree_widget_get_children (object);
g_list_store_append (result_list, sublist);
g_object_unref (sublist);
result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list));
g_object_unref (result_list);
return G_LIST_MODEL (result);
}
static GListModel *
object_tree_icon_view_get_children (GObject *object)
{
@ -499,6 +522,11 @@ static const ObjectTreeClassFuncs object_tree_class_funcs[] = {
object_tree_widget_get_parent,
object_tree_tree_view_get_children
},
{
gtk_column_view_get_type,
object_tree_widget_get_parent,
object_tree_column_view_get_children
},
{
gtk_combo_box_get_type,
object_tree_widget_get_parent,

145
gtk/inspector/prop-holder.c Normal file
View File

@ -0,0 +1,145 @@
#include "prop-holder.h"
enum {
PROP_OBJECT = 1,
PROP_PSPEC,
PROP_NAME,
NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES];
struct _PropHolder {
GObject instance;
GObject *object;
GParamSpec *pspec;
};
G_DEFINE_TYPE (PropHolder, prop_holder, G_TYPE_OBJECT)
static void
prop_holder_init (PropHolder *holder)
{
}
static void
prop_holder_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PropHolder *holder = PROP_HOLDER (object);
switch (prop_id)
{
case PROP_OBJECT:
holder->object = g_value_dup_object (value);
break;
case PROP_PSPEC:
holder->pspec = g_value_get_param (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
prop_holder_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PropHolder *holder = PROP_HOLDER (object);
switch (prop_id)
{
case PROP_OBJECT:
g_value_set_object (value, holder->object);
break;
case PROP_PSPEC:
g_value_set_param (value, holder->pspec);
break;
case PROP_NAME:
g_value_set_string (value, holder->pspec->name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
prop_holder_finalize (GObject *object)
{
PropHolder *holder = PROP_HOLDER (object);
g_object_unref (holder->object);
G_OBJECT_CLASS (prop_holder_parent_class)->finalize (object);
}
static void
prop_holder_class_init (PropHolderClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = prop_holder_finalize;
object_class->set_property = prop_holder_set_property;
object_class->get_property = prop_holder_get_property;
properties[PROP_OBJECT] =
g_param_spec_object ("object", "object", "object",
G_TYPE_OBJECT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
properties[PROP_PSPEC] =
g_param_spec_param ("pspec", "pspec", "pspec",
G_TYPE_PARAM,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
properties[PROP_NAME] =
g_param_spec_string ("name", "name", "name",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
}
PropHolder *
prop_holder_new (GObject *object,
GParamSpec *pspec)
{
PropHolder *holder;
holder = g_object_new (PROP_TYPE_HOLDER,
"object", object,
"pspec", pspec,
NULL);
return holder;
}
GObject *
prop_holder_get_object (PropHolder *holder)
{
return holder->object;
}
GParamSpec *
prop_holder_get_pspec (PropHolder *holder)
{
return holder->pspec;
}
const char *
prop_holder_get_name (PropHolder *holder)
{
return holder->pspec->name;
}

View File

@ -0,0 +1,17 @@
#ifndef __PROP_HOLDER_H__
#define __PROP_HOLDER_H__
#include <gtk/gtk.h>
#define PROP_TYPE_HOLDER (prop_holder_get_type ())
G_DECLARE_FINAL_TYPE (PropHolder, prop_holder, PROP, HOLDER, GObject)
PropHolder * prop_holder_new (GObject *object,
GParamSpec *pspeC);
GObject *prop_holder_get_object (PropHolder *holder);
GParamSpec *prop_holder_get_pspec (PropHolder *holder);
const char *prop_holder_get_name (PropHolder *holder);
#endif /* __PROP_HOLDER_H__ */

View File

@ -44,6 +44,7 @@
#include "gtkroot.h"
#include "gtkgestureclick.h"
#include "gtkstylecontext.h"
#include "prop-holder.h"
enum
{
@ -52,11 +53,6 @@ enum
PROP_SEARCH_ENTRY
};
typedef enum {
COLUMN_NAME,
COLUMN_ORIGIN
} SortColumn;
struct _GtkInspectorPropListPrivate
{
GObject *object;
@ -64,17 +60,11 @@ struct _GtkInspectorPropListPrivate
GtkInspectorObjectTree *object_tree;
GtkWidget *search_entry;
GtkWidget *search_stack;
GtkWidget *list2;
GtkWidget *name_sort_indicator;
GtkWidget *origin_sort_indicator;
GtkWidget *name_heading;
GtkWidget *origin_heading;
SortColumn sort_column;
GtkSortType sort_direction;
GtkSizeGroup *names;
GtkSizeGroup *types;
GtkSizeGroup *values;
GtkSizeGroup *origins;
GtkWidget *list;
GtkFilter *filter;
GtkColumnViewColumn *name;
GtkColumnViewColumn *type;
GtkColumnViewColumn *origin;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorPropList, gtk_inspector_prop_list, GTK_TYPE_BOX)
@ -94,103 +84,66 @@ show_search_entry (GtkInspectorPropList *pl)
pl->priv->search_entry);
}
static void
apply_sort (GtkInspectorPropList *pl,
SortColumn column,
GtkSortType direction)
static char *
holder_prop (gpointer item)
{
const char *icon_name;
GParamSpec *prop = prop_holder_get_pspec (PROP_HOLDER (item));
icon_name = direction == GTK_SORT_ASCENDING ? "pan-down-symbolic"
: "pan-up-symbolic";
if (column == COLUMN_NAME)
{
gtk_image_clear (GTK_IMAGE (pl->priv->origin_sort_indicator));
gtk_image_set_from_icon_name (GTK_IMAGE (pl->priv->name_sort_indicator),
icon_name);
}
else
{
gtk_image_clear (GTK_IMAGE (pl->priv->name_sort_indicator));
gtk_image_set_from_icon_name (GTK_IMAGE (pl->priv->origin_sort_indicator),
icon_name);
}
pl->priv->sort_column = column;
pl->priv->sort_direction = direction;
gtk_list_box_invalidate_sort (GTK_LIST_BOX (pl->priv->list2));
return g_strdup (prop->name);
}
static void
sort_changed (GtkGestureClick *gesture,
int n_press,
double x,
double y,
GtkInspectorPropList *pl)
static char *
holder_type (gpointer item)
{
SortColumn column;
GtkSortType direction;
GtkWidget *widget;
GParamSpec *prop = prop_holder_get_pspec (PROP_HOLDER (item));
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
if (widget == pl->priv->name_heading)
column = COLUMN_NAME;
else
column = COLUMN_ORIGIN;
if (pl->priv->sort_column == column &&
pl->priv->sort_direction == GTK_SORT_ASCENDING)
direction = GTK_SORT_DESCENDING;
else
direction = GTK_SORT_ASCENDING;
apply_sort (pl, column, direction);
return g_strdup (g_type_name (prop->value_type));
}
static const char *
row_get_column (GtkListBoxRow *row,
SortColumn column)
static char *
holder_origin (gpointer item)
{
GParamSpec *prop = g_object_get_data (G_OBJECT (row), "pspec");
GParamSpec *prop = prop_holder_get_pspec (PROP_HOLDER (item));
if (column == COLUMN_NAME)
return prop->name;
else
return g_type_name (prop->owner_type);
}
static int
sort_func (GtkListBoxRow *row1,
GtkListBoxRow *row2,
gpointer user_data)
{
GtkInspectorPropList *pl = user_data;
const char *s1 = row_get_column (row1, pl->priv->sort_column);
const char *s2 = row_get_column (row2, pl->priv->sort_column);
int ret = strcmp (s1, s2);
return pl->priv->sort_direction == GTK_SORT_ASCENDING ? ret : -ret;
}
static gboolean
filter_func (GtkListBoxRow *row,
gpointer data)
{
GtkInspectorPropList *pl = data;
GParamSpec *pspec = (GParamSpec *)g_object_get_data (G_OBJECT (row), "pspec");
const char *text = gtk_editable_get_text (GTK_EDITABLE (pl->priv->search_entry));
return g_str_has_prefix (pspec->name, text);
return g_strdup (g_type_name (prop->owner_type));
}
static void
gtk_inspector_prop_list_init (GtkInspectorPropList *pl)
{
GtkSorter *sorter;
pl->priv = gtk_inspector_prop_list_get_instance_private (pl);
gtk_widget_init_template (GTK_WIDGET (pl));
apply_sort (pl, COLUMN_NAME, GTK_SORT_ASCENDING);
pl->priv->filter = gtk_string_filter_new ();
gtk_string_filter_set_match_mode (GTK_STRING_FILTER (pl->priv->filter), GTK_STRING_FILTER_MATCH_MODE_PREFIX);
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
0, NULL,
(GCallback)holder_prop,
NULL, NULL));
gtk_string_filter_set_expression (GTK_STRING_FILTER (pl->priv->filter),
gtk_string_sorter_get_expression (GTK_STRING_SORTER (sorter)));
gtk_column_view_column_set_sorter (pl->priv->name, sorter);
g_object_unref (sorter);
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
0, NULL,
(GCallback)holder_type,
NULL, NULL));
gtk_column_view_column_set_sorter (pl->priv->type, sorter);
g_object_unref (sorter);
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
0, NULL,
(GCallback)holder_origin,
NULL, NULL));
gtk_column_view_column_set_sorter (pl->priv->origin, sorter);
g_object_unref (sorter);
}
static void
@ -253,6 +206,7 @@ show_object (GtkInspectorPropEditor *editor,
gtk_inspector_object_tree_activate_object (pl->priv->object_tree, object);
}
static void cleanup_object (GtkInspectorPropList *pl);
static void
@ -265,6 +219,16 @@ finalize (GObject *object)
G_OBJECT_CLASS (gtk_inspector_prop_list_parent_class)->finalize (object);
}
static void
update_filter (GtkInspectorPropList *pl,
GtkSearchEntry *entry)
{
const char *text;
text = gtk_editable_get_text (GTK_EDITABLE (entry));
gtk_string_filter_set_search (GTK_STRING_FILTER (pl->priv->filter), text);
}
static void
constructed (GObject *object)
{
@ -278,10 +242,7 @@ constructed (GObject *object)
g_signal_connect_swapped (pl->priv->search_entry, "search-started",
G_CALLBACK (show_search_entry), pl);
g_signal_connect_swapped (pl->priv->search_entry, "search-changed",
G_CALLBACK (gtk_list_box_invalidate_filter), pl->priv->list2);
gtk_list_box_set_filter_func (GTK_LIST_BOX (pl->priv->list2), filter_func, pl, NULL);
gtk_list_box_set_sort_func (GTK_LIST_BOX (pl->priv->list2), sort_func, pl, NULL);
G_CALLBACK (update_filter), pl);
}
static void
@ -298,7 +259,7 @@ update_key_capture (GtkInspectorPropList *pl)
focus = gtk_root_get_focus (GTK_ROOT (toplevel));
if (GTK_IS_EDITABLE (focus) &&
gtk_widget_is_ancestor (focus, pl->priv->list2))
gtk_widget_is_ancestor (focus, pl->priv->list))
capture_widget = NULL;
else
capture_widget = toplevel;
@ -344,6 +305,120 @@ unroot (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_inspector_prop_list_parent_class)->unroot (widget);
}
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);
gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
}
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);
gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
}
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);
gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell");
}
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);
}
static void
bind_value_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item,
gpointer data)
{
GObject *item;
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));
widget = gtk_inspector_prop_editor_new (object, name, NULL);
g_signal_connect (widget, "show-object", G_CALLBACK (show_object), data);
gtk_list_item_set_child (list_item, widget);
gtk_style_context_add_class (gtk_widget_get_style_context (widget), "cell");
}
static void
unbind_value_cb (GtkSignalListItemFactory *factory,
GtkListItem *list_item,
gpointer data)
{
gtk_list_item_set_child (list_item, NULL);
}
static void
gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
{
@ -369,16 +444,18 @@ gtk_inspector_prop_list_class_init (GtkInspectorPropListClass *klass)
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/prop-list.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, list2);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, names);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, types);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, values);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, origins);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, name_heading);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, name_sort_indicator);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, origin_heading);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorPropList, origin_sort_indicator);
gtk_widget_class_bind_template_callback (widget_class, sort_changed);
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);
gtk_widget_class_bind_template_callback (widget_class, bind_value_cb);
gtk_widget_class_bind_template_callback (widget_class, unbind_value_cb);
}
/* Like g_strdup_value_contents, but keeps the type name separate */
@ -483,88 +560,6 @@ strdup_value_contents (const GValue *value,
}
}
static GtkWidget *
gtk_inspector_prop_list_create_row (GtkInspectorPropList *pl,
GParamSpec *prop)
{
GValue gvalue = {0};
gchar *value;
gchar *type;
gchar *attribute = NULL;
gboolean writable;
GtkWidget *row;
GtkWidget *box;
GtkWidget *label;
GtkWidget *widget;
g_value_init (&gvalue, prop->value_type);
g_object_get_property (pl->priv->object, prop->name, &gvalue);
strdup_value_contents (&gvalue, &value, &type);
if (GTK_IS_CELL_RENDERER (pl->priv->object))
{
gpointer *layout;
GtkCellArea *area;
gint column = -1;
area = NULL;
layout = g_object_get_data (pl->priv->object, "gtk-inspector-cell-layout");
if (layout)
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (layout));
if (area)
column = gtk_cell_area_attribute_get_column (area,
GTK_CELL_RENDERER (pl->priv->object),
prop->name);
if (column != -1)
attribute = g_strdup_printf ("%d", column);
}
writable = ((prop->flags & G_PARAM_WRITABLE) != 0) &&
((prop->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
row = gtk_list_box_row_new ();
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
g_object_set_data (G_OBJECT (row), "pspec", prop);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box);
label = gtk_label_new (prop->name);
gtk_widget_add_css_class (label, "cell");
gtk_widget_set_sensitive (label, writable);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_size_group_add_widget (pl->priv->names, label);
gtk_box_append (GTK_BOX (box), label);
label = gtk_label_new (type ? type : "");
gtk_widget_add_css_class (label, "cell");
gtk_widget_set_sensitive (label, writable);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_size_group_add_widget (pl->priv->types, label);
gtk_box_append (GTK_BOX (box), label);
label = gtk_label_new (g_type_name (prop->owner_type));
gtk_widget_add_css_class (label, "cell");
gtk_widget_set_sensitive (label, writable);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_size_group_add_widget (pl->priv->origins, label);
gtk_box_append (GTK_BOX (box), label);
widget = gtk_inspector_prop_editor_new (pl->priv->object, prop->name, pl->priv->values);
gtk_widget_add_css_class (widget, "cell");
gtk_box_append (GTK_BOX (box), widget);
g_signal_connect (widget, "show-object", G_CALLBACK (show_object), pl);
g_free (value);
g_free (type);
g_free (attribute);
g_value_unset (&gvalue);
return row;
}
static void
cleanup_object (GtkInspectorPropList *pl)
{
@ -583,7 +578,10 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
GParamSpec **props;
guint num_properties;
guint i;
GtkWidget *w;
GListStore *store;
GListModel *list;
GListModel *filtered;
GtkSortListModel *sorted;
if (!object)
return FALSE;
@ -600,19 +598,19 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
pl->priv->object = object;
while ((w = gtk_widget_get_first_child (pl->priv->list2)))
gtk_list_box_remove (GTK_LIST_BOX (pl->priv->list2), w);
store = g_list_store_new (PROP_TYPE_HOLDER);
for (i = 0; i < num_properties; i++)
{
GParamSpec *prop = props[i];
GtkWidget *row;
PropHolder *holder;
if (! (prop->flags & G_PARAM_READABLE))
continue;
row = gtk_inspector_prop_list_create_row (pl, prop);
gtk_list_box_insert (GTK_LIST_BOX (pl->priv->list2), row, -1);
holder = prop_holder_new (object, prop);
g_list_store_append (store, holder);
g_object_unref (holder);
}
g_free (props);
@ -620,8 +618,21 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
if (GTK_IS_WIDGET (object))
g_signal_connect_object (object, "destroy", G_CALLBACK (cleanup_object), pl, G_CONNECT_SWAPPED);
filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), pl->priv->filter));
sorted = gtk_sort_list_model_new (filtered, NULL);
list = G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (sorted)));
gtk_column_view_set_model (GTK_COLUMN_VIEW (pl->priv->list), list);
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);
gtk_widget_show (GTK_WIDGET (pl));
g_object_unref (list);
g_object_unref (sorted);
g_object_unref (filtered);
g_object_unref (store);
return TRUE;
}

View File

@ -8,87 +8,60 @@
<style>
<class name="view"/>
</style>
<child>
<object class="GtkBox">
<style>
<class name="header"/>
</style>
<child>
<object class="GtkBox" id="name_heading">
<property name="hexpand">0</property>
<child>
<object class="GtkGestureClick">
<signal name="pressed" handler="sort_changed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Name</property>
<property name="xalign">0</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkImage" id="name_sort_indicator">
<style>
<class name="sort_indicator"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel" id="type_heading">
<property name="label">Type</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkBox" id="origin_heading">
<property name="hexpand">0</property>
<child>
<object class="GtkGestureClick">
<signal name="pressed" handler="sort_changed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Defined at</property>
<property name="xalign">0</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkImage" id="origin_sort_indicator">
<style>
<class name="sort_indicator"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel" id="value_heading">
<property name="label">Value</property>
<property name="xalign">0</property>
<property name="hexpand">0</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="hscrollbar-policy">never</property>
<child>
<object class="GtkListBox" id="list2">
<object class="GtkColumnView" id="list">
<style>
<class name="list"/>
</style>
<property name="selection-mode">none</property>
<child>
<object class="GtkColumnViewColumn" id="name">
<property name="title" translatable="yes">Name</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_name_cb"/>
<signal name="bind" handler="bind_name_cb"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="type">
<property name="title" translatable="yes">Type</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_type_cb"/>
<signal name="bind" handler="bind_type_cb"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="origin">
<property name="title" translatable="yes">Defined At</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_origin_cb"/>
<signal name="bind" handler="bind_origin_cb"/>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title" translatable="yes">Value</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="bind" handler="bind_value_cb"/>
<signal name="unbind" handler="unbind_value_cb"/>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
@ -96,28 +69,4 @@
</object>
</child>
</template>
<object class="GtkSizeGroup" id="names">
<property name="mode">horizontal</property>
<widgets>
<widget name="name_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="types">
<property name="mode">horizontal</property>
<widgets>
<widget name="type_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="origins">
<property name="mode">horizontal</property>
<widgets>
<widget name="origin_heading"/>
</widgets>
</object>
<object class="GtkSizeGroup" id="values">
<property name="mode">horizontal</property>
<widgets>
<widget name="value_heading"/>
</widgets>
</object>
</interface>

View File

@ -0,0 +1,106 @@
#include "resource-holder.h"
struct _ResourceHolder {
GObject instance;
char *name;
char *path;
int count;
gsize size;
GListModel *children;
ResourceHolder *parent;
};
G_DEFINE_TYPE (ResourceHolder, resource_holder, G_TYPE_OBJECT)
static void
resource_holder_init (ResourceHolder *holder)
{
}
static void
resource_holder_finalize (GObject *object)
{
ResourceHolder *holder = RESOURCE_HOLDER (object);
g_free (holder->name);
g_free (holder->path);
g_clear_object (&holder->children);
G_OBJECT_CLASS (resource_holder_parent_class)->finalize (object);
}
static void
resource_holder_class_init (ResourceHolderClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = resource_holder_finalize;
}
ResourceHolder *
resource_holder_new (const char *name,
const char *path,
int count,
gsize size,
GListModel *children)
{
ResourceHolder *holder;
holder = g_object_new (RESOURCE_TYPE_HOLDER, NULL);
holder->name = g_strdup (name);
holder->path = g_strdup (path);
holder->count = count;
holder->size = size;
g_set_object (&holder->children, children);
if (children)
{
int i;
for (i = 0; i < g_list_model_get_n_items (children); i++)
{
ResourceHolder *child = g_list_model_get_item (children, i);
child->parent = holder;
g_object_unref (child);
}
}
return holder;
}
const char *
resource_holder_get_name (ResourceHolder *holder)
{
return holder->name;
}
const char *
resource_holder_get_path (ResourceHolder *holder)
{
return holder->path;
}
int
resource_holder_get_count (ResourceHolder *holder)
{
return holder->count;
}
gsize
resource_holder_get_size (ResourceHolder *holder)
{
return holder->size;
}
GListModel *
resource_holder_get_children (ResourceHolder *holder)
{
return holder->children;
}
ResourceHolder *
resource_holder_get_parent (ResourceHolder *holder)
{
return holder->parent;
}

View File

@ -0,0 +1,24 @@
#ifndef __RESOURCE_HOLDER_H__
#define __RESOURCE_HOLDER_H__
#include <gtk/gtk.h>
#define RESOURCE_TYPE_HOLDER (resource_holder_get_type ())
G_DECLARE_FINAL_TYPE (ResourceHolder, resource_holder, RESOURCE, HOLDER, GObject)
ResourceHolder * resource_holder_new (const char *name,
const char *path,
int count,
gsize size,
GListModel *children);
const char *resource_holder_get_name (ResourceHolder *holder);
const char *resource_holder_get_path (ResourceHolder *holder);
int resource_holder_get_count (ResourceHolder *holder);
gsize resource_holder_get_size (ResourceHolder *holder);
GListModel *resource_holder_get_children (ResourceHolder *holder);
ResourceHolder *resource_holder_get_parent (ResourceHolder *holder);
#endif /* __RESOURCE_HOLDER_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,9 @@
<object class="GtkSearchEntry" id="search_entry">
<property name="max-width-chars">40</property>
<signal name="search-changed" handler="on_search_changed"/>
<signal name="next-match" handler="next_match"/>
<signal name="previous-match" handler="previous_match"/>
<signal name="stop-search" handler="stop_search"/>
</object>
</child>
<child>
@ -54,56 +57,39 @@
<property name="vexpand">1</property>
<property name="hscrollbar-policy">never</property>
<child>
<object class="GtkTreeView" id="tree">
<property name="model">model</property>
<property name="enable-search">0</property>
<property name="enable-grid-lines">vertical</property>
<signal name="row-activated" handler="row_activated"/>
<child internal-child="selection">
<object class="GtkTreeSelection">
<signal name="changed" handler="on_selection_changed"/>
</object>
</child>
<object class="GtkColumnView" id="list">
<signal name="activate" handler="on_row_activated"/>
<child>
<object class="GtkTreeViewColumn" id="path_column">
<object class="GtkColumnViewColumn" id="path">
<property name="title" translatable="yes">Path</property>
<property name="resizable">1</property>
<property name="sort-column-id">0</property>
<child>
<object class="GtkCellRendererText">
<property name="scale">0.8</property>
<property name="ellipsize">end</property>
<property name="width-chars">10</property>
<property name="max-width-chars">5</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_name_cb"/>
<signal name="bind" handler="bind_name_cb"/>
</object>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="count_column">
<object class="GtkColumnViewColumn" id="count">
<property name="title" translatable="yes">Count</property>
<property name="resizable">1</property>
<property name="sort-column-id">1</property>
<child>
<object class="GtkCellRendererText" id="count_renderer">
<property name="scale">0.8</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_count_cb"/>
<signal name="bind" handler="bind_count_cb"/>
</object>
</child>
</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="size_column">
<object class="GtkColumnViewColumn" id="size">
<property name="title" translatable="yes">Size</property>
<property name="resizable">1</property>
<property name="sort-column-id">2</property>
<child>
<object class="GtkCellRendererText" id="size_renderer">
<property name="scale">0.8</property>
<property name="factory">
<object class="GtkSignalListItemFactory">
<signal name="setup" handler="setup_size_cb"/>
<signal name="bind" handler="bind_size_cb"/>
</object>
</child>
</property>
</object>
</child>
</object>