3
using System.Runtime.InteropServices;
11
namespace Tomboy.Bugzilla
13
public class BugzillaNoteAddin : NoteAddin
17
static BugzillaNoteAddin ()
22
public override void Initialize ()
24
Logger.Debug ("Bugzilla.Initialize");
25
if (!Note.TagTable.IsDynamicTagRegistered ("link:bugzilla")) {
26
Note.TagTable.RegisterDynamicTag ("link:bugzilla", typeof (BugzillaLink));
30
public override void Shutdown ()
32
Logger.Debug ("Bugzilla.Shutdown");
35
public override void OnNoteOpened ()
37
Logger.Debug ("Bugzilla.OnNoteOpened");
38
Window.Editor.DragDataReceived += OnDragDataReceived;
41
[DllImport("libgobject-2.0.so.0")]
42
static extern void g_signal_stop_emission_by_name (IntPtr raw, string name);
45
void OnDragDataReceived (object sender, Gtk.DragDataReceivedArgs args)
47
Logger.Debug ("Bugzilla.OnDragDataReceived");
48
foreach (Gdk.Atom atom in args.Context.Targets) {
49
if (atom.Name == "text/uri-list" ||
50
atom.Name == "_NETSCAPE_URL") {
57
void DropUriList (Gtk.DragDataReceivedArgs args)
59
Logger.Debug ("Bugzilla.DropUriList");
60
if (args.SelectionData.Length > 0) {
61
string uriString = Encoding.UTF8.GetString (args.SelectionData.Data);
63
if (uriString.IndexOf ("show_bug.cgi?id=") != -1) {
64
if (InsertBug (args.X, args.Y, uriString)) {
65
Gtk.Drag.Finish (args.Context, true, false, args.Time);
66
g_signal_stop_emission_by_name(Window.Editor.Handle,
67
"drag_data_received");
73
bool InsertBug (int x, int y, string uri)
75
Logger.Debug ("Bugzilla.InsertBug");
77
string bug = uri.Substring (uri.IndexOf ("show_bug.cgi?id=") + 16);
78
int id = int.Parse (bug);
79
// Debounce. I'm not sure why this is necessary :(
86
BugzillaLink link_tag = (BugzillaLink)
87
Note.TagTable.CreateDynamicTag ("link:bugzilla");
88
link_tag.BugUrl = uri;
90
// Place the cursor in the position where the uri was
91
// dropped, adjusting x,y by the TextView's VisibleRect.
92
Gdk.Rectangle rect = Window.Editor.VisibleRect;
95
Gtk.TextIter cursor = Window.Editor.GetIterAtLocation (x, y);
96
Buffer.PlaceCursor (cursor);
98
Buffer.Undoer.AddUndoAction (new InsertBugAction (cursor, bug, Buffer, link_tag));
100
Gtk.TextTag[] tags = {link_tag};
101
Buffer.InsertWithTags (ref cursor, bug, tags);
102
Logger.Debug ("\tReturning true");
105
Logger.Debug ("\tReturning false");
b'\\ No newline at end of file'