~ted/ubuntu/lucid/tomboy/with-patch

« back to all changes in this revision

Viewing changes to Tomboy/Addins/Bugzilla/BugzillaNoteAddin.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-07-16 10:26:35 UTC
  • mfrom: (1.1.21 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20070716102635-0wzk26jo50csob7b
Tags: 0.7.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Runtime.InteropServices;
 
4
using System.Text;
 
5
using System.Xml;
 
6
 
 
7
//using Mono.Unix;
 
8
 
 
9
using Tomboy;
 
10
 
 
11
namespace Tomboy.Bugzilla
 
12
{
 
13
        public class BugzillaNoteAddin : NoteAddin
 
14
        {
 
15
                static int last_bug;
 
16
 
 
17
                static BugzillaNoteAddin ()
 
18
                {
 
19
                        last_bug = -1;
 
20
                }
 
21
 
 
22
                public override void Initialize ()
 
23
                {
 
24
Logger.Debug ("Bugzilla.Initialize");
 
25
                        if (!Note.TagTable.IsDynamicTagRegistered ("link:bugzilla")) {
 
26
                                Note.TagTable.RegisterDynamicTag ("link:bugzilla", typeof (BugzillaLink));
 
27
                        }
 
28
                }
 
29
 
 
30
                public override void Shutdown ()
 
31
                {
 
32
Logger.Debug ("Bugzilla.Shutdown");
 
33
                }
 
34
 
 
35
                public override void OnNoteOpened ()
 
36
                {
 
37
Logger.Debug ("Bugzilla.OnNoteOpened");
 
38
                        Window.Editor.DragDataReceived += OnDragDataReceived;
 
39
                }
 
40
 
 
41
                [DllImport("libgobject-2.0.so.0")]
 
42
                static extern void g_signal_stop_emission_by_name (IntPtr raw, string name);
 
43
 
 
44
                [GLib.ConnectBefore]
 
45
                void OnDragDataReceived (object sender, Gtk.DragDataReceivedArgs args)
 
46
                {
 
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") {
 
51
                                        DropUriList (args);
 
52
                                        return;
 
53
                                }
 
54
                        }
 
55
                }
 
56
 
 
57
                void DropUriList (Gtk.DragDataReceivedArgs args)
 
58
                {
 
59
Logger.Debug ("Bugzilla.DropUriList");
 
60
                        if (args.SelectionData.Length > 0) {
 
61
                                string uriString = Encoding.UTF8.GetString (args.SelectionData.Data);
 
62
 
 
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");
 
68
                                        }
 
69
                                }
 
70
                        }
 
71
                }
 
72
 
 
73
                bool InsertBug (int x, int y, string uri)
 
74
                {
 
75
Logger.Debug ("Bugzilla.InsertBug");
 
76
                        try {
 
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 :(
 
80
                                if (id == last_bug) {
 
81
                                        last_bug = -1;
 
82
                                        return true;
 
83
                                }
 
84
                                last_bug = id;
 
85
 
 
86
                                BugzillaLink link_tag = (BugzillaLink)
 
87
                                        Note.TagTable.CreateDynamicTag ("link:bugzilla");
 
88
                                link_tag.BugUrl = uri;
 
89
 
 
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;
 
93
                                x = x + rect.X;
 
94
                                y = y + rect.Y;
 
95
                                Gtk.TextIter cursor = Window.Editor.GetIterAtLocation (x, y);
 
96
                                Buffer.PlaceCursor (cursor);
 
97
 
 
98
                                Buffer.Undoer.AddUndoAction (new InsertBugAction (cursor, bug, Buffer, link_tag));
 
99
 
 
100
                                Gtk.TextTag[] tags = {link_tag};
 
101
                                Buffer.InsertWithTags (ref cursor, bug, tags);
 
102
Logger.Debug ("\tReturning true");
 
103
                                return true;
 
104
                        } catch {
 
105
Logger.Debug ("\tReturning false");
 
106
                                return false;
 
107
                        }
 
108
                }
 
109
        }
 
110
}
 
 
b'\\ No newline at end of file'