Bug 417688 - Add context menu to copy URL for attached links in events/tasks. r=philipp,a=philipp
authorMerike Sell <merike.sell@eesti.ee>
Sun, 05 Feb 2012 21:44:27 +0100
changeset 10779 dfbe3fe97df96e79d4940ecbea47501f6b69eb9d
parent 10778 109a02643af0c159405211ff21ddbb1036189d30
child 10780 2896ec0b8c069e665052c14b68636e31492e6849
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp, philipp
bugs417688
Bug 417688 - Add context menu to copy URL for attached links in events/tasks. r=philipp,a=philipp
calendar/base/content/calendar-common-sets.xul
calendar/base/content/calendar-task-view.js
calendar/base/content/dialogs/calendar-event-dialog.js
calendar/base/content/dialogs/calendar-event-dialog.xul
calendar/locales/en-US/chrome/calendar/calendar.dtd
--- a/calendar/base/content/calendar-common-sets.xul
+++ b/calendar/base/content/calendar-common-sets.xul
@@ -593,10 +593,18 @@
                     value="all"
                     type="radio"
                     command="calendar_task_filter_todaypane_command"
                     label="&calendar.task.filter.all.label;"
                     accesskey="&calendar.task.filter.all.accesskey;"/>
         </menupopup>
       </menu>
     </menupopup>
+
+    <!-- TASKVIEW LINK CONTEXT MENU -->
+    <menupopup id="taskview-link-context-menu">
+      <menuitem id="taskview-link-context-menu-copy"
+                label="&calendar.copylink.label;"
+                accesskey="&calendar.copylink.accesskey;"
+                oncommand="taskViewCopyLink(document.popupNode)"/>
+    </menupopup>
   </popupset>
 </overlay>
--- a/calendar/base/content/calendar-task-view.js
+++ b/calendar/base/content/calendar-task-view.js
@@ -167,17 +167,19 @@ var taskDetailsView = {
                 displayElement("calendar-task-details-attachment-rows", true);
                 for each (let attachment in attachments) {
                     let url = attachment.calIAttachment.uri.spec
                     let urlLabel = createXULElement("label");
                     urlLabel.setAttribute("value", url);
                     urlLabel.setAttribute("tooltiptext", url);
                     urlLabel.setAttribute("class", "text-link");
                     urlLabel.setAttribute("crop", "end");
-                    urlLabel.setAttribute("onclick", "launchBrowser(this.value)");
+                    urlLabel.setAttribute("onclick",
+                                          "if (event.button != 2) launchBrowser(this.value);");
+                    urlLabel.setAttribute("context", "taskview-link-context-menu");
                     attachmentRows.appendChild(urlLabel);
                 }
             }
         }
     },
 
     /**
      * Initialize the task actions toolbar by setting default mode, icon size,
@@ -323,9 +325,23 @@ function taskViewOnLoad() {
                                                    "keyLabelMac" : "keyLabelNonMac");
 
             textFilter.setAttribute("placeholder", base.replace("#1", keyLabel));
             textFilter.value = "";
         }
     }
 }
 
+/**
+ * Copy the value of the given link node to the clipboard
+ *
+ * @param linkNode      The node containing the value to copy to the clipboard
+ */
+function taskViewCopyLink(linkNode) {
+    if (linkNode) {
+        let linkAddress = linkNode.value;
+        let clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
+                                  .getService(Components.interfaces.nsIClipboardHelper);
+        clipboard.copyString(linkAddress);
+    }
+}
+
 window.addEventListener("load", taskViewOnLoad, false);
--- a/calendar/base/content/dialogs/calendar-event-dialog.js
+++ b/calendar/base/content/dialogs/calendar-event-dialog.js
@@ -1875,16 +1875,27 @@ function openAttachment() {
         var externalLoader = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
                                        .getService(Components.interfaces.nsIExternalProtocolService);
         // TODO There should be a nicer dialog
         externalLoader.loadUrl(attURI);
     }
 }
 
 /**
+ * Copies the link location of the first selected attachment to the clipboard
+ */
+function copyAttachment() {
+    let documentLink = document.getElementById("attachment-link");
+    let attURI = documentLink.getSelectedItem(0).attachment.uri.spec;
+    let clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
+                              .getService(Components.interfaces.nsIClipboardHelper);
+    clipboard.copyString(attURI);
+}
+
+/**
  * Handler function to handle pressing keys in the attachment listbox.
  *
  * @param event     The DOM event caused by the key press.
  */
 function attachmentLinkKeyPress(event) {
     const kKE = Components.interfaces.nsIDOMKeyEvent;
     switch (event.keyCode) {
         case kKE.DOM_VK_BACK_SPACE:
--- a/calendar/base/content/dialogs/calendar-event-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog.xul
@@ -208,17 +208,19 @@
                  value="OPAQUE"/>
         <command id="cmd_showtimeas_free"
                  oncommand="editShowTimeAs(event.target)"
                  value="TRANSPARENT"/>
         <command id="cmd_attach_url"
                  disable-on-readonly="true"
                  oncommand="attachURL()"/>
         <command id="cmd_openAttachment"
-                 oncommand="openAttachment()"/> 
+                 oncommand="openAttachment()"/>
+        <command id="cmd_copyAttachment"
+                 oncommand="copyAttachment()"/>
         <command id="cmd_deleteAttachment"
                  disable-on-readonly="true"
                  oncommand="deleteAttachment()"/>
         <command id="cmd_deleteAllAttachments"
                  disable-on-readonly="true"
                  oncommand="deleteAllAttachments()"/>
         <command id="cmd_timezone"
                  oncommand="updateDateTime()"/>
@@ -1166,16 +1168,20 @@
         <menuseparator id="attendee-popup-separator"/>
         <menuitem class="status-icon menuitem-iconic" oncommand="sendMailToAttendees([event.target.attendee])" crop="end"/>
       </menupopup>
       <menupopup id="attachment-popup">
             <menuitem id="attachment-popup-open"
                       label="&event.attachments.popup.open.label;"
                       accesskey="&event.attachments.popup.open.accesskey;"
                       command="cmd_openAttachment"/>
+            <menuitem id="attachment-popup-copy"
+                      label="&calendar.copylink.label;"
+                      accesskey="&calendar.copylink.accesskey;"
+                      command="cmd_copyAttachment"/>
             <menuitem id="attachment-popup-delete"
                       label="&event.attachments.popup.remove.label;"
                       accesskey="&event.attachments.popup.remove.accesskey;"
                       command="cmd_deleteAttachment"/>
             <menuitem id="attachment-popup-deleteAll"
                       label="&event.attachments.popup.removeAll.label;"
                       accesskey="&event.attachments.popup.removeAll.accesskey;"
                       command="cmd_deleteAllAttachments"/>
--- a/calendar/locales/en-US/chrome/calendar/calendar.dtd
+++ b/calendar/locales/en-US/chrome/calendar/calendar.dtd
@@ -248,16 +248,19 @@
 
 <!ENTITY calendar.context.postpone.1hour.label      "1 Hour">
 <!ENTITY calendar.context.postpone.1hour.accesskey  "H">
 <!ENTITY calendar.context.postpone.1day.label       "1 Day">
 <!ENTITY calendar.context.postpone.1day.accesskey   "D">
 <!ENTITY calendar.context.postpone.1week.label      "1 Week">
 <!ENTITY calendar.context.postpone.1week.accesskey  "W">
 
+<!ENTITY calendar.copylink.label       "Copy Link Location">
+<!ENTITY calendar.copylink.accesskey   "C">
+
 <!-- Task View -->
 <!-- Note that the above *.context.* strings are currently used for the other
      task action buttons -->
 <!ENTITY calendar.taskview.delete.label     "Delete">
 <!ENTITY calendar.taskview.delete.accesskey "l">
 
 <!-- Server Context Menu -->
 <!ENTITY calendar.context.newserver.label              "New Calendar…">