0

If this isn't the appropriate forum for this question, I apologize. Please remove it if that's the case. I know that Elementary OS developers use Vala for their development and I'm unaware of a more appropriate forum where such a question can be asked of them... So, in Vala/Gtk3, I need to gain access to the serialized contents of a Gtk.TextBuffer (linked to a Gtk.TextView widget) including all of the Gtk.TextTags which have been applied to the text. This is so that I can translate each of the formatted (bolded, italicized, etc.) parts of the text to Pango markup which can then be inserted into another Widget. Can someone provide insight into how this is done? As you can see from the following linked post, I've attempted this using the Gtk.TextBuffer's register_serialize_tagset() and serialize() methods but unfortunately, this only results in obtaining an XML header that contains just one line of text: "GTKTEXTBUFFERCONTENTS-0001". Is there some other means that Elementary OS Vala developers typically employ to gain access to a Gtk.TextBuffer's serialized text? How exactly does one go about saving the "rich text" contents of Gtk.TextView widget to a database (or even to an ordinary file) if this doesn't work?

[https://stackoverflow.com/questions/68580733/how-do-i-obtain-the-complete-serialized-text-from-a-gtk-textview-in-vala]

1
  • thank you, that was helpful! \ I needed to change data[31:]; to data[31:data.length]; though.
    – pthr
    Aug 16 at 19:38
0

I found the solution. It looks like in order to use the array returned by serialize, you have to treat it as though it begins at character 31. That gets you beyond the first line and into the sought-after data. Thus, the corrected version of my original code is this...

Gtk.TextIter start_iter;
Gtk.TextIter end_iter;
textview.buffer.get_start_iter(out start_iter);
textview.buffer.get_end_iter(out end_iter);
var format = textview.buffer.register_serialize_tagset("my-tagset");
var data = textview.buffer.serialize(textview.buffer, format, start_iter, end_iter);
var sub_arr = data[31:];
print((string) sub_arr + "\n");

And yes, I'm treating the XML header as being of constant width here. Though I suspect this is workable, time may prove otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.