GNOME Bugzilla – Bug 141157
Request: GtkTextBuffer maximum length api
Last modified: 2018-02-10 03:21:23 UTC
swt provides API Text.setTextLimit(int) which allows the user to set a limit on the number of characters that a Text can contain, beyond which it does not accept new characters. This is not currently implemented in the gtk multiple- line Text scenario because GtkTextBuffer does not provide something similar to gtk_entry_set_max_length(...) to do this for GtkTextViews.
It should be relatively simple to implement this by overriding the default behavior of the insert-text signal on GtkTextBuffer: http://developer.gnome.org/doc/API/2.0/gtk/GtkTextBuffer.html#GtkTextBuffer-insert-text In an application, you could connect to the insert-text signal "before" (run before the default handler, using g_signal_connect not connect_after) then call g_signal_stop_emission_by_name() to keep the default handler from running if the buffer is already too large http://developer.gnome.org/doc/API/2.0/gobject/gobject-Signals.html#g-signal-stop-emission-by-name a set_max_length might be a nice API addition anyway but in the meantime you could do something like this as a workaround.
Assigning to self as I'm trying to implement this API
Created attachment 200479 [details] [review] "max-length" property for GtkTextBuffer I have been working on implementing "max-length" property for GtkTextBuffer. Attached is a proposed patch which implements "max-length" similar to GtkEntryBuffer. Request review.
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue for it.