Use trac icon for trac bugs to diff from bugzilla
[tomboy-trac.git] / src / InsertBugAction.cs
blob5942e1896749ae35af178c55f44bf4e02e03fb47
1 using System;
3 namespace Tomboy.Trac
5 public class InsertBugAction : SplitterAction
7 TracLink Tag;
8 int Offset;
9 string Id;
11 public InsertBugAction (Gtk.TextIter start,
12 string id,
13 Gtk.TextBuffer buffer,
14 TracLink tag)
16 Tag = tag;
17 Id = id;
19 Offset = start.Offset;
22 public override void Undo (Gtk.TextBuffer buffer)
24 // Tag images change the offset by one, but only when deleting.
25 Gtk.TextIter start_iter = buffer.GetIterAtOffset (Offset);
26 Gtk.TextIter end_iter = buffer.GetIterAtOffset (Offset + chop.Length + 1);
27 buffer.Delete (ref start_iter, ref end_iter);
28 buffer.MoveMark (buffer.InsertMark, buffer.GetIterAtOffset (Offset));
29 buffer.MoveMark (buffer.SelectionBound, buffer.GetIterAtOffset (Offset));
31 Tag.WidgetLocation = null;
33 ApplySplitTags (buffer);
36 public override void Redo (Gtk.TextBuffer buffer)
38 RemoveSplitTags (buffer);
40 Gtk.TextIter cursor = buffer.GetIterAtOffset (Offset);
42 Gtk.TextTag[] tags = {Tag};
43 buffer.InsertWithTags (ref cursor, Id, tags);
45 buffer.MoveMark (buffer.SelectionBound, buffer.GetIterAtOffset (Offset));
46 buffer.MoveMark (buffer.InsertMark,
47 buffer.GetIterAtOffset (Offset + chop.Length));
51 public override void Merge (EditAction action)
53 SplitterAction splitter = action as SplitterAction;
54 this.splitTags = splitter.SplitTags;
55 this.chop = splitter.Chop;
59 * The internal listeners will create an InsertAction when the text
60 * is inserted. Since it's ugly to have the bug insertion appear
61 * to the user as two items in the undo stack, have this item eat
62 * the other one.
64 public override bool CanMerge (EditAction action)
66 InsertAction insert = action as InsertAction;
67 if (insert == null) {
68 return false;
71 if (String.Compare(Id, insert.Chop.Text) == 0) {
72 return true;
75 return false;
78 public override void Destroy ()