Mimicing the behavior of sourceview with textview

Hello all,

I tried to embed gtksourceview5 to gtkmm-4.0 with no luck. Thus I decided to move with an alternative solution such as to mimic the behavior of sourceview with a textview widget. How can I make textview to work as sourceview ?

I will only be using text input, read buffer and line numbering at the left side. Any suggestion or solution are welcomed.

Thanks in advance,

Hello, what exactly is the problem with gtksourceview?

To answer your question, if you really want to reproduce the behavior of gtksourceview, text input and read buffer work exactly the same way, but to get the line number you will have to add a widget to the gutter using gtk_text_view_set_gutter() and create some code that updates this widget with the corresponding line number.

1 Like

Actually there is no problem with the gtksourceview5, I am just having hard time integrating C and C++ so to speak gtkmm-4.0 and gtksourceview-5. I managed to setup gtkmm-4.0 and gtksourceviewmm-4.0 those two work within each other as expected but when I tried to switch between gtkmm-4.0 and gtksourceview-5 I have various problems which I think are hard to resolve.

I am going to look around the gutter and report back, thanks

1 Like
  m_TextView.set_gutter(Gtk::TextWindowType::LEFT, m_TextView );

What is wrong with this ?

The second argument of the Gtk.TextView.set_gutter() function must be another widget, not the Gtk.TextView itself. Probably the best choice is a Gtk.Label.

In fact, perhaps a look at the Gtk.SourceView code and how they implement the line counter would be interesting.

1 Like

For the following ;

  m_TextView.set_gutter(Gtk::TextWindowType::LEFT, m_Label);
  m_refTextBuffer1->signal_changed().connect(sigc::mem_fun(*this,          &ExampleWindow::on) );

on function is not being fired but the rest is operational. m_refTextBuffer1 is assigned to m_TextView. What do you think I might be missing ? Btw, I can see the label on the left middle side but can not iterate it due to change in textbuffer is not detected

I added a signal_changed() handler to the text buffers in gtkmm’s TextView demo
and in the TextView example in gtkmm-documentation. In both cases the signal handler
is called when the contents of the buffer is changed. I don’t see anything wrong
with the code snippet that you have shown. Something must be wrong somewhere
else in your program.

m_ScrolledWindow.set_child(m_Label); is unnecessary. ScrolledWindow can have
only one child (from the last call to set_child()). But that does not explain why
your signal handler is not called.