2014-05-18 05:03:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-05-19 04:17:23 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
#include "prop-editor.h"
|
2019-11-09 00:13:28 +00:00
|
|
|
|
2015-10-25 06:13:13 +00:00
|
|
|
#include "strv-editor.h"
|
2019-04-12 19:07:01 +00:00
|
|
|
#include "prop-list.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
|
|
|
#include "gtkactionable.h"
|
|
|
|
#include "gtkadjustment.h"
|
|
|
|
#include "gtkapplicationwindow.h"
|
2022-10-07 21:47:28 +00:00
|
|
|
#include "deprecated/gtkcelllayout.h"
|
|
|
|
#include "deprecated/gtkcombobox.h"
|
|
|
|
#include "deprecated/gtkiconview.h"
|
|
|
|
#include "deprecated/gtktreeview.h"
|
2022-10-28 14:00:37 +00:00
|
|
|
#include "gtkcolordialogbutton.h"
|
|
|
|
#include "gtkfontdialogbutton.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkpopover.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtkspinbutton.h"
|
2014-09-19 12:44:21 +00:00
|
|
|
#include "gtksettingsprivate.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtktogglebutton.h"
|
2020-05-02 04:51:20 +00:00
|
|
|
#include "gtkviewport.h"
|
2014-05-31 02:56:12 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2015-10-27 03:38:05 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
2019-02-13 20:08:17 +00:00
|
|
|
#include "gtklistbox.h"
|
2019-04-12 03:42:31 +00:00
|
|
|
#include "gtkmenubutton.h"
|
2014-05-18 05:03:24 +00:00
|
|
|
|
2022-10-07 21:47:28 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
struct _GtkInspectorPropEditor
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkBox parent_instance;
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
GObject *object;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name;
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkWidget *self;
|
2019-04-12 18:34:11 +00:00
|
|
|
GtkSizeGroup *size_group;
|
2014-05-18 05:03:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_OBJECT,
|
|
|
|
PROP_NAME,
|
2019-04-12 18:34:11 +00:00
|
|
|
PROP_SIZE_GROUP
|
2014-05-18 05:03:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SHOW_OBJECT,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
G_DEFINE_TYPE (GtkInspectorPropEditor, gtk_inspector_prop_editor, GTK_TYPE_BOX);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
static GParamSpec *
|
2019-11-09 00:13:28 +00:00
|
|
|
find_property (GtkInspectorPropEditor *self)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
return g_object_class_find_property (G_OBJECT_GET_CLASS (self->object), self->name);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gpointer instance;
|
|
|
|
GObject *alive_object;
|
|
|
|
gulong id;
|
|
|
|
} DisconnectData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
disconnect_func (gpointer data)
|
|
|
|
{
|
|
|
|
DisconnectData *dd = data;
|
|
|
|
|
|
|
|
g_signal_handler_disconnect (dd->instance, dd->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
signal_removed (gpointer data,
|
|
|
|
GClosure *closure)
|
|
|
|
{
|
|
|
|
DisconnectData *dd = data;
|
|
|
|
|
|
|
|
g_object_steal_data (dd->alive_object, "alive-object-data");
|
|
|
|
g_free (dd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_object_connect_property (GObject *object,
|
|
|
|
GParamSpec *spec,
|
|
|
|
GCallback func,
|
|
|
|
gpointer data,
|
|
|
|
GObject *alive_object)
|
|
|
|
{
|
|
|
|
GClosure *closure;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *with_detail;
|
2014-05-18 05:03:24 +00:00
|
|
|
DisconnectData *dd;
|
|
|
|
|
2019-04-02 21:56:26 +00:00
|
|
|
with_detail = g_strconcat ("notify::", spec->name, NULL);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
dd = g_new (DisconnectData, 1);
|
|
|
|
|
|
|
|
closure = g_cclosure_new (func, data, NULL);
|
|
|
|
g_closure_add_invalidate_notifier (closure, dd, signal_removed);
|
|
|
|
dd->id = g_signal_connect_closure (object, with_detail, closure, FALSE);
|
|
|
|
dd->instance = object;
|
|
|
|
dd->alive_object = alive_object;
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (alive_object), "alive-object-data",
|
|
|
|
dd, disconnect_func);
|
|
|
|
|
|
|
|
g_free (with_detail);
|
|
|
|
}
|
|
|
|
|
2015-10-25 06:13:13 +00:00
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
block_notify (GObject *self)
|
2015-10-25 06:13:13 +00:00
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
DisconnectData *dd = (DisconnectData *)g_object_get_data (self, "alive-object-data");
|
2015-10-25 06:13:13 +00:00
|
|
|
|
|
|
|
if (dd)
|
|
|
|
g_signal_handler_block (dd->instance, dd->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
unblock_notify (GObject *self)
|
2015-10-25 06:13:13 +00:00
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
DisconnectData *dd = (DisconnectData *)g_object_get_data (self, "alive-object-data");
|
2015-10-25 06:13:13 +00:00
|
|
|
|
|
|
|
if (dd)
|
|
|
|
g_signal_handler_unblock (dd->instance, dd->id);
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GObject *obj;
|
|
|
|
GParamSpec *spec;
|
|
|
|
gulong modified_id;
|
|
|
|
} ObjectProperty;
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_object_property (ObjectProperty *p)
|
|
|
|
{
|
|
|
|
g_free (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
connect_controller (GObject *controller,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *signal,
|
2014-05-18 05:03:24 +00:00
|
|
|
GObject *model,
|
|
|
|
GParamSpec *spec,
|
|
|
|
GCallback func)
|
|
|
|
{
|
|
|
|
ObjectProperty *p;
|
|
|
|
|
|
|
|
p = g_new (ObjectProperty, 1);
|
|
|
|
p->obj = model;
|
|
|
|
p->spec = spec;
|
|
|
|
|
|
|
|
p->modified_id = g_signal_connect_data (controller, signal, func, p,
|
|
|
|
(GClosureNotify)free_object_property, 0);
|
|
|
|
g_object_set_data (controller, "object-property", p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
block_controller (GObject *controller)
|
|
|
|
{
|
|
|
|
ObjectProperty *p = g_object_get_data (controller, "object-property");
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
g_signal_handler_block (controller, p->modified_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unblock_controller (GObject *controller)
|
|
|
|
{
|
|
|
|
ObjectProperty *p = g_object_get_data (controller, "object-property");
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
g_signal_handler_unblock (controller, p->modified_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property_value (GObject *object, GParamSpec *pspec, GValue *value)
|
|
|
|
{
|
2019-04-02 21:56:26 +00:00
|
|
|
g_object_get_property (object, pspec->name, value);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property_value (GObject *object, GParamSpec *pspec, GValue *value)
|
|
|
|
{
|
2019-04-02 21:56:26 +00:00
|
|
|
g_object_set_property (object, pspec->name, value);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notify_property (GObject *object, GParamSpec *pspec)
|
|
|
|
{
|
2019-04-02 21:56:26 +00:00
|
|
|
g_object_notify (object, pspec->name);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
int_modified (GtkAdjustment *adj, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
2021-11-30 23:38:33 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
g_value_init (&val, G_TYPE_INT);
|
|
|
|
g_value_set_int (&val, (int) gtk_adjustment_get_value (adj));
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
int_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_INT);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
if (g_value_get_int (&val) != (int)gtk_adjustment_get_value (adj))
|
|
|
|
{
|
|
|
|
block_controller (G_OBJECT (adj));
|
|
|
|
gtk_adjustment_set_value (adj, g_value_get_int (&val));
|
|
|
|
unblock_controller (G_OBJECT (adj));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
uint_modified (GtkAdjustment *adj, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
2021-11-30 23:38:33 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
g_value_init (&val, G_TYPE_UINT);
|
|
|
|
g_value_set_uint (&val, (guint) gtk_adjustment_get_value (adj));
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
uint_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_UINT);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
if (g_value_get_uint (&val) != (guint)gtk_adjustment_get_value (adj))
|
|
|
|
{
|
|
|
|
block_controller (G_OBJECT (adj));
|
|
|
|
gtk_adjustment_set_value (adj, g_value_get_uint (&val));
|
|
|
|
unblock_controller (G_OBJECT (adj));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
float_modified (GtkAdjustment *adj, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
2021-11-30 23:38:33 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
g_value_init (&val, G_TYPE_FLOAT);
|
|
|
|
g_value_set_float (&val, (float) gtk_adjustment_get_value (adj));
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
float_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_FLOAT);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
if (g_value_get_float (&val) != (float) gtk_adjustment_get_value (adj))
|
|
|
|
{
|
|
|
|
block_controller (G_OBJECT (adj));
|
|
|
|
gtk_adjustment_set_value (adj, g_value_get_float (&val));
|
|
|
|
unblock_controller (G_OBJECT (adj));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
double_modified (GtkAdjustment *adj, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
2021-11-30 23:38:33 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
g_value_init (&val, G_TYPE_DOUBLE);
|
|
|
|
g_value_set_double (&val, gtk_adjustment_get_value (adj));
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
double_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_DOUBLE);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
if (g_value_get_double (&val) != gtk_adjustment_get_value (adj))
|
|
|
|
{
|
|
|
|
block_controller (G_OBJECT (adj));
|
|
|
|
gtk_adjustment_set_value (adj, g_value_get_double (&val));
|
|
|
|
unblock_controller (G_OBJECT (adj));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
string_modified (GtkEntry *entry, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
2021-11-30 23:38:33 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
g_value_init (&val, G_TYPE_STRING);
|
2019-02-28 19:31:36 +00:00
|
|
|
g_value_set_static_string (&val, gtk_editable_get_text (GTK_EDITABLE (entry)));
|
2014-05-18 05:03:24 +00:00
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
2015-10-27 03:38:05 +00:00
|
|
|
static void
|
|
|
|
intern_string_modified (GtkEntry *entry, ObjectProperty *p)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *s;
|
2015-10-27 03:38:05 +00:00
|
|
|
|
2020-01-23 23:43:26 +00:00
|
|
|
s = gtk_editable_get_text (GTK_EDITABLE (entry));
|
2015-10-27 03:38:05 +00:00
|
|
|
if (g_str_equal (p->spec->name, "id"))
|
2020-01-23 23:43:26 +00:00
|
|
|
gtk_css_node_set_id (GTK_CSS_NODE (p->obj), g_quark_from_string (s));
|
2015-10-27 03:38:05 +00:00
|
|
|
else if (g_str_equal (p->spec->name, "name"))
|
2020-01-23 23:43:26 +00:00
|
|
|
gtk_css_node_set_name (GTK_CSS_NODE (p->obj), g_quark_from_string (s));
|
2015-10-27 03:38:05 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 12:35:16 +00:00
|
|
|
static void
|
|
|
|
attr_list_modified (GtkEntry *entry, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
attrs = pango_attr_list_from_string (gtk_editable_get_text (GTK_EDITABLE (entry)));
|
|
|
|
if (!attrs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_value_init (&val, PANGO_TYPE_ATTR_LIST);
|
|
|
|
g_value_take_boxed (&val, attrs);
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
|
|
|
string_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkEntry *entry = GTK_ENTRY (data);
|
|
|
|
GValue val = G_VALUE_INIT;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *str;
|
|
|
|
const char *text;
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_STRING);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
str = g_value_get_string (&val);
|
|
|
|
if (str == NULL)
|
|
|
|
str = "";
|
2019-02-28 19:31:36 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (entry));
|
2014-05-18 05:03:24 +00:00
|
|
|
if (g_strcmp0 (str, text) != 0)
|
|
|
|
{
|
|
|
|
block_controller (G_OBJECT (entry));
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), str);
|
2014-05-18 05:03:24 +00:00
|
|
|
unblock_controller (G_OBJECT (entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
2022-03-25 12:35:16 +00:00
|
|
|
static void
|
|
|
|
attr_list_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkEntry *entry = GTK_ENTRY (data);
|
|
|
|
GValue val = G_VALUE_INIT;
|
2022-04-03 19:53:34 +00:00
|
|
|
char *str = NULL;
|
2022-03-25 12:35:16 +00:00
|
|
|
const char *text;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
g_value_init (&val, PANGO_TYPE_ATTR_LIST);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
attrs = g_value_get_boxed (&val);
|
2022-04-03 19:53:34 +00:00
|
|
|
if (attrs)
|
|
|
|
str = pango_attr_list_to_string (attrs);
|
2022-03-25 12:35:16 +00:00
|
|
|
if (str == NULL)
|
|
|
|
str = g_strdup ("");
|
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (entry));
|
|
|
|
if (g_strcmp0 (str, text) != 0)
|
|
|
|
{
|
|
|
|
block_controller (G_OBJECT (entry));
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), str);
|
|
|
|
unblock_controller (G_OBJECT (entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
2015-10-25 06:13:13 +00:00
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
strv_modified (GtkInspectorStrvEditor *self, ObjectProperty *p)
|
2015-10-25 06:13:13 +00:00
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
2020-07-24 18:40:36 +00:00
|
|
|
char **strv;
|
2015-10-25 06:13:13 +00:00
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_STRV);
|
2019-11-09 00:13:28 +00:00
|
|
|
strv = gtk_inspector_strv_editor_get_strv (self);
|
2015-10-25 06:13:13 +00:00
|
|
|
g_value_take_boxed (&val, strv);
|
2019-11-09 00:13:28 +00:00
|
|
|
block_notify (G_OBJECT (self));
|
2015-10-25 06:13:13 +00:00
|
|
|
set_property_value (p->obj, p->spec, &val);
|
2019-11-09 00:13:28 +00:00
|
|
|
unblock_notify (G_OBJECT (self));
|
2015-10-25 06:13:13 +00:00
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
strv_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorStrvEditor *self = data;
|
2015-10-25 06:13:13 +00:00
|
|
|
GValue val = G_VALUE_INIT;
|
2020-07-24 18:40:36 +00:00
|
|
|
char **strv;
|
2015-10-25 06:13:13 +00:00
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_STRV);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
strv = g_value_get_boxed (&val);
|
2019-11-09 00:13:28 +00:00
|
|
|
block_controller (G_OBJECT (self));
|
|
|
|
gtk_inspector_strv_editor_set_strv (self, strv);
|
|
|
|
unblock_controller (G_OBJECT (self));
|
2015-10-25 06:13:13 +00:00
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
2019-04-12 03:42:31 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
2020-08-07 03:45:30 +00:00
|
|
|
bool_modified (GtkCheckButton *cb,
|
|
|
|
ObjectProperty *p)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_BOOLEAN);
|
2020-08-07 03:45:30 +00:00
|
|
|
g_value_set_boolean (&val, gtk_check_button_get_active (cb));
|
2014-05-18 05:03:24 +00:00
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bool_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButton *cb = GTK_CHECK_BUTTON (data);
|
2014-05-18 05:03:24 +00:00
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_BOOLEAN);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
if (g_value_get_boolean (&val) != gtk_check_button_get_active (cb))
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
block_controller (G_OBJECT (cb));
|
|
|
|
gtk_check_button_set_active (cb, g_value_get_boolean (&val));
|
|
|
|
unblock_controller (G_OBJECT (cb));
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-13 21:19:53 +00:00
|
|
|
enum_modified (GtkDropDown *dropdown, GParamSpec *pspec, ObjectProperty *p)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2019-12-13 21:19:53 +00:00
|
|
|
int i = gtk_drop_down_get_selected (dropdown);
|
2014-05-18 05:03:24 +00:00
|
|
|
GEnumClass *eclass;
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
eclass = G_ENUM_CLASS (g_type_class_peek (p->spec->value_type));
|
|
|
|
|
|
|
|
g_value_init (&val, p->spec->value_type);
|
|
|
|
g_value_set_enum (&val, eclass->values[i].value);
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
enum_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
GEnumClass *eclass;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
eclass = G_ENUM_CLASS (g_type_class_peek (pspec->value_type));
|
|
|
|
|
|
|
|
g_value_init (&val, pspec->value_type);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < eclass->n_values)
|
|
|
|
{
|
|
|
|
if (eclass->values[i].value == g_value_get_enum (&val))
|
|
|
|
break;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
2019-12-13 21:19:53 +00:00
|
|
|
block_controller (G_OBJECT (data));
|
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (data), i);
|
|
|
|
unblock_controller (G_OBJECT (data));
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
flags_modified (GtkCheckButton *button, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
gboolean active;
|
|
|
|
GFlagsClass *fclass;
|
|
|
|
guint flags;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2014-05-18 05:03:24 +00:00
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
2020-08-30 23:36:27 +00:00
|
|
|
active = gtk_check_button_get_active (button);
|
2014-05-18 05:03:24 +00:00
|
|
|
i = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "index"));
|
|
|
|
fclass = G_FLAGS_CLASS (g_type_class_peek (p->spec->value_type));
|
|
|
|
|
|
|
|
g_value_init (&val, p->spec->value_type);
|
|
|
|
get_property_value (p->obj, p->spec, &val);
|
|
|
|
flags = g_value_get_flags (&val);
|
|
|
|
if (active)
|
|
|
|
flags |= fclass->values[i].value;
|
|
|
|
else
|
|
|
|
flags &= ~fclass->values[i].value;
|
|
|
|
g_value_set_flags (&val, flags);
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
static char *
|
|
|
|
flags_to_string (GFlagsClass *flags_class,
|
|
|
|
guint value)
|
|
|
|
{
|
|
|
|
GString *str;
|
|
|
|
GFlagsValue *flags_value;
|
|
|
|
|
|
|
|
str = g_string_new (NULL);
|
|
|
|
|
|
|
|
while ((str->len == 0 || value != 0) &&
|
|
|
|
(flags_value = g_flags_get_first_value (flags_class, value)) != NULL)
|
|
|
|
{
|
|
|
|
if (str->len > 0)
|
|
|
|
g_string_append (str, " | ");
|
|
|
|
|
|
|
|
g_string_append (str, flags_value->value_nick);
|
|
|
|
|
|
|
|
value &= ~flags_value->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the extra bits */
|
|
|
|
if (value != 0 || str->len == 0)
|
|
|
|
{
|
|
|
|
if (str->len > 0)
|
|
|
|
g_string_append (str, " | ");
|
|
|
|
|
|
|
|
g_string_append_printf (str, "0x%x", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
|
|
|
flags_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
GFlagsClass *fclass;
|
|
|
|
guint flags;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2019-04-12 03:42:31 +00:00
|
|
|
GtkPopover *popover;
|
|
|
|
GtkWidget *sw;
|
2014-05-18 05:03:24 +00:00
|
|
|
GtkWidget *viewport;
|
|
|
|
GtkWidget *box;
|
2019-04-12 03:42:31 +00:00
|
|
|
char *str;
|
2020-05-08 06:19:18 +00:00
|
|
|
GtkWidget *child;
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
fclass = G_FLAGS_CLASS (g_type_class_peek (pspec->value_type));
|
|
|
|
|
|
|
|
g_value_init (&val, pspec->value_type);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
flags = g_value_get_flags (&val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
str = flags_to_string (fclass, flags);
|
2019-05-20 23:33:07 +00:00
|
|
|
gtk_menu_button_set_label (GTK_MENU_BUTTON (data), str);
|
2019-04-12 03:42:31 +00:00
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
popover = gtk_menu_button_get_popover (GTK_MENU_BUTTON (data));
|
2020-05-02 02:22:20 +00:00
|
|
|
sw = gtk_popover_get_child (GTK_POPOVER (popover));
|
2020-05-02 04:51:20 +00:00
|
|
|
viewport = gtk_scrolled_window_get_child (GTK_SCROLLED_WINDOW (sw));
|
2020-05-01 19:43:09 +00:00
|
|
|
box = gtk_viewport_get_child (GTK_VIEWPORT (viewport));
|
2020-05-08 06:19:18 +00:00
|
|
|
for (child = gtk_widget_get_first_child (box);
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
|
|
|
block_controller (G_OBJECT (child));
|
|
|
|
|
|
|
|
for (child = gtk_widget_get_first_child (box), i = 0;
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child), i++)
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (child),
|
|
|
|
(fclass->values[i].value & flags) != 0);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
2020-05-08 06:19:18 +00:00
|
|
|
for (child = gtk_widget_get_first_child (box);
|
|
|
|
child != NULL;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
|
|
|
unblock_controller (G_OBJECT (child));
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gunichar
|
|
|
|
unichar_get_value (GtkEntry *entry)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text = gtk_editable_get_text (GTK_EDITABLE (entry));
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
if (text[0])
|
|
|
|
return g_utf8_get_char (text);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unichar_modified (GtkEntry *entry, ObjectProperty *p)
|
|
|
|
{
|
|
|
|
gunichar u = unichar_get_value (entry);
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, p->spec->value_type);
|
|
|
|
g_value_set_uint (&val, u);
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
unichar_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkEntry *entry = GTK_ENTRY (data);
|
|
|
|
gunichar new_val;
|
|
|
|
gunichar old_val = unichar_get_value (entry);
|
|
|
|
GValue val = G_VALUE_INIT;
|
2020-07-24 18:40:36 +00:00
|
|
|
char buf[7];
|
2020-07-24 13:54:49 +00:00
|
|
|
int len;
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_value_init (&val, pspec->value_type);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
new_val = (gunichar)g_value_get_uint (&val);
|
2019-12-25 00:40:50 +00:00
|
|
|
g_value_unset (&val);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
if (new_val != old_val)
|
|
|
|
{
|
|
|
|
if (!new_val)
|
|
|
|
len = 0;
|
|
|
|
else
|
|
|
|
len = g_unichar_to_utf8 (new_val, buf);
|
|
|
|
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
block_controller (G_OBJECT (entry));
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), buf);
|
2014-05-18 05:03:24 +00:00
|
|
|
unblock_controller (G_OBJECT (entry));
|
|
|
|
}
|
|
|
|
}
|
2014-06-05 09:49:34 +00:00
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
|
|
|
pointer_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkLabel *label = GTK_LABEL (data);
|
2020-07-24 18:40:36 +00:00
|
|
|
char *str;
|
2014-05-18 05:03:24 +00:00
|
|
|
gpointer ptr;
|
|
|
|
|
|
|
|
g_object_get (object, pspec->name, &ptr, NULL);
|
|
|
|
|
2014-05-19 04:17:23 +00:00
|
|
|
str = g_strdup_printf (_("Pointer: %p"), ptr);
|
2014-05-18 05:03:24 +00:00
|
|
|
gtk_label_set_text (label, str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
2014-05-18 05:03:24 +00:00
|
|
|
object_label (GObject *obj, GParamSpec *pspec)
|
|
|
|
{
|
2019-04-12 03:42:31 +00:00
|
|
|
return g_strdup_printf ("%p", obj);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
object_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *label, *button;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *str;
|
2014-05-18 05:03:24 +00:00
|
|
|
GObject *obj;
|
|
|
|
|
2020-05-08 06:19:18 +00:00
|
|
|
label = gtk_widget_get_first_child (GTK_WIDGET (data));
|
|
|
|
button = gtk_widget_get_next_sibling (label);
|
2014-05-18 05:03:24 +00:00
|
|
|
g_object_get (object, pspec->name, &obj, NULL);
|
|
|
|
|
|
|
|
str = object_label (obj, pspec);
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (label), str);
|
|
|
|
gtk_widget_set_sensitive (button, G_IS_OBJECT (obj));
|
|
|
|
|
|
|
|
if (obj)
|
|
|
|
g_object_unref (obj);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
object_properties (GtkInspectorPropEditor *self)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
GObject *obj;
|
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
g_object_get (self->object, self->name, &obj, NULL);
|
2014-05-18 05:03:24 +00:00
|
|
|
if (G_IS_OBJECT (obj))
|
2019-11-09 00:13:28 +00:00
|
|
|
g_signal_emit (self, signals[SHOW_OBJECT], 0, obj, self->name, "properties");
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-10-28 14:00:37 +00:00
|
|
|
rgba_modified (GtkColorDialogButton *cb, GParamSpec *ignored, ObjectProperty *p)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, p->spec->value_type);
|
|
|
|
g_object_get_property (G_OBJECT (cb), "rgba", &val);
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rgba_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkColorChooser *cb = GTK_COLOR_CHOOSER (data);
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
GdkRGBA *color;
|
|
|
|
|
|
|
|
g_value_init (&val, GDK_TYPE_RGBA);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
color = g_value_get_boxed (&val);
|
|
|
|
|
2022-10-28 14:00:37 +00:00
|
|
|
if (color != NULL)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
block_controller (G_OBJECT (cb));
|
2022-10-28 14:00:37 +00:00
|
|
|
gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (cb), color);
|
2014-05-18 05:03:24 +00:00
|
|
|
unblock_controller (G_OBJECT (cb));
|
|
|
|
}
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-10-28 14:00:37 +00:00
|
|
|
font_modified (GtkFontDialogButton *fb, GParamSpec *pspec, ObjectProperty *p)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&val, PANGO_TYPE_FONT_DESCRIPTION);
|
|
|
|
g_object_get_property (G_OBJECT (fb), "font-desc", &val);
|
|
|
|
set_property_value (p->obj, p->spec, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
font_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
2022-10-28 14:00:37 +00:00
|
|
|
GtkFontDialogButton *fb = GTK_FONT_DIALOG_BUTTON (data);
|
2014-05-18 05:03:24 +00:00
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
const PangoFontDescription *font_desc;
|
|
|
|
|
|
|
|
g_value_init (&val, PANGO_TYPE_FONT_DESCRIPTION);
|
|
|
|
get_property_value (object, pspec, &val);
|
|
|
|
|
|
|
|
font_desc = g_value_get_boxed (&val);
|
|
|
|
|
2022-10-28 14:00:37 +00:00
|
|
|
block_controller (G_OBJECT (fb));
|
|
|
|
gtk_font_dialog_button_set_font_desc (fb, font_desc);
|
|
|
|
unblock_controller (G_OBJECT (fb));
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
2020-07-14 00:49:56 +00:00
|
|
|
static char *
|
|
|
|
describe_expression (GtkExpression *expression)
|
|
|
|
{
|
|
|
|
if (expression == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (G_TYPE_CHECK_INSTANCE_TYPE (expression, GTK_TYPE_CONSTANT_EXPRESSION))
|
|
|
|
{
|
|
|
|
const GValue *value = gtk_constant_expression_get_value (expression);
|
|
|
|
GValue dest = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&dest, G_TYPE_STRING);
|
|
|
|
if (g_value_transform (value, &dest))
|
|
|
|
{
|
2020-08-30 17:11:39 +00:00
|
|
|
/* Translators: %s is a type name, for example
|
|
|
|
* GtkPropertyExpression with value \"2.5\"
|
|
|
|
*/
|
2020-07-14 00:49:56 +00:00
|
|
|
char *res = g_strdup_printf (_("%s with value \"%s\""),
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (expression)),
|
|
|
|
g_value_get_string (&dest));
|
|
|
|
g_value_unset (&dest);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-30 17:11:39 +00:00
|
|
|
/* Translators: Both %s are type names, for example
|
|
|
|
* GtkPropertyExpression with type GObject
|
|
|
|
*/
|
2020-07-14 00:49:56 +00:00
|
|
|
return g_strdup_printf (_("%s with type %s"),
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (expression)),
|
|
|
|
g_type_name (G_VALUE_TYPE (value)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (G_TYPE_CHECK_INSTANCE_TYPE (expression, GTK_TYPE_OBJECT_EXPRESSION))
|
|
|
|
{
|
|
|
|
gpointer obj = gtk_object_expression_get_object (expression);
|
|
|
|
|
|
|
|
if (obj)
|
2020-08-30 17:11:39 +00:00
|
|
|
/* Translators: Both %s are type names, for example
|
|
|
|
* GtkObjectExpression for GtkStringObject 0x23456789
|
|
|
|
*/
|
2020-07-14 00:49:56 +00:00
|
|
|
return g_strdup_printf (_("%s for %s %p"),
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (expression)),
|
|
|
|
G_OBJECT_TYPE_NAME (obj), obj);
|
|
|
|
else
|
2020-08-30 17:11:39 +00:00
|
|
|
return g_strdup (g_type_name (G_TYPE_FROM_INSTANCE (expression)));
|
2020-07-14 00:49:56 +00:00
|
|
|
}
|
|
|
|
else if (G_TYPE_CHECK_INSTANCE_TYPE (expression, GTK_TYPE_PROPERTY_EXPRESSION))
|
|
|
|
{
|
|
|
|
GParamSpec *pspec = gtk_property_expression_get_pspec (expression);
|
|
|
|
GtkExpression *expr = gtk_property_expression_get_expression (expression);
|
|
|
|
char *str;
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
str = describe_expression (expr);
|
2020-08-30 17:11:39 +00:00
|
|
|
/* Translators: The first %s is a type name, %s:%s is a qualified
|
|
|
|
* property name, and is a value, for example
|
|
|
|
* GtkPropertyExpression for property GtkLabellabel on: GObjectExpression ...
|
|
|
|
*/
|
2020-07-14 00:49:56 +00:00
|
|
|
res = g_strdup_printf ("%s for property %s:%s on: %s",
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (expression)),
|
|
|
|
g_type_name (pspec->owner_type),
|
|
|
|
pspec->name,
|
|
|
|
str);
|
|
|
|
g_free (str);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else
|
2020-08-30 17:11:39 +00:00
|
|
|
/* Translators: Both %s are type names, for example
|
|
|
|
* GtkPropertyExpression with value type: gchararray
|
|
|
|
*/
|
2020-07-14 00:49:56 +00:00
|
|
|
return g_strdup_printf (_("%s with value type %s"),
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (expression)),
|
|
|
|
g_type_name (gtk_expression_get_value_type (expression)));
|
|
|
|
}
|
|
|
|
|
2021-03-21 20:02:39 +00:00
|
|
|
static void
|
|
|
|
toggle_unicode (GtkToggleButton *button,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkWidget *stack)
|
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *unicode;
|
|
|
|
|
|
|
|
entry = gtk_stack_get_child_by_name (GTK_STACK (stack), "entry");
|
|
|
|
unicode = gtk_stack_get_child_by_name (GTK_STACK (stack), "unicode");
|
|
|
|
if (gtk_toggle_button_get_active (button))
|
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
const char *p;
|
|
|
|
GString *s;
|
|
|
|
|
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (entry));
|
|
|
|
s = g_string_sized_new (6 * strlen (text));
|
|
|
|
for (p = text; *p; p = g_utf8_next_char (p))
|
|
|
|
{
|
|
|
|
gunichar ch = g_utf8_get_char (p);
|
|
|
|
if (s->len > 0)
|
|
|
|
g_string_append_c (s, ' ');
|
|
|
|
g_string_append_printf (s, "U+%04X", ch);
|
|
|
|
}
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (unicode), s->str);
|
|
|
|
g_string_free (s, TRUE);
|
|
|
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), "unicode");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (unicode), "");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), "entry");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static GtkWidget *
|
2014-05-31 01:35:39 +00:00
|
|
|
property_editor (GObject *object,
|
2014-05-18 05:03:24 +00:00
|
|
|
GParamSpec *spec,
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
GtkWidget *prop_edit;
|
|
|
|
GtkAdjustment *adj;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *msg;
|
2014-05-18 05:03:24 +00:00
|
|
|
GType type = G_PARAM_SPEC_TYPE (spec);
|
|
|
|
|
|
|
|
if (type == G_TYPE_PARAM_INT)
|
|
|
|
{
|
|
|
|
adj = gtk_adjustment_new (G_PARAM_SPEC_INT (spec)->default_value,
|
|
|
|
G_PARAM_SPEC_INT (spec)->minimum,
|
|
|
|
G_PARAM_SPEC_INT (spec)->maximum,
|
|
|
|
1,
|
|
|
|
MAX ((G_PARAM_SPEC_INT (spec)->maximum - G_PARAM_SPEC_INT (spec)->minimum) / 10, 1),
|
|
|
|
0.0);
|
|
|
|
|
|
|
|
prop_edit = gtk_spin_button_new (adj, 1.0, 0);
|
|
|
|
|
2019-05-01 04:57:54 +00:00
|
|
|
g_object_connect_property (object, spec, G_CALLBACK (int_changed), adj, G_OBJECT (adj));
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
connect_controller (G_OBJECT (adj), "value_changed",
|
|
|
|
object, spec, G_CALLBACK (int_modified));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_UINT)
|
|
|
|
{
|
|
|
|
adj = gtk_adjustment_new (G_PARAM_SPEC_UINT (spec)->default_value,
|
|
|
|
G_PARAM_SPEC_UINT (spec)->minimum,
|
|
|
|
G_PARAM_SPEC_UINT (spec)->maximum,
|
|
|
|
1,
|
|
|
|
MAX ((G_PARAM_SPEC_UINT (spec)->maximum - G_PARAM_SPEC_UINT (spec)->minimum) / 10, 1),
|
|
|
|
0.0);
|
|
|
|
|
|
|
|
prop_edit = gtk_spin_button_new (adj, 1.0, 0);
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (uint_changed),
|
|
|
|
adj, G_OBJECT (adj));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (adj), "value_changed",
|
|
|
|
object, spec, G_CALLBACK (uint_modified));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_FLOAT)
|
|
|
|
{
|
|
|
|
adj = gtk_adjustment_new (G_PARAM_SPEC_FLOAT (spec)->default_value,
|
|
|
|
G_PARAM_SPEC_FLOAT (spec)->minimum,
|
|
|
|
G_PARAM_SPEC_FLOAT (spec)->maximum,
|
|
|
|
0.1,
|
|
|
|
MAX ((G_PARAM_SPEC_FLOAT (spec)->maximum - G_PARAM_SPEC_FLOAT (spec)->minimum) / 10, 0.1),
|
|
|
|
0.0);
|
|
|
|
|
|
|
|
prop_edit = gtk_spin_button_new (adj, 0.1, 2);
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (float_changed),
|
|
|
|
adj, G_OBJECT (adj));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (adj), "value_changed",
|
|
|
|
object, spec, G_CALLBACK (float_modified));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_DOUBLE)
|
|
|
|
{
|
|
|
|
adj = gtk_adjustment_new (G_PARAM_SPEC_DOUBLE (spec)->default_value,
|
|
|
|
G_PARAM_SPEC_DOUBLE (spec)->minimum,
|
|
|
|
G_PARAM_SPEC_DOUBLE (spec)->maximum,
|
|
|
|
0.1,
|
2016-03-10 00:40:06 +00:00
|
|
|
1.0,
|
2014-05-18 05:03:24 +00:00
|
|
|
0.0);
|
|
|
|
|
|
|
|
prop_edit = gtk_spin_button_new (adj, 0.1, 2);
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (double_changed),
|
|
|
|
adj, G_OBJECT (adj));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (adj), "value_changed",
|
|
|
|
object, spec, G_CALLBACK (double_modified));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_STRING)
|
|
|
|
{
|
2021-03-21 20:02:39 +00:00
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *stack;
|
|
|
|
GtkWidget *unicode;
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (string_changed),
|
2021-03-21 20:02:39 +00:00
|
|
|
entry, G_OBJECT (entry));
|
2014-05-18 05:03:24 +00:00
|
|
|
|
2015-10-27 03:38:05 +00:00
|
|
|
if (GTK_IS_CSS_NODE (object))
|
2021-03-21 20:02:39 +00:00
|
|
|
connect_controller (G_OBJECT (entry), "changed",
|
2015-10-27 03:38:05 +00:00
|
|
|
object, spec, G_CALLBACK (intern_string_modified));
|
|
|
|
else
|
2021-03-21 20:02:39 +00:00
|
|
|
connect_controller (G_OBJECT (entry), "changed",
|
2015-10-27 03:38:05 +00:00
|
|
|
object, spec, G_CALLBACK (string_modified));
|
2021-03-21 20:02:39 +00:00
|
|
|
|
|
|
|
unicode = gtk_entry_new ();
|
|
|
|
gtk_editable_set_editable (GTK_EDITABLE (unicode), FALSE);
|
|
|
|
|
|
|
|
stack = gtk_stack_new ();
|
|
|
|
gtk_stack_add_named (GTK_STACK (stack), entry, "entry");
|
|
|
|
gtk_stack_add_named (GTK_STACK (stack), unicode, "unicode");
|
|
|
|
|
|
|
|
prop_edit = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
gtk_box_append (GTK_BOX (prop_edit), stack);
|
|
|
|
|
|
|
|
button = gtk_toggle_button_new_with_label ("Unicode");
|
|
|
|
gtk_box_append (GTK_BOX (prop_edit), button);
|
|
|
|
|
|
|
|
g_signal_connect (button, "notify::active", G_CALLBACK (toggle_unicode), stack);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_BOOLEAN)
|
|
|
|
{
|
2019-04-12 03:42:31 +00:00
|
|
|
prop_edit = gtk_check_button_new_with_label ("");
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (bool_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (prop_edit), "toggled",
|
|
|
|
object, spec, G_CALLBACK (bool_modified));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_ENUM)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GEnumClass *eclass;
|
2020-07-26 13:34:08 +00:00
|
|
|
GtkStringList *names;
|
2020-07-24 13:54:49 +00:00
|
|
|
int j;
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
eclass = G_ENUM_CLASS (g_type_class_ref (spec->value_type));
|
|
|
|
|
2020-07-26 13:34:08 +00:00
|
|
|
names = gtk_string_list_new (NULL);
|
2019-12-13 21:19:53 +00:00
|
|
|
for (j = 0; j < eclass->n_values; j++)
|
2020-07-26 13:34:08 +00:00
|
|
|
gtk_string_list_append (names, eclass->values[j].value_name);
|
2019-12-13 21:19:53 +00:00
|
|
|
|
2020-07-26 13:34:08 +00:00
|
|
|
prop_edit = gtk_drop_down_new (G_LIST_MODEL (names), NULL);
|
2019-12-13 21:19:53 +00:00
|
|
|
|
|
|
|
connect_controller (G_OBJECT (prop_edit), "notify::selected",
|
|
|
|
object, spec, G_CALLBACK (enum_modified));
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_type_class_unref (eclass);
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (enum_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_FLAGS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GtkWidget *box;
|
2019-04-12 03:42:31 +00:00
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *popover;
|
2014-05-18 05:03:24 +00:00
|
|
|
GFlagsClass *fclass;
|
2020-07-24 13:54:49 +00:00
|
|
|
int j;
|
2014-05-18 05:03:24 +00:00
|
|
|
|
2020-05-02 02:22:20 +00:00
|
|
|
popover = gtk_popover_new ();
|
2019-04-12 03:42:31 +00:00
|
|
|
prop_edit = gtk_menu_button_new ();
|
|
|
|
gtk_menu_button_set_popover (GTK_MENU_BUTTON (prop_edit), popover);
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
sw = gtk_scrolled_window_new ();
|
2020-05-02 02:22:20 +00:00
|
|
|
gtk_popover_set_child (GTK_POPOVER (popover), sw);
|
2019-04-12 03:42:31 +00:00
|
|
|
g_object_set (sw,
|
2020-02-25 23:25:52 +00:00
|
|
|
"hexpand", TRUE,
|
|
|
|
"vexpand", TRUE,
|
2014-05-18 05:03:24 +00:00
|
|
|
"hscrollbar-policy", GTK_POLICY_NEVER,
|
|
|
|
"vscrollbar-policy", GTK_POLICY_NEVER,
|
|
|
|
NULL);
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), box);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
fclass = G_FLAGS_CLASS (g_type_class_ref (spec->value_type));
|
|
|
|
|
|
|
|
for (j = 0; j < fclass->n_values; j++)
|
|
|
|
{
|
|
|
|
GtkWidget *b;
|
|
|
|
|
2019-04-12 03:42:31 +00:00
|
|
|
b = gtk_check_button_new_with_label (fclass->values[j].value_nick);
|
2014-05-18 05:03:24 +00:00
|
|
|
g_object_set_data (G_OBJECT (b), "index", GINT_TO_POINTER (j));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), b);
|
2014-05-18 05:03:24 +00:00
|
|
|
connect_controller (G_OBJECT (b), "toggled",
|
|
|
|
object, spec, G_CALLBACK (flags_modified));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j >= 10)
|
2021-11-30 23:38:33 +00:00
|
|
|
{
|
|
|
|
g_object_set (sw,
|
|
|
|
"vscrollbar-policy", GTK_POLICY_AUTOMATIC,
|
|
|
|
"min-content-height", 250,
|
|
|
|
NULL);
|
|
|
|
}
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_type_class_unref (fclass);
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (flags_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_UNICHAR)
|
|
|
|
{
|
|
|
|
prop_edit = gtk_entry_new ();
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (prop_edit), 1);
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (unichar_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (prop_edit), "changed",
|
|
|
|
object, spec, G_CALLBACK (unichar_modified));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_POINTER)
|
|
|
|
{
|
|
|
|
prop_edit = gtk_label_new ("");
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (pointer_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_OBJECT)
|
|
|
|
{
|
|
|
|
GtkWidget *label, *button;
|
|
|
|
|
|
|
|
prop_edit = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
2014-05-19 04:17:23 +00:00
|
|
|
button = gtk_button_new_with_label (_("Properties"));
|
2014-05-18 05:03:24 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (object_properties),
|
2019-11-09 00:13:28 +00:00
|
|
|
self);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (prop_edit), label);
|
|
|
|
gtk_box_append (GTK_BOX (prop_edit), button);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (object_changed),
|
|
|
|
prop_edit, G_OBJECT (label));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_BOXED &&
|
|
|
|
G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_RGBA)
|
|
|
|
{
|
2022-10-28 14:00:37 +00:00
|
|
|
prop_edit = gtk_color_dialog_button_new (gtk_color_dialog_new ());
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (rgba_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (prop_edit), "notify::rgba",
|
|
|
|
object, spec, G_CALLBACK (rgba_modified));
|
|
|
|
}
|
|
|
|
else if (type == G_TYPE_PARAM_BOXED &&
|
|
|
|
G_PARAM_SPEC_VALUE_TYPE (spec) == PANGO_TYPE_FONT_DESCRIPTION)
|
|
|
|
{
|
2022-10-28 14:00:37 +00:00
|
|
|
prop_edit = gtk_font_dialog_button_new (gtk_font_dialog_new ());
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (font_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (prop_edit), "notify::font-desc",
|
|
|
|
object, spec, G_CALLBACK (font_modified));
|
|
|
|
}
|
2015-10-25 06:13:13 +00:00
|
|
|
else if (type == G_TYPE_PARAM_BOXED &&
|
|
|
|
G_PARAM_SPEC_VALUE_TYPE (spec) == G_TYPE_STRV)
|
|
|
|
{
|
|
|
|
prop_edit = g_object_new (gtk_inspector_strv_editor_get_type (),
|
|
|
|
"visible", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (strv_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (prop_edit), "changed",
|
|
|
|
object, spec, G_CALLBACK (strv_modified));
|
|
|
|
|
|
|
|
gtk_widget_set_halign (prop_edit, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (prop_edit, GTK_ALIGN_CENTER);
|
|
|
|
}
|
2022-03-25 12:35:16 +00:00
|
|
|
else if (type == G_TYPE_PARAM_BOXED &&
|
|
|
|
G_PARAM_SPEC_VALUE_TYPE (spec) == PANGO_TYPE_ATTR_LIST)
|
|
|
|
{
|
|
|
|
prop_edit = gtk_entry_new ();
|
|
|
|
|
|
|
|
g_object_connect_property (object, spec,
|
|
|
|
G_CALLBACK (attr_list_changed),
|
|
|
|
prop_edit, G_OBJECT (prop_edit));
|
|
|
|
|
|
|
|
connect_controller (G_OBJECT (prop_edit), "changed",
|
|
|
|
object, spec, G_CALLBACK (attr_list_modified));
|
|
|
|
}
|
2020-07-14 00:49:56 +00:00
|
|
|
else if (type == GTK_TYPE_PARAM_SPEC_EXPRESSION)
|
|
|
|
{
|
|
|
|
GtkExpression *expression;
|
|
|
|
g_object_get (object, spec->name, &expression, NULL);
|
|
|
|
msg = describe_expression (expression);
|
|
|
|
prop_edit = gtk_label_new (msg);
|
|
|
|
g_free (msg);
|
|
|
|
g_clear_pointer (&expression, gtk_expression_unref);
|
|
|
|
gtk_widget_set_halign (prop_edit, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (prop_edit, GTK_ALIGN_CENTER);
|
|
|
|
}
|
2014-05-18 05:03:24 +00:00
|
|
|
else
|
|
|
|
{
|
2014-05-19 04:17:23 +00:00
|
|
|
msg = g_strdup_printf (_("Uneditable property type: %s"),
|
2014-05-18 05:03:24 +00:00
|
|
|
g_type_name (G_PARAM_SPEC_TYPE (spec)));
|
|
|
|
prop_edit = gtk_label_new (msg);
|
|
|
|
g_free (msg);
|
|
|
|
gtk_widget_set_halign (prop_edit, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (prop_edit, GTK_ALIGN_CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
notify_property (object, spec);
|
|
|
|
|
2022-10-11 11:34:21 +00:00
|
|
|
if (GTK_IS_LABEL (prop_edit))
|
|
|
|
{
|
|
|
|
gtk_widget_set_can_focus (prop_edit, TRUE);
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (prop_edit),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL,
|
|
|
|
g_strdup_printf ("%s: %s",
|
|
|
|
self->name,
|
|
|
|
gtk_label_get_text (GTK_LABEL (prop_edit))),
|
2022-10-21 01:13:46 +00:00
|
|
|
-1);
|
2022-10-11 11:34:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (prop_edit),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, self->name,
|
2022-10-21 01:13:46 +00:00
|
|
|
-1);
|
2022-10-11 11:34:21 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
return prop_edit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
gtk_inspector_prop_editor_init (GtkInspectorPropEditor *self)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
g_object_set (self,
|
2019-04-12 03:42:31 +00:00
|
|
|
"orientation", GTK_ORIENTATION_HORIZONTAL,
|
2014-05-18 05:03:24 +00:00
|
|
|
"spacing", 10,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:52:03 +00:00
|
|
|
static GtkTreeModel *
|
2014-05-19 04:13:30 +00:00
|
|
|
gtk_cell_layout_get_model (GtkCellLayout *layout)
|
|
|
|
{
|
|
|
|
if (GTK_IS_TREE_VIEW_COLUMN (layout))
|
|
|
|
return gtk_tree_view_get_model (GTK_TREE_VIEW (gtk_tree_view_column_get_tree_view (GTK_TREE_VIEW_COLUMN (layout))));
|
|
|
|
else if (GTK_IS_ICON_VIEW (layout))
|
|
|
|
return gtk_icon_view_get_model (GTK_ICON_VIEW (layout));
|
2021-11-30 23:38:33 +00:00
|
|
|
else if (GTK_IS_COMBO_BOX (layout))
|
2014-05-19 04:13:30 +00:00
|
|
|
return gtk_combo_box_get_model (GTK_COMBO_BOX (layout));
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:52:03 +00:00
|
|
|
static GtkWidget *
|
2014-05-31 01:47:40 +00:00
|
|
|
gtk_cell_layout_get_widget (GtkCellLayout *layout)
|
|
|
|
{
|
|
|
|
if (GTK_IS_TREE_VIEW_COLUMN (layout))
|
|
|
|
return gtk_tree_view_column_get_tree_view (GTK_TREE_VIEW_COLUMN (layout));
|
|
|
|
else if (GTK_IS_WIDGET (layout))
|
|
|
|
return GTK_WIDGET (layout);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-19 04:13:30 +00:00
|
|
|
static void
|
2014-05-31 01:35:39 +00:00
|
|
|
model_properties (GtkButton *button,
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self)
|
2014-05-19 04:13:30 +00:00
|
|
|
{
|
|
|
|
GObject *model;
|
|
|
|
|
|
|
|
model = g_object_get_data (G_OBJECT (button), "model");
|
2019-11-09 00:13:28 +00:00
|
|
|
g_signal_emit (self, signals[SHOW_OBJECT], 0, model, "model", "data");
|
2014-05-19 04:13:30 +00:00
|
|
|
}
|
|
|
|
|
2014-05-25 03:30:01 +00:00
|
|
|
static void
|
2019-12-14 03:12:15 +00:00
|
|
|
attribute_mapping_changed (GtkDropDown *dropdown,
|
|
|
|
GParamSpec *pspec,
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self)
|
2014-05-25 03:30:01 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int col;
|
2014-05-25 03:30:01 +00:00
|
|
|
gpointer layout;
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
GtkCellArea *area;
|
|
|
|
|
2019-12-14 03:12:15 +00:00
|
|
|
col = gtk_drop_down_get_selected (dropdown) - 1;
|
2019-11-09 00:13:28 +00:00
|
|
|
layout = g_object_get_data (self->object, "gtk-inspector-cell-layout");
|
2014-05-25 03:30:01 +00:00
|
|
|
if (GTK_IS_CELL_LAYOUT (layout))
|
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
cell = GTK_CELL_RENDERER (self->object);
|
2014-05-25 03:30:01 +00:00
|
|
|
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (layout));
|
2019-11-09 00:13:28 +00:00
|
|
|
gtk_cell_area_attribute_disconnect (area, cell, self->name);
|
2014-05-25 03:30:01 +00:00
|
|
|
if (col != -1)
|
2019-11-09 00:13:28 +00:00
|
|
|
gtk_cell_area_attribute_connect (area, cell, self->name, col);
|
|
|
|
gtk_widget_set_sensitive (self->self, col == -1);
|
|
|
|
notify_property (self->object, find_property (self));
|
2014-05-31 01:47:40 +00:00
|
|
|
gtk_widget_queue_draw (gtk_cell_layout_get_widget (GTK_CELL_LAYOUT (layout)));
|
2014-05-25 03:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-14 03:12:15 +00:00
|
|
|
#define ATTRIBUTE_TYPE_HOLDER (attribute_holder_get_type ())
|
|
|
|
G_DECLARE_FINAL_TYPE (AttributeHolder, attribute_holder, ATTRIBUTE, HOLDER, GObject)
|
|
|
|
|
|
|
|
struct _AttributeHolder {
|
|
|
|
GObject parent_instance;
|
|
|
|
int column;
|
|
|
|
gboolean sensitive;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (AttributeHolder, attribute_holder, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
attribute_holder_init (AttributeHolder *holder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
attribute_holder_class_init (AttributeHolderClass *class)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static AttributeHolder *
|
|
|
|
attribute_holder_new (int column,
|
|
|
|
gboolean sensitive)
|
|
|
|
{
|
|
|
|
AttributeHolder *holder = g_object_new (ATTRIBUTE_TYPE_HOLDER, NULL);
|
|
|
|
holder->column = column;
|
|
|
|
holder->sensitive = sensitive;
|
|
|
|
return holder;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
attribute_setup_item (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
|
|
|
|
gtk_list_item_set_child (item, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
attribute_bind_item (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
AttributeHolder *holder;
|
|
|
|
|
|
|
|
holder = gtk_list_item_get_item (item);
|
|
|
|
label = gtk_list_item_get_child (item);
|
|
|
|
|
|
|
|
if (holder->column >= 0)
|
|
|
|
{
|
|
|
|
char *text = g_strdup_printf ("%d", holder->column);
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
2020-08-30 17:11:39 +00:00
|
|
|
gtk_label_set_label (GTK_LABEL (label), C_("column number", "None"));
|
2019-12-14 03:12:15 +00:00
|
|
|
|
|
|
|
gtk_list_item_set_selectable (item, holder->sensitive);
|
|
|
|
gtk_widget_set_sensitive (label, holder->sensitive);
|
|
|
|
}
|
|
|
|
|
2014-05-31 01:35:39 +00:00
|
|
|
static GtkWidget *
|
|
|
|
attribute_editor (GObject *object,
|
|
|
|
GParamSpec *spec,
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self)
|
2014-05-31 01:35:39 +00:00
|
|
|
{
|
|
|
|
gpointer layout;
|
|
|
|
GtkCellArea *area;
|
|
|
|
GtkTreeModel *model = NULL;
|
2020-07-24 13:54:49 +00:00
|
|
|
int col = -1;
|
2014-05-31 01:35:39 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *box;
|
2019-12-14 03:12:15 +00:00
|
|
|
GtkWidget *dropdown;
|
|
|
|
GListStore *store;
|
|
|
|
GtkListItemFactory *factory;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2019-12-14 03:12:15 +00:00
|
|
|
AttributeHolder *holder;
|
2014-05-31 01:35:39 +00:00
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
layout = g_object_get_data (object, "gtk-inspector-cell-layout");
|
|
|
|
if (GTK_IS_CELL_LAYOUT (layout))
|
|
|
|
{
|
|
|
|
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (layout));
|
|
|
|
col = gtk_cell_area_attribute_get_column (area,
|
2021-11-30 23:38:33 +00:00
|
|
|
GTK_CELL_RENDERER (object),
|
2019-11-09 00:13:28 +00:00
|
|
|
self->name);
|
2014-05-31 01:35:39 +00:00
|
|
|
model = gtk_cell_layout_get_model (GTK_CELL_LAYOUT (layout));
|
|
|
|
}
|
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
2014-05-31 01:35:39 +00:00
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
label = gtk_label_new (_("Attribute:"));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), label);
|
2014-05-31 01:35:39 +00:00
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
button = gtk_button_new_with_label (_("Model"));
|
2014-05-31 01:35:39 +00:00
|
|
|
g_object_set_data (G_OBJECT (button), "model", model);
|
2019-11-09 00:13:28 +00:00
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (model_properties), self);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2014-05-31 01:35:39 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), gtk_label_new (_("Column:")));
|
2020-07-26 13:34:08 +00:00
|
|
|
dropdown = gtk_drop_down_new (NULL, NULL);
|
2019-12-14 03:12:15 +00:00
|
|
|
|
|
|
|
store = g_list_store_new (ATTRIBUTE_TYPE_HOLDER);
|
|
|
|
holder = attribute_holder_new (-1, TRUE);
|
|
|
|
g_list_store_append (store, holder);
|
|
|
|
g_object_unref (holder);
|
|
|
|
|
2014-05-31 01:35:39 +00:00
|
|
|
for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
|
|
|
|
{
|
|
|
|
sensitive = g_value_type_transformable (gtk_tree_model_get_column_type (model, i),
|
|
|
|
spec->value_type);
|
2019-12-14 03:12:15 +00:00
|
|
|
holder = attribute_holder_new (i, sensitive);
|
|
|
|
g_list_store_append (store, holder);
|
|
|
|
g_object_unref (holder);
|
2014-05-31 01:35:39 +00:00
|
|
|
}
|
2019-12-14 03:12:15 +00:00
|
|
|
gtk_drop_down_set_model (GTK_DROP_DOWN (dropdown), G_LIST_MODEL (store));
|
|
|
|
g_object_unref (store);
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (attribute_setup_item), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (attribute_bind_item), NULL);
|
|
|
|
gtk_drop_down_set_factory (GTK_DROP_DOWN (dropdown), factory);
|
|
|
|
g_object_unref (factory);
|
|
|
|
|
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (dropdown), col + 1);
|
|
|
|
attribute_mapping_changed (GTK_DROP_DOWN (dropdown), NULL, self);
|
|
|
|
g_signal_connect (dropdown, "notify::selected",
|
2019-11-09 00:13:28 +00:00
|
|
|
G_CALLBACK (attribute_mapping_changed), self);
|
2019-12-14 03:12:15 +00:00
|
|
|
|
|
|
|
gtk_box_append (GTK_BOX (box), dropdown);
|
2014-05-31 01:35:39 +00:00
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
return box;
|
2014-05-31 01:35:39 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 02:56:12 +00:00
|
|
|
static GObject *
|
|
|
|
find_action_owner (GtkActionable *actionable)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (actionable);
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *full_name;
|
2014-05-31 02:56:12 +00:00
|
|
|
GtkWidget *win;
|
|
|
|
|
|
|
|
full_name = gtk_actionable_get_action_name (actionable);
|
2014-06-06 01:08:56 +00:00
|
|
|
if (!full_name)
|
|
|
|
return NULL;
|
|
|
|
|
2014-05-31 02:56:12 +00:00
|
|
|
win = gtk_widget_get_ancestor (widget, GTK_TYPE_APPLICATION_WINDOW);
|
2019-06-15 22:05:54 +00:00
|
|
|
if (g_str_has_prefix (full_name, "win.") == 0)
|
2014-05-31 02:56:12 +00:00
|
|
|
{
|
|
|
|
if (G_IS_OBJECT (win))
|
2014-07-30 21:46:13 +00:00
|
|
|
return (GObject *)win;
|
2014-05-31 02:56:12 +00:00
|
|
|
}
|
2019-06-15 22:05:54 +00:00
|
|
|
else if (g_str_has_prefix (full_name, "app.") == 0)
|
|
|
|
{
|
2014-05-31 02:56:12 +00:00
|
|
|
if (GTK_IS_WINDOW (win))
|
|
|
|
return (GObject *)gtk_window_get_application (GTK_WINDOW (win));
|
|
|
|
}
|
2014-07-30 21:46:13 +00:00
|
|
|
|
|
|
|
while (widget != NULL)
|
2014-05-31 02:56:12 +00:00
|
|
|
{
|
2019-06-15 22:05:54 +00:00
|
|
|
GtkActionMuxer *muxer;
|
|
|
|
|
|
|
|
muxer = _gtk_widget_get_action_muxer (widget, FALSE);
|
|
|
|
if (muxer && gtk_action_muxer_find (muxer, full_name, NULL))
|
2014-07-30 21:46:13 +00:00
|
|
|
return (GObject *)widget;
|
2019-06-15 22:05:54 +00:00
|
|
|
|
2019-12-27 13:48:03 +00:00
|
|
|
widget = gtk_widget_get_parent (widget);
|
2014-05-31 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
2019-06-15 22:05:54 +00:00
|
|
|
return NULL;
|
2014-05-31 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_action_owner (GtkButton *button,
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self)
|
2014-05-31 02:56:12 +00:00
|
|
|
{
|
|
|
|
GObject *owner;
|
|
|
|
|
|
|
|
owner = g_object_get_data (G_OBJECT (button), "owner");
|
2019-11-09 00:13:28 +00:00
|
|
|
g_signal_emit (self, signals[SHOW_OBJECT], 0, owner, NULL, "actions");
|
2014-05-31 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
action_editor (GObject *object,
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self)
|
2014-05-31 02:56:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *button;
|
|
|
|
GObject *owner;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
2014-05-31 02:56:12 +00:00
|
|
|
|
|
|
|
owner = find_action_owner (GTK_ACTIONABLE (object));
|
|
|
|
|
2019-04-12 17:01:19 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
2014-05-31 02:56:12 +00:00
|
|
|
if (owner)
|
|
|
|
{
|
2020-08-30 17:11:39 +00:00
|
|
|
/* Translators: %s is a type name, for example
|
|
|
|
* Action from 0x2345678 (GtkApplicationWindow)
|
|
|
|
*/
|
2019-04-12 17:01:19 +00:00
|
|
|
text = g_strdup_printf (_("Action from: %p (%s)"),
|
2014-05-31 02:56:12 +00:00
|
|
|
owner, g_type_name_from_instance ((GTypeInstance *)owner));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), gtk_label_new (text));
|
2014-05-31 02:56:12 +00:00
|
|
|
g_free (text);
|
|
|
|
button = gtk_button_new_with_label (_("Properties"));
|
|
|
|
g_object_set_data (G_OBJECT (button), "owner", owner);
|
|
|
|
g_signal_connect (button, "clicked",
|
2019-11-09 00:13:28 +00:00
|
|
|
G_CALLBACK (show_action_owner), self);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2014-05-31 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 17:01:19 +00:00
|
|
|
return box;
|
2014-07-11 03:57:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 02:01:38 +00:00
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
add_attribute_info (GtkInspectorPropEditor *self,
|
2016-03-10 02:01:38 +00:00
|
|
|
GParamSpec *spec)
|
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
if (GTK_IS_CELL_RENDERER (self->object))
|
|
|
|
gtk_box_append (GTK_BOX (self),
|
|
|
|
attribute_editor (self->object, spec, self));
|
2016-03-10 02:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
add_actionable_info (GtkInspectorPropEditor *self)
|
2016-03-10 02:01:38 +00:00
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
if (GTK_IS_ACTIONABLE (self->object) &&
|
|
|
|
g_strcmp0 (self->name, "action-name") == 0)
|
|
|
|
gtk_box_append (GTK_BOX (self),
|
|
|
|
action_editor (self->object, self));
|
2016-03-10 02:01:38 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 23:14:37 +00:00
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
reset_setting (GtkInspectorPropEditor *self)
|
2015-09-17 23:14:37 +00:00
|
|
|
{
|
2020-08-05 15:10:22 +00:00
|
|
|
gtk_settings_reset_property (GTK_SETTINGS (self->object), self->name);
|
2015-09-17 23:14:37 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 12:44:21 +00:00
|
|
|
static void
|
2019-11-09 00:13:28 +00:00
|
|
|
add_gtk_settings_info (GtkInspectorPropEditor *self)
|
2014-09-19 12:44:21 +00:00
|
|
|
{
|
|
|
|
GObject *object;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name;
|
2014-09-19 12:44:21 +00:00
|
|
|
GtkWidget *row;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *source;
|
2015-09-17 23:14:37 +00:00
|
|
|
GtkWidget *button;
|
2014-09-19 12:44:21 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
object = self->object;
|
|
|
|
name = self->name;
|
2014-09-19 12:44:21 +00:00
|
|
|
|
|
|
|
if (!GTK_IS_SETTINGS (object))
|
|
|
|
return;
|
|
|
|
|
|
|
|
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
|
2015-09-17 23:14:37 +00:00
|
|
|
button = gtk_button_new_with_label (_("Reset"));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (row), button);
|
2019-04-12 18:34:11 +00:00
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
2019-11-09 00:13:28 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked", G_CALLBACK (reset_setting), self);
|
2015-09-17 23:14:37 +00:00
|
|
|
|
2014-09-19 12:44:21 +00:00
|
|
|
switch (_gtk_settings_get_setting_source (GTK_SETTINGS (object), name))
|
|
|
|
{
|
|
|
|
case GTK_SETTINGS_SOURCE_DEFAULT:
|
2020-08-30 17:11:39 +00:00
|
|
|
source = C_("GtkSettings source", "Default");
|
2014-09-19 12:44:21 +00:00
|
|
|
break;
|
|
|
|
case GTK_SETTINGS_SOURCE_THEME:
|
2020-08-30 17:11:39 +00:00
|
|
|
source = C_("GtkSettings source", "Theme");
|
2014-09-19 12:44:21 +00:00
|
|
|
break;
|
|
|
|
case GTK_SETTINGS_SOURCE_XSETTING:
|
2020-08-30 17:11:39 +00:00
|
|
|
source = C_("GtkSettings source", "XSettings");
|
2014-09-19 12:44:21 +00:00
|
|
|
break;
|
|
|
|
case GTK_SETTINGS_SOURCE_APPLICATION:
|
2015-09-17 23:14:37 +00:00
|
|
|
gtk_widget_set_sensitive (button, TRUE);
|
2020-08-30 17:11:39 +00:00
|
|
|
source = C_("GtkSettings source", "Application");
|
2014-09-19 12:44:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-08-30 17:11:39 +00:00
|
|
|
source = C_("GtkSettings source", "Unknown");
|
2014-09-19 12:44:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (row), gtk_label_new (_("Source:")));
|
|
|
|
gtk_box_append (GTK_BOX (row), gtk_label_new (source));
|
2014-09-19 12:44:21 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
gtk_box_append (GTK_BOX (self), row);
|
2014-09-19 12:44:21 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 04:57:54 +00:00
|
|
|
static void
|
|
|
|
readonly_changed (GObject *object,
|
|
|
|
GParamSpec *spec,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GValue gvalue = {0};
|
2020-07-24 18:40:36 +00:00
|
|
|
char *value;
|
|
|
|
char *type;
|
2019-05-01 04:57:54 +00:00
|
|
|
|
|
|
|
g_value_init (&gvalue, spec->value_type);
|
|
|
|
g_object_get_property (object, spec->name, &gvalue);
|
|
|
|
strdup_value_contents (&gvalue, &value, &type);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (data), value);
|
|
|
|
|
2019-12-25 00:40:50 +00:00
|
|
|
g_value_unset (&gvalue);
|
2019-05-01 04:57:54 +00:00
|
|
|
g_free (value);
|
|
|
|
g_free (type);
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self = GTK_INSPECTOR_PROP_EDITOR (object);
|
2014-05-18 05:03:24 +00:00
|
|
|
GParamSpec *spec;
|
|
|
|
GtkWidget *label;
|
|
|
|
gboolean can_modify;
|
2019-04-12 18:34:11 +00:00
|
|
|
GtkWidget *box;
|
2014-05-18 05:03:24 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
spec = find_property (self);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
2014-05-25 03:30:01 +00:00
|
|
|
can_modify = ((spec->flags & G_PARAM_WRITABLE) != 0 &&
|
|
|
|
(spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
|
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
|
2016-03-10 02:42:08 +00:00
|
|
|
if ((spec->flags & G_PARAM_CONSTRUCT_ONLY) != 0)
|
|
|
|
label = gtk_label_new ("(construct-only)");
|
|
|
|
else if ((spec->flags & G_PARAM_WRITABLE) == 0)
|
|
|
|
label = gtk_label_new ("(not writable)");
|
|
|
|
else
|
|
|
|
label = NULL;
|
|
|
|
|
|
|
|
if (label)
|
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (label, "dim-label");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), label);
|
2016-03-10 02:42:08 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 02:01:38 +00:00
|
|
|
/* By reaching this, we already know the property is readable.
|
|
|
|
* Since all we can do for a GObject is dive down into it's properties
|
|
|
|
* and inspect bindings and such, pretend to be mutable.
|
2015-05-05 19:19:10 +00:00
|
|
|
*/
|
|
|
|
if (g_type_is_a (spec->value_type, G_TYPE_OBJECT))
|
|
|
|
can_modify = TRUE;
|
|
|
|
|
2014-05-25 03:30:01 +00:00
|
|
|
if (!can_modify)
|
2019-04-12 19:07:01 +00:00
|
|
|
{
|
2019-05-01 04:57:54 +00:00
|
|
|
label = gtk_label_new ("");
|
2020-11-17 18:33:59 +00:00
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
|
|
|
gtk_label_set_max_width_chars (GTK_LABEL (label), 20);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_FILL);
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (label, "dim-label");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), label);
|
2019-04-12 19:07:01 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
readonly_changed (self->object, spec, label);
|
|
|
|
g_object_connect_property (self->object, spec,
|
2019-05-01 04:57:54 +00:00
|
|
|
G_CALLBACK (readonly_changed),
|
|
|
|
label, G_OBJECT (label));
|
2019-04-12 19:07:01 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
if (self->size_group)
|
|
|
|
gtk_size_group_add_widget (self->size_group, box);
|
|
|
|
gtk_box_append (GTK_BOX (self), box);
|
2019-04-12 19:07:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-05-25 03:30:01 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
self->self = property_editor (self->object, spec, self);
|
|
|
|
gtk_box_append (GTK_BOX (box), self->self);
|
|
|
|
if (self->size_group)
|
|
|
|
gtk_size_group_add_widget (self->size_group, box);
|
|
|
|
gtk_box_append (GTK_BOX (self), box);
|
2014-05-25 03:30:01 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
add_attribute_info (self, spec);
|
|
|
|
add_actionable_info (self);
|
|
|
|
add_gtk_settings_info (self);
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 09:49:34 +00:00
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self = GTK_INSPECTOR_PROP_EDITOR (object);
|
2014-06-05 09:49:34 +00:00
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
g_free (self->name);
|
2014-06-05 09:49:34 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_prop_editor_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self = GTK_INSPECTOR_PROP_EDITOR (object);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
|
|
|
case PROP_OBJECT:
|
2019-11-09 00:13:28 +00:00
|
|
|
g_value_set_object (value, self->object);
|
2014-05-18 05:03:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_NAME:
|
2019-11-09 00:13:28 +00:00
|
|
|
g_value_set_string (value, self->name);
|
2014-05-18 05:03:24 +00:00
|
|
|
break;
|
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
case PROP_SIZE_GROUP:
|
2019-11-09 00:13:28 +00:00
|
|
|
g_value_set_object (value, self->size_group);
|
2019-04-12 18:34:11 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
GtkInspectorPropEditor *self = GTK_INSPECTOR_PROP_EDITOR (object);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
|
|
|
case PROP_OBJECT:
|
2019-11-09 00:13:28 +00:00
|
|
|
self->object = g_value_get_object (value);
|
2014-05-18 05:03:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_NAME:
|
2019-11-09 00:13:28 +00:00
|
|
|
g_free (self->name);
|
|
|
|
self->name = g_value_dup_string (value);
|
2014-05-18 05:03:24 +00:00
|
|
|
break;
|
|
|
|
|
2019-04-12 18:34:11 +00:00
|
|
|
case PROP_SIZE_GROUP:
|
2019-11-09 00:13:28 +00:00
|
|
|
self->size_group = g_value_get_object (value);
|
2019-04-12 18:34:11 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
|
|
|
|
break;
|
2021-11-30 23:38:33 +00:00
|
|
|
}
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_prop_editor_class_init (GtkInspectorPropEditorClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2020-07-18 15:53:16 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
object_class->constructed = constructed;
|
2014-06-05 09:49:34 +00:00
|
|
|
object_class->finalize = finalize;
|
2014-05-18 05:03:24 +00:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
2020-07-18 15:53:16 +00:00
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
|
|
|
|
2014-05-18 05:03:24 +00:00
|
|
|
signals[SHOW_OBJECT] =
|
|
|
|
g_signal_new ("show-object",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2019-11-09 00:13:28 +00:00
|
|
|
0,
|
2014-05-18 05:03:24 +00:00
|
|
|
NULL, NULL, NULL,
|
2014-05-31 03:21:13 +00:00
|
|
|
G_TYPE_NONE, 3, G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_STRING);
|
2014-05-18 05:03:24 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_OBJECT,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("object", NULL, NULL,
|
2014-05-18 05:03:24 +00:00
|
|
|
G_TYPE_OBJECT, G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_NAME,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_string ("name", NULL, NULL,
|
2014-05-18 05:03:24 +00:00
|
|
|
NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
|
2019-04-12 18:34:11 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_SIZE_GROUP,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("size-group", NULL, NULL,
|
2019-04-12 18:34:11 +00:00
|
|
|
GTK_TYPE_SIZE_GROUP, G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
|
2014-05-18 05:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2019-04-12 18:34:11 +00:00
|
|
|
gtk_inspector_prop_editor_new (GObject *object,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
2019-04-12 18:34:11 +00:00
|
|
|
GtkSizeGroup *values)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_INSPECTOR_PROP_EDITOR,
|
|
|
|
"object", object,
|
|
|
|
"name", name,
|
2019-04-12 18:34:11 +00:00
|
|
|
"size-group", values,
|
2014-05-18 05:03:24 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2019-11-09 00:13:28 +00:00
|
|
|
gtk_inspector_prop_editor_should_expand (GtkInspectorPropEditor *self)
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
2019-11-09 00:13:28 +00:00
|
|
|
if (GTK_IS_SCROLLED_WINDOW (self->self))
|
2014-05-18 05:03:24 +00:00
|
|
|
{
|
|
|
|
GtkPolicyType policy;
|
|
|
|
|
2019-11-09 00:13:28 +00:00
|
|
|
g_object_get (self->self, "vscrollbar-policy", &policy, NULL);
|
2014-05-18 05:03:24 +00:00
|
|
|
if (policy != GTK_POLICY_NEVER)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// vim: set et:
|