Re: 4 TextBuffer questions



Thanks for your answer Marco.


I am using a TextView/TextBuffer to display text with color.
How can I copy a substring of my TextBuffer into another TextBuffer, keeping the original colors ? The result of the get_text method does not seem to contain informations about the tags.


iterator Gtk::TextBuffer::insert ( const iterator& pos, const iterator& range_begin, const iterator& range_end ) Copies text, tags, and pixbufs between range_start and range_end and inserts the copy at pos. If range_start and range_end are in a different buffer from pos then the two buffers must share the same tag table.


Perfect. I will try this ASAP. What do you mean by "share the same tag table" ? If destination and source buffers have tags with the same name, but in different tag tables, is it enough (I guess not) ?

Another question: How can I add an antry to the default context menu of the TextView (cut/paste/...). I need to add specific actions when the user right-clicks in the TextView.

Overide virtual void Gtk::TextView::on_populate_popup  (Menu*  menu)
but that's just a guess, never tried that myself.


Seems a good idea. I should have found it myself in the doc...

Third : how can I add a bar on the left side of a TextView, to display additionnal informations (like bookmarks) ?


place any widget next to the textview that you find suitable to display that info. (maybe a treeview).


I expected that it was built in the TextView widget. If I have to manage it myself, as you suggest, this could be a pain. I need to update the bar each time the TextBuffer is modified.
Is it an easier way ?

Last (but not least) : How can I highlight the current line ? I could apply a tag with the background color set to yellow, but only the characters would be highlighted. The background behind the text would remain white, which would not look very nice.


As i understand you want to highlight the line over the full width of the textview even if the text on that line is not the full width?, i'm not sure if that is possible, maybe you should use the treeview widget instead.


You're right. Is the TreeView as fast as the TextView ? My app displays scrolling text (traces), and it can be pretty verbose...

Thanks a lot. It really helped.
Ben






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]