[Gtk-sharp-list] Patch for TextBuffer

Thiago Milczarek Sayćo sayao@brturbo.com
Sat, 21 Feb 2004 17:03:17 -0300

Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On Sat, 2004-02-21 at 15:45, Mike Kestner wrote:
> On Sat, 2004-02-21 at 11:56, Thiago Milczarek SayĆ£o wrote:
> > I did a patch some days ago that got commited. It was the InsertWithTags
> > patch. I didn't notice that the Insert function take 2 arguments, the
> > iter and the text, so i did the InsertWithTags function take just two
> > argument that is the text and the tags (i forgot the iter).
> Are you saying you submitted a patch that you didn't test?  Please don't
> ever do that.  If a patch lands on this list, I'm assuming that it is
> addressing a demonstrated problem, and that when the patch is applied,
> the problem no longer exists.
I did test it. All patches i have sent work fine. I just did the
stupidity of making the wrong argument list to the function. It
addresses the problem of not having a gtk_text_buffer_insert_with_tags
() equivalent function.

> > This patch corrects the InsertWithTags to take three arguments, the
> > iter, the text and the tags.
> Has it been tested?

It was tested. The test i did is attached (run it inside the samples
dir). I've also tested on the gsirc (irc client).

> > The second patch add alias to the functions Insert, InsertWithTags and
> > InsertPixbuf to automatically take EndIter as the iter argument. I don't
> > know if its a good idea, so i did a separated patch to let mkestner
> > decide :)
> Ditto.


Content-Disposition: attachment; filename=TestBuffer.cs
Content-Type: text/x-csharp; name=TestBuffer.cs; charset=UTF-8
Content-Transfer-Encoding: 7bit

using System;
using Gtk;
using Gdk;

class TestBuffer
	TextView tv;
	static void Main ()
		new TestBuffer ();
	TestBuffer ()
		Application.Init ();
		Gtk.Window win = new Gtk.Window ("TextView Test");
		win.SetDefaultSize (400, 300);
		win.DeleteEvent += new DeleteEventHandler (OnWinDelete);
		VBox vbox = new VBox (false, 0);
		win.Add (vbox);

		TextTagTable tt = new TextTagTable ();

		TextTag t1 = new TextTag (null);
		t1.Foreground = "light blue";

		TextTag t2 = new TextTag (null);
		t2.Foreground = "red";

		TextTag t3 = new TextTag (null);
		t3.Foreground = "green";

		TextTag t4 = new TextTag (null);
		t4.Background = "yellow";

		tt.Add (t1);
		tt.Add (t2);
		tt.Add (t3);
		tt.Add (t4);

		TextBuffer buf = new TextBuffer (tt);
		tv = new TextView ();
		tv.Buffer = buf;

		Gdk.Pixbuf pix = new Gdk.Pixbuf ("pixmaps/gtk-sharp-logo.png");
		buf.InsertPixbuf (pix);
		buf.Insert ("Text");
		buf.InsertWithTags ("RED", t2);
		buf.InsertWithTags ("RED FG YELLOW BG", t2, t4);
		buf.InsertWithTags (buf.GetIterAtOffset (5), "Green", t3);
		buf.InsertWithTags (buf.GetIterAtOffset (20), "Green", t3);
		Gdk.Pixbuf pix2 = new Gdk.Pixbuf ("pixmaps/gtk-sharp-logo.png");
		buf.InsertPixbuf (pix2);

		int offset = buf.EndIter.Offset;

		buf.Insert ("Text");
		buf.InsertWithTags ("RED", t2);
		buf.InsertWithTags ("RED FG YELLOW BG", t2, t4);
		buf.InsertWithTags (buf.GetIterAtOffset (offset + 4), "Green", t3);
		buf.InsertWithTags (buf.GetIterAtOffset (offset + 19), "Green", t3);

		buf.Insert ("\n");
		buf.Insert ("This text is at another line");
		buf.InsertWithTags ("\nThis text is red", t2);
		buf.InsertWithTags ("\nThis text is green", t3);

		vbox.PackStart (tv, true, true, 0);
		win.ShowAll ();
		Application.Run ();
	void OnWinDelete (object o, DeleteEventArgs args)
		Application.Quit ();