GNOME Bugzilla – Bug 708584
GtkTextView: add a virtual function create_buffer()
Last modified: 2013-09-26 17:08:46 UTC
A patch will be attached soon. See bug #643732 for the bug in GtkSourceView.
Created attachment 255528 [details] [review] GtkTextView: add create_buffer virtual method pointer gtk_text_view_get_buffer() returns its priv->buffer. If priv->buffer is NULL, a GtkTextBuffer is created and returned. With a GtkSourceView (subclass of GtkTextView) and GtkSourceBuffer (subclass of GtkTextBuffer), the gtk_text_view_get_buffer() function is a problem. When we call gtk_text_view_get_buffer() when the priv->buffer is NULL, we want a GtkSourceBuffer, not a GtkTextBuffer. Why not make the get_buffer() function virtual, and override it in GtkSourceView? It would not be a clean solution, because when get_buffer() creates a new buffer, gtk_text_view_set_buffer() is called, which indirectly call get_buffer(), etc. So there is an infinite loop. And a hack is needed to avoid it. On the other hand, the create_buffer() virtual function always creates a buffer. It doesn't depend on priv->buffer.
Review of attachment 255528 [details] [review]: I don't like the commit message at all - it completely breaks scanning to see what was done because you are talking about things not in GTK+ and approaches you didn't take. (Too me, making get_buffer() virtual is obviously completely horribly the wrong thing, so discussing why you didn't do it is a waste of space :-) A commit mesage like This allows subclasses of GtkTextView that require a corresponding subclass of GtkTextBuffer to automatically do the right thing when constructed with a NULL buffer. An example of this is GtkSourceView which requires a GtkSourceBuffer. would be fine. ::: gtk/gtktextview.h @@ +107,3 @@ void (* toggle_overwrite) (GtkTextView *text_view); + GtkTextBuffer * (* create_buffer) (void); This definitely needs to take the text_view as the argument. A) it's conventional B) it is very useful C) you'll break language bindings if you have a virtual function without a self method.
Thank you for the review. Second patch iteration is coming soon.
Created attachment 255856 [details] [review] GtkTextView: add create_buffer virtual method pointer This allows subclasses of GtkTextView that require a corresponding subclass of GtkTextBuffer to automatically do the right thing when constructed with a NULL buffer. An example of this is GtkSourceView which requires a GtkSourceBuffer.
Review of attachment 255856 [details] [review]: Seems OK to me
Pushed.