Textview buffer insert warning

590 views Asked by At

This is probably a noobish question to ask, but hopefully someone has an answer. I'm just trying to append text to the end of a textview ('log' in this case), and the following code DOES work;

log.Buffer.Insert (log.Buffer.EndIter, "\n TCPserver>>Simple Constructor");

but I'm getting a warning I would LOVE To get rid of, because I'm doing this in a lot of different places;

 Warning CS0618: 'Gtk.TextBuffer.Insert(Gtk.TextIter, string)' is obsolete: 'Replaced by 'ref TextIter iter' overload' (CS0618) (bubbles)
1

There are 1 answers

0
Skyler Brandt On BEST ANSWER

All you have to do is create a local variable to the TextIter and then pass the Insert function a reference to that. Here's a snippet of code that should work, I do something very similar in one of my projects:

var tb = log.Buffer;
var ti = tb.GetIterAtLine (tb.LineCount);
tb.Insert (ref ti, "TCPserver>>Simple Constructor\n");

I also tried this code with the newline at the beginning of the string, but that didn't work for me.

Edit:

var ti = log.Buffer.EndIter;
log.Buffer.Insert (ref ti, "\n TCPserver>>Simple Constructor");

Is a bit cleaner and placing the newline at the beginning of the string also works.