Compare commits

...

1 Commits

Author SHA1 Message Date
Jamie Murphy
a9a91d4e7e entry: Update text-length as length changes
Initially, there was nothing connecting the actual text-length from the
EntryBuffer to the exposed `GtkEntry:text-length` property. It would
only be updated when the property is used. This adds a handler for
`notify::length` on the buffer to make sure the `text-length` property
updates accordingly.
2024-04-03 23:39:31 -07:00

View File

@@ -170,6 +170,7 @@ struct _GtkEntryPrivate
GtkWidget *text;
GtkWidget *progress_widget;
GSignalGroup *buffer_signals;
guint show_emoji_icon : 1;
guint editing_canceled : 1; /* Only used by GtkCellRendererText */
@@ -1350,6 +1351,12 @@ notify_cb (GObject *object,
g_object_notify (data, pspec->name);
}
static void
length_changed_cb (GtkEntry *entry)
{
g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_TEXT_LENGTH]);
}
static void
connect_text_signals (GtkEntry *entry)
{
@@ -1357,6 +1364,9 @@ connect_text_signals (GtkEntry *entry)
g_signal_connect (priv->text, "activate", G_CALLBACK (activate_cb), entry);
g_signal_connect (priv->text, "notify", G_CALLBACK (notify_cb), entry);
g_signal_group_connect_swapped (priv->buffer_signals, "notify::length",
G_CALLBACK (length_changed_cb), entry);
}
static void
@@ -1385,10 +1395,15 @@ gtk_entry_init (GtkEntry *entry)
GtkGesture *catchall;
priv->text = gtk_text_new ();
priv->buffer_signals = g_signal_group_new (GTK_TYPE_ENTRY_BUFFER);
gtk_widget_set_parent (priv->text, GTK_WIDGET (entry));
gtk_editable_init_delegate (GTK_EDITABLE (entry));
connect_text_signals (entry);
g_object_bind_property (priv->text, "buffer",
priv->buffer_signals, "target",
G_BINDING_SYNC_CREATE);
catchall = gtk_gesture_click_new ();
g_signal_connect (catchall, "pressed",
G_CALLBACK (catchall_click_press), entry);
@@ -1423,6 +1438,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
gtk_editable_finish_delegate (GTK_EDITABLE (entry));
}
g_clear_pointer (&priv->text, gtk_widget_unparent);
g_clear_object (&priv->buffer_signals);
G_OBJECT_CLASS (gtk_entry_parent_class)->dispose (object);
}