After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 708584 - GtkTextView: add a virtual function create_buffer()
GtkTextView: add a virtual function create_buffer()
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks: 643732
 
 
Reported: 2013-09-22 17:41 UTC by Sébastien Wilmet
Modified: 2013-09-26 17:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkTextView: add create_buffer virtual method pointer (3.23 KB, patch)
2013-09-22 17:42 UTC, Sébastien Wilmet
needs-work Details | Review
GtkTextView: add create_buffer virtual method pointer (2.73 KB, patch)
2013-09-26 16:46 UTC, Sébastien Wilmet
accepted-commit_now Details | Review

Description Sébastien Wilmet 2013-09-22 17:41:33 UTC
A patch will be attached soon. See bug #643732 for the bug in GtkSourceView.
Comment 1 Sébastien Wilmet 2013-09-22 17:42:11 UTC
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.
Comment 2 Owen Taylor 2013-09-26 16:26:58 UTC
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.
Comment 3 Sébastien Wilmet 2013-09-26 16:45:10 UTC
Thank you for the review. Second patch iteration is coming soon.
Comment 4 Sébastien Wilmet 2013-09-26 16:46:02 UTC
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.
Comment 5 Owen Taylor 2013-09-26 17:03:56 UTC
Review of attachment 255856 [details] [review]:

Seems OK to me
Comment 6 Sébastien Wilmet 2013-09-26 17:08:46 UTC
Pushed.