I'm trying to load a .c file into a GtkSourceView widget.
Using C Language, with Gtk+ 2.22.1 and Glade 3.6.7 and GtkSourceView 2.10.1.
I noticed that in Glade UI I can only configure a SourceView to hold a TextBuffer; I did not find a SourceBuffer component. So, I created a SourceView in Glade without a default buffer. Now I want to set the SourceBuffer to be the buffer of my SourceView component.
gtk_source_view_new_with_buffer() is the only way I found to attach a SourceBuffer to a SourceView. The problem is that this function is creating a SourceView and I want to attach a SourceBuffer to an already created SourceView built with Glade. How can I do that?
I didn't paste any code because there is no code to show. I just created a Glade file with some UI component plus the SourceView-2 component with ID gtk_sourceview.
In the C file I fetch the SourceView component with
GtkSourceView *sourceview = GTK_WIDGET (gtk_builder_get_object (builder, "gtk_sourceview"));
What's missing is how to create a SourceBuffer and attach it to the SourceView component.
Thanks!
Update: I tried using:
GtkSourceBuffer *sourcebuffer = GTK_SOURCE_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(sourceview)));
But I got the following assert error:
(tour_de_gtk:13884): Gtk-CRITICAL **: IA__gtk_text_view_get_buffer: assertion `GTK_IS_TEXT_VIEW (text_view)' failed
What can I do to resolve this ?
Thanks!
The
GtkSourceViewalready has a buffer. Get it the same way you get a regular text buffer:This is because
GtkSourceViewis a subclass ofGtkTextView, so text view functions work on it too.EDIT:
Here is a program and glade file that works.
Program:
Glade file: