4
using System.Runtime.InteropServices;
10
public class InsertBugAction : SplitterAction
16
public InsertBugAction (Gtk.TextIter start,
18
Gtk.TextBuffer buffer,
24
Offset = start.Offset;
27
public override void Undo (Gtk.TextBuffer buffer)
29
// Tag images change the offset by one, but only when deleting.
30
Gtk.TextIter start_iter = buffer.GetIterAtOffset (Offset);
31
Gtk.TextIter end_iter = buffer.GetIterAtOffset (Offset + chop.Length + 1);
32
buffer.Delete (ref start_iter, ref end_iter);
33
buffer.MoveMark (buffer.InsertMark, buffer.GetIterAtOffset (Offset));
34
buffer.MoveMark (buffer.SelectionBound, buffer.GetIterAtOffset (Offset));
36
Tag.ImageLocation = null;
38
ApplySplitTags (buffer);
41
public override void Redo (Gtk.TextBuffer buffer)
43
RemoveSplitTags (buffer);
45
Gtk.TextIter cursor = buffer.GetIterAtOffset (Offset);
47
Gtk.TextTag[] tags = {Tag};
48
buffer.InsertWithTags (ref cursor, Id, tags);
50
buffer.MoveMark (buffer.SelectionBound, buffer.GetIterAtOffset (Offset));
51
buffer.MoveMark (buffer.InsertMark,
52
buffer.GetIterAtOffset (Offset + chop.Length));
56
public override void Merge (EditAction action)
58
SplitterAction splitter = action as SplitterAction;
59
this.splitTags = splitter.SplitTags;
60
this.chop = splitter.Chop;
64
* The internal listeners will create an InsertAction when the text
65
* is inserted. Since it's ugly to have the bug insertion appear
66
* to the user as two items in the undo stack, have this item eat
69
public override bool CanMerge (EditAction action)
71
InsertAction insert = action as InsertAction;
76
if (String.Compare(Id, insert.Chop.Text) == 0) {
83
public override void Destroy ()
88
public class BugzillaLink : DynamicNoteTag
92
public BugzillaLink ()
97
public override void Initialize (string element_name)
99
base.Initialize (element_name);
101
Underline = Pango.Underline.Single;
105
CanSpellCheck = false;
111
get { return (string) Attributes ["uri"]; }
112
set { Attributes ["uri"] = value; }
115
protected override bool OnActivate (NoteEditor editor, Gtk.TextIter start, Gtk.TextIter end)
117
if (BugUrl != string.Empty) {
118
Logger.Log ("Opening url '{0}'...", BugUrl);
119
Gnome.Url.Show (BugUrl);
124
public override void Read (XmlTextReader xml, bool start)
126
base.Read (xml, start);
129
public override Gdk.Pixbuf Image
136
System.Uri uri = new System.Uri(BugUrl);
140
string host = uri.Host;
141
string imageDir = "~/.tomboy/BugzillaIcons/";
143
string imagePath = imageDir.Replace ("~", Environment.GetEnvironmentVariable ("HOME")) + host + ".png";
146
Icon = new Gdk.Pixbuf (imagePath);
147
} catch (GLib.GException) {
148
Icon = new Gdk.Pixbuf(null, "stock_bug.png");
156
public class BugzillaPlugin : NotePlugin
160
static BugzillaPlugin ()
165
protected override void Initialize ()
167
if (!Note.TagTable.IsDynamicTagRegistered ("link:bugzilla")) {
168
Note.TagTable.RegisterDynamicTag ("link:bugzilla", typeof (BugzillaLink));
172
protected override void Shutdown ()
176
protected override void OnNoteOpened ()
178
Window.Editor.DragDataReceived += OnDragDataReceived;
181
[DllImport("libgobject-2.0.so.0")]
182
static extern void g_signal_stop_emission_by_name (IntPtr raw, string name);
185
void OnDragDataReceived (object sender, Gtk.DragDataReceivedArgs args)
187
foreach (Gdk.Atom atom in args.Context.Targets) {
188
if (atom.Name == "text/uri-list" ||
189
atom.Name == "_NETSCAPE_URL") {
196
void DropUriList (Gtk.DragDataReceivedArgs args)
198
string uriString = Encoding.UTF8.GetString (args.SelectionData.Data);
200
if (uriString.IndexOf ("show_bug.cgi?id=") != -1) {
201
if (InsertBug (uriString)) {
202
Gtk.Drag.Finish (args.Context, true, false, args.Time);
203
g_signal_stop_emission_by_name(Window.Editor.Handle,
204
"drag_data_received");
209
bool InsertBug(string uri)
212
string bug = uri.Substring (uri.IndexOf ("show_bug.cgi?id=") + 16);
213
int id = int.Parse (bug);
214
// Debounce. I'm not sure why this is necessary :(
215
if (id == last_bug) {
221
BugzillaLink link_tag = (BugzillaLink)
222
Note.TagTable.CreateDynamicTag ("link:bugzilla");
223
link_tag.BugUrl = uri;
225
Gtk.TextIter cursor = Buffer.GetIterAtMark (Buffer.InsertMark);
227
Buffer.Undoer.AddUndoAction (new InsertBugAction (cursor, bug, Buffer, link_tag));
229
Gtk.TextTag[] tags = {link_tag};
230
Buffer.InsertWithTags (ref cursor, bug, tags);