inspector: Clean up GtkInspectorActions
Drop the Private struct, dispose properly, and don't derive from GtkBox.
This commit is contained in:
@@ -34,9 +34,13 @@
|
||||
#include "gtklistbox.h"
|
||||
#include "gtkstylecontext.h"
|
||||
#include "gtksizegroup.h"
|
||||
#include "gtkboxlayout.h"
|
||||
|
||||
struct _GtkInspectorActionsPrivate
|
||||
|
||||
struct _GtkInspectorActions
|
||||
{
|
||||
GtkWidget parent;
|
||||
|
||||
GtkWidget *list;
|
||||
GtkWidget *button;
|
||||
|
||||
@@ -45,18 +49,27 @@ struct _GtkInspectorActionsPrivate
|
||||
GtkColumnViewColumn *name;
|
||||
};
|
||||
|
||||
typedef struct _GtkInspectorActionsClass
|
||||
{
|
||||
GtkWidgetClass parent;
|
||||
} GtkInspectorActionsClass;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_BUTTON
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorActions, gtk_inspector_actions, GTK_TYPE_BOX)
|
||||
G_DEFINE_TYPE (GtkInspectorActions, gtk_inspector_actions, GTK_TYPE_WIDGET)
|
||||
|
||||
static void
|
||||
gtk_inspector_actions_init (GtkInspectorActions *sl)
|
||||
{
|
||||
sl->priv = gtk_inspector_actions_get_instance_private (sl);
|
||||
GtkBoxLayout *layout;
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (sl));
|
||||
|
||||
layout = GTK_BOX_LAYOUT (gtk_widget_get_layout_manager (GTK_WIDGET (sl)));
|
||||
gtk_orientable_set_orientation (GTK_ORIENTABLE (layout), GTK_ORIENTATION_VERTICAL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -65,7 +78,7 @@ action_added_cb (GActionGroup *group,
|
||||
GtkInspectorActions *sl)
|
||||
{
|
||||
ActionHolder *holder = action_holder_new (group, action_name);
|
||||
g_list_store_append (G_LIST_STORE (sl->priv->actions), holder);
|
||||
g_list_store_append (G_LIST_STORE (sl->actions), holder);
|
||||
g_object_unref (holder);
|
||||
}
|
||||
|
||||
@@ -233,13 +246,13 @@ action_removed_cb (GActionGroup *group,
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_list_model_get_n_items (sl->priv->actions); i++)
|
||||
for (i = 0; i < g_list_model_get_n_items (sl->actions); i++)
|
||||
{
|
||||
ActionHolder *holder = g_list_model_get_item (sl->priv->actions, i);
|
||||
ActionHolder *holder = g_list_model_get_item (sl->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_list_store_remove (G_LIST_STORE (sl->actions), i);
|
||||
|
||||
g_object_unref (holder);
|
||||
}
|
||||
@@ -252,13 +265,13 @@ notify_action_changed (GtkInspectorActions *sl,
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_list_model_get_n_items (sl->priv->actions); i++)
|
||||
for (i = 0; i < g_list_model_get_n_items (sl->actions); i++)
|
||||
{
|
||||
ActionHolder *holder = g_list_model_get_item (sl->priv->actions, i);
|
||||
ActionHolder *holder = g_list_model_get_item (sl->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_list_model_items_changed (sl->actions, i, 1, 1);
|
||||
|
||||
g_object_unref (holder);
|
||||
}
|
||||
@@ -285,8 +298,8 @@ action_state_changed_cb (GActionGroup *group,
|
||||
static void
|
||||
refresh_all (GtkInspectorActions *sl)
|
||||
{
|
||||
guint n = g_list_model_get_n_items (sl->priv->actions);
|
||||
g_list_model_items_changed (sl->priv->actions, 0, n, n);
|
||||
guint n = g_list_model_get_n_items (sl->actions);
|
||||
g_list_model_items_changed (sl->actions, 0, n, n);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -326,7 +339,7 @@ add_group (GtkInspectorActions *sl,
|
||||
action_added_cb (group, names[i], sl);
|
||||
g_strfreev (names);
|
||||
|
||||
g_set_object (&sl->priv->group, group);
|
||||
g_set_object (&sl->group, group);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -336,7 +349,7 @@ remove_group (GtkInspectorActions *sl,
|
||||
{
|
||||
disconnect_group (group, sl);
|
||||
|
||||
g_set_object (&sl->priv->group, NULL);
|
||||
g_set_object (&sl->group, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -351,10 +364,10 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
|
||||
|
||||
g_object_set (page, "visible", FALSE, NULL);
|
||||
|
||||
if (sl->priv->group)
|
||||
remove_group (sl, page, sl->priv->group);
|
||||
if (sl->group)
|
||||
remove_group (sl, page, sl->group);
|
||||
|
||||
g_list_store_remove_all (G_LIST_STORE (sl->priv->actions));
|
||||
g_list_store_remove_all (G_LIST_STORE (sl->actions));
|
||||
|
||||
if (GTK_IS_APPLICATION (object))
|
||||
add_group (sl, page, G_ACTION_GROUP (object));
|
||||
@@ -367,7 +380,7 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
|
||||
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);
|
||||
gtk_column_view_sort_by_column (GTK_COLUMN_VIEW (sl->list), sl->name, GTK_SORT_ASCENDING);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -381,7 +394,7 @@ get_property (GObject *object,
|
||||
switch (param_id)
|
||||
{
|
||||
case PROP_BUTTON:
|
||||
g_value_set_object (value, sl->priv->button);
|
||||
g_value_set_object (value, sl->button);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -401,7 +414,7 @@ set_property (GObject *object,
|
||||
switch (param_id)
|
||||
{
|
||||
case PROP_BUTTON:
|
||||
sl->priv->button = g_value_get_object (value);
|
||||
sl->button = g_value_get_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -424,7 +437,7 @@ constructed (GObject *object)
|
||||
GListModel *sorted;
|
||||
GListModel *model;
|
||||
|
||||
g_signal_connect_swapped (sl->priv->button, "clicked",
|
||||
g_signal_connect_swapped (sl->button, "clicked",
|
||||
G_CALLBACK (refresh_all), sl);
|
||||
|
||||
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING,
|
||||
@@ -432,26 +445,30 @@ constructed (GObject *object)
|
||||
0, NULL,
|
||||
(GCallback)holder_name,
|
||||
NULL, NULL));
|
||||
gtk_column_view_column_set_sorter (sl->priv->name, sorter);
|
||||
gtk_column_view_column_set_sorter (sl->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))));
|
||||
sl->actions = G_LIST_MODEL (g_list_store_new (ACTION_TYPE_HOLDER));
|
||||
sorted = G_LIST_MODEL (gtk_sort_list_model_new (sl->actions,
|
||||
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list))));
|
||||
model = G_LIST_MODEL (gtk_no_selection_new (sorted));
|
||||
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->priv->list), model);
|
||||
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model);
|
||||
g_object_unref (sorted);
|
||||
g_object_unref (model);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
dispose (GObject *object)
|
||||
{
|
||||
GtkInspectorActions *sl = GTK_INSPECTOR_ACTIONS (object);
|
||||
GtkWidget *child;
|
||||
|
||||
g_object_unref (sl->priv->actions);
|
||||
g_clear_object (&sl->actions);
|
||||
|
||||
G_OBJECT_CLASS (gtk_inspector_actions_parent_class)->finalize (object);
|
||||
while ((child = gtk_widget_get_first_child (GTK_WIDGET (sl))))
|
||||
gtk_widget_unparent (child);
|
||||
|
||||
G_OBJECT_CLASS (gtk_inspector_actions_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -459,8 +476,8 @@ 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->dispose = dispose;
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
object_class->constructed = constructed;
|
||||
@@ -470,8 +487,8 @@ gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass)
|
||||
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
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 (widget_class, GtkInspectorActions, list);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorActions, name);
|
||||
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);
|
||||
@@ -482,6 +499,8 @@ gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass)
|
||||
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);
|
||||
|
||||
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
||||
}
|
||||
|
||||
// vim: set et sw=2 ts=2:
|
||||
|
||||
@@ -18,28 +18,13 @@
|
||||
#ifndef _GTK_INSPECTOR_ACTIONS_H_
|
||||
#define _GTK_INSPECTOR_ACTIONS_H_
|
||||
|
||||
#include <gtk/gtkbox.h>
|
||||
#include <gtk/gtkwidget.h>
|
||||
|
||||
#define GTK_TYPE_INSPECTOR_ACTIONS (gtk_inspector_actions_get_type())
|
||||
#define GTK_INSPECTOR_ACTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_ACTIONS, GtkInspectorActions))
|
||||
#define GTK_INSPECTOR_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_ACTIONS, GtkInspectorActionsClass))
|
||||
#define GTK_INSPECTOR_IS_ACTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_ACTIONS))
|
||||
#define GTK_INSPECTOR_IS_ACTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_ACTIONS))
|
||||
#define GTK_INSPECTOR_ACTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_ACTIONS, GtkInspectorActionsClass))
|
||||
|
||||
|
||||
typedef struct _GtkInspectorActionsPrivate GtkInspectorActionsPrivate;
|
||||
|
||||
typedef struct _GtkInspectorActions
|
||||
{
|
||||
GtkBox parent;
|
||||
GtkInspectorActionsPrivate *priv;
|
||||
} GtkInspectorActions;
|
||||
|
||||
typedef struct _GtkInspectorActionsClass
|
||||
{
|
||||
GtkBoxClass parent;
|
||||
} GtkInspectorActionsClass;
|
||||
typedef struct _GtkInspectorActions GtkInspectorActions;
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface domain="gtk40">
|
||||
<template class="GtkInspectorActions" parent="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<template class="GtkInspectorActions" parent="GtkWidget">
|
||||
<style>
|
||||
<class name="view"/>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user