]> git.ktnx.net Git - icedeb.git/commitdiff
clicking on the toolbar button now loads BTS bug page
authorDamyan Ivanov <dmn@debian.org>
Thu, 26 Feb 2009 12:35:26 +0000 (14:35 +0200)
committerDamyan Ivanov <dmn@debian.org>
Thu, 26 Feb 2009 12:35:26 +0000 (14:35 +0200)
chrome/button.js

index a9483994af6145b5147e947f5e02a32c5a557813..3dadd3e4aac6d355f5492e9461db0d546ee6a7ab 100644 (file)
@@ -1,8 +1,39 @@
-Debian = {
+function getClipboardText() {
+    var clip = Components.classes['@mozilla.org/widget/clipboard;1']
+        .getService(Components.interfaces.nsIClipboard);
+    if (!clip) return null;
+
+    var trans = Components.classes['@mozilla.org/widget/transferable;1']
+        .createInstance(Components.interfaces.nsITransferable);
+    if (!trans) return null;
+
+    trans.addDataFlavor("text/unicode");
+    clip.getData(trans,
+            clip.supportsSelectionClipboard()
+            ? clip.kSelectionClipboard
+            : clip.kGlobalClipboard
+    );
+
+    var str = new Object;
+    var strLength = new Object;
+    trans.getTransferData("text/unicode", str, strLength);
+
+    var text = null;
 
-btsButton: function (e) {
-         alert("Just testing")
-               },
+    if (str) str  = str.value.QueryInterface(Components.interfaces.nsISupportsString);
+    if (str) text = str.data.substring(0, strLength.value / 2);
 
+    return text;
+}
+
+function lookup_bts() {
+    var bug = getClipboardText();
+    loadURI("http://bugs.debian.org/" + bug);
+}
+
+Debian = {
+    btsButton: function (e) {
+        lookup_bts();
+    }
 }