diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-03-21 16:02:39 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-03-21 16:05:10 -0400 |
commit | c5aa35f8efc8a02ad4f937da9ac8d9298d19f048 (patch) | |
tree | aab219a6e18395c493f3985f8833242d0e1e068b | |
parent | 7a56aa910ebc72cbd156fb779ef12f68b675db54 (diff) | |
download | gtk+-c5aa35f8efc8a02ad4f937da9ac8d9298d19f048.tar.gz |
inspector: Allow inspecting Unicode
Add a way to show text as a Unicode sequence.
This can be helpful in understanding what is
happening with text.
-rw-r--r-- | gtk/inspector/prop-editor.c | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/gtk/inspector/prop-editor.c b/gtk/inspector/prop-editor.c index 019d34ffbe..247cfc8c03 100644 --- a/gtk/inspector/prop-editor.c +++ b/gtk/inspector/prop-editor.c @@ -844,6 +844,43 @@ describe_expression (GtkExpression *expression) g_type_name (gtk_expression_get_value_type (expression))); } +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"); + } +} + static GtkWidget * property_editor (GObject *object, GParamSpec *spec, @@ -926,18 +963,38 @@ property_editor (GObject *object, } else if (type == G_TYPE_PARAM_STRING) { - prop_edit = gtk_entry_new (); + GtkWidget *entry; + GtkWidget *button; + GtkWidget *stack; + GtkWidget *unicode; + + entry = gtk_entry_new (); g_object_connect_property (object, spec, G_CALLBACK (string_changed), - prop_edit, G_OBJECT (prop_edit)); + entry, G_OBJECT (entry)); if (GTK_IS_CSS_NODE (object)) - connect_controller (G_OBJECT (prop_edit), "changed", + connect_controller (G_OBJECT (entry), "changed", object, spec, G_CALLBACK (intern_string_modified)); else - connect_controller (G_OBJECT (prop_edit), "changed", + connect_controller (G_OBJECT (entry), "changed", object, spec, G_CALLBACK (string_modified)); + + 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); } else if (type == G_TYPE_PARAM_BOOLEAN) { |