From c889af0aae7a564662727e67823f8bcca6359199 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 28 Jun 2010 20:22:47 -0400 Subject: Re-enable the context menu; work-around and initial patch by Drew Willcoxon --- lib/main.js | 73 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3a2bda6..1fb0c95 100644 --- a/lib/main.js +++ b/lib/main.js @@ -43,6 +43,35 @@ exports.main = function(options, callback) { } } ); + + // Allow toggling of CC event displays using a context menu entry + var contextMenu = require("context-menu"); + var ccMenuItem = contextMenu.Item({ + label: "Toggle CC History", + context: function(context) onBugzillaPage(context.window), + onClick: function(context) { + var style = context.document.getElementById("bztw_cc"); + style.disabled = !style.disabled; + } + }); + contextMenu.add(ccMenuItem); + + var copyCheckinCommentItem = contextMenu.Item({ + label: "Copy Check-in Comment", + context: function(context) { + if (!onBugzillaPage(context.window)) + return false; + var d = context.document; + var message = d.getElementById("__bz_tw_checkin_comment"); + return !!message; + }, + onClick: function(context) { + var d = context.document; + var message = d.getElementById("__bz_tw_checkin_comment"); + require("clipboard").set(message.textContent); + } + }); + contextMenu.add(copyCheckinCommentItem); }; function onBugzillaPage(window) { @@ -111,21 +140,6 @@ function tweakBugzilla(d) { )); d.getElementsByTagName("head")[0].appendChild(style); - /* - // Allow toggling of CC event displays using a context menu entry - var contextMenu = require("context-menu"); - var style = d.getElementById("bztw_cc"); - var ccMenuItem = contextMenu.Item({ - label: "Toggle CC History", - context: onBugzillaPage, - onClick: function() style.disabled = !style.disabled - }); - contextMenu.add(ccMenuItem); - d.defaultView.addEventListener("unload", function() { - contextMenu.remove(ccMenuItem); - }, false); - */ - var userNameCache = {}; function getUserName(email) { if (email in userNameCache) { @@ -196,23 +210,6 @@ function tweakBugzilla(d) { var CheckinComment = new CheckinCommentCtor(); CheckinComment.initialize(d, AttachmentFlagHandler._interestingFlags); - if (CheckinComment.isValid()) { - var message = d.getElementById("__bz_tw_checkin_comment"); - if (message) { - message = message.textContent; - /* - var copyCheckinCommentItem = contextMenu.Item({ - label: "Copy Check-in Comment", - context: onBugzillaPage, - onClick: function() require("clipboard").set(message) - }); - contextMenu.add(copyCheckinCommentItem); - d.defaultView.addEventListener("unload", function() { - contextMenu.remove(copyCheckinCommentItem); - }, false); - */ - } - } var iframe = d.createElement('iframe'); iframe.src = historyLink.href; @@ -796,11 +793,13 @@ CheckinCommentCtor.prototype = { checkinFlags.push(flag); } this.checkinFlags = checkinFlags.join(" "); - var div = doc.createElement("div"); - div.setAttribute("style", "display: none;"); - div.id = "__bz_tw_checkin_comment"; - div.appendChild(doc.createTextNode(this.toString())); - doc.body.appendChild(div); + if (this.isValid()) { + var div = doc.createElement("div"); + div.setAttribute("style", "display: none;"); + div.id = "__bz_tw_checkin_comment"; + div.appendChild(doc.createTextNode(this.toString())); + doc.body.appendChild(div); + } }, isValid: function() { return this.bugNumber != null && -- cgit