Bug 1115363 - Implement copy text option on sidebar of storage. r=miker
authorfanny <fannyvieira082@gmail.com>
Fri, 22 Mar 2019 13:26:42 +0000
changeset 465692 f12b85babb3fb4c3ab6aebe22e2e4dcf3c49e0b6
parent 465691 91936ad1c3f1145d94d2be054012dcba5ad76311
child 465693 8126cdde0a7805b4c5e10b9d8a9cccb7504f6dfb
push id35746
push usershindli@mozilla.com
push dateSat, 23 Mar 2019 09:46:24 +0000
treeherdermozilla-central@02b7484f316b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiker
bugs1115363
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1115363 - Implement copy text option on sidebar of storage. r=miker Before this change, there was no option to copy text of an attribute in sidebar of storage.You can now copy an attribute and it's text. Differential Revision: https://phabricator.services.mozilla.com/D23977
devtools/client/locales/en-US/storage.dtd
devtools/client/shared/widgets/VariablesView.jsm
devtools/client/storage/index.xul
devtools/client/storage/ui.js
--- a/devtools/client/locales/en-US/storage.dtd
+++ b/devtools/client/locales/en-US/storage.dtd
@@ -7,8 +7,11 @@
 <!-- LOCALIZATION NOTE : Placeholder for the searchbox that allows you to filter the table items. -->
 <!ENTITY searchBox.placeholder         "Filter items">
 
 <!-- LOCALIZATION NOTE : Label of popup menu action to delete all storage items. -->
 <!ENTITY storage.popupMenu.deleteAllLabel "Delete All">
 
 <!-- LOCALIZATION NOTE : Label of popup menu action to delete all session cookies. -->
 <!ENTITY storage.popupMenu.deleteAllSessionCookiesLabel "Delete All Session Cookies">
+
+<!-- LOCALIZATION NOTE : Label of popup menu action to copy a storage item. -->
+<!ENTITY storage.popupMenu.copyLabel "Copy">
--- a/devtools/client/shared/widgets/VariablesView.jsm
+++ b/devtools/client/shared/widgets/VariablesView.jsm
@@ -782,32 +782,38 @@ VariablesView.prototype = {
       aItem.collapse();
     }
     aItem._target.focus();
     aItem._arrow.scrollIntoView({ block: "nearest" });
     return true;
   },
 
   /**
+   * Copy current selection to clipboard.
+   */
+  _copyItem: function() {
+    const item = this.getFocusedItem();
+    clipboardHelper.copyString(
+      item._nameString + item.separatorStr + item._valueString
+    );
+  },
+
+  /**
    * Listener handling a key down event on the view.
    */
   _onViewKeyDown: function(e) {
     const item = this.getFocusedItem();
 
     // Prevent scrolling when pressing navigation keys.
     ViewHelpers.preventScrolling(e);
 
     switch (e.keyCode) {
       case KeyCodes.DOM_VK_C:
-        // Copy current selection to clipboard.
         if (e.ctrlKey || e.metaKey) {
-          const item = this.getFocusedItem();
-          clipboardHelper.copyString(
-            item._nameString + item.separatorStr + item._valueString
-          );
+          this._copyItem();
         }
         return;
 
       case KeyCodes.DOM_VK_UP:
         // Always rewind focus.
         this.focusPrevItem(true);
         return;
 
--- a/devtools/client/storage/index.xul
+++ b/devtools/client/storage/index.xul
@@ -23,16 +23,20 @@
   <popupset id="storagePopupSet">
     <menupopup id="storage-tree-popup">
       <menuitem id="storage-tree-popup-delete-all"
                 label="&storage.popupMenu.deleteAllLabel;"/>
       <menuitem id="storage-tree-popup-delete-all-session-cookies"
                 label="&storage.popupMenu.deleteAllSessionCookiesLabel;"/>
       <menuitem id="storage-tree-popup-delete"/>
     </menupopup>
+    <menupopup id="variable-view-popup">
+      <menuitem id="variable-view-popup-copy"
+                label="&storage.popupMenu.copyLabel;"/>
+    </menupopup>
     <menupopup id="storage-table-popup">
       <menuitem id="storage-table-popup-add"/>
       <menuitem id="storage-table-popup-delete"/>
       <menuitem id="storage-table-popup-delete-all-from"/>
       <menuitem id="storage-table-popup-delete-all"
                 label="&storage.popupMenu.deleteAllLabel;"/>
       <menuitem id="storage-table-popup-delete-all-session-cookies"
                 label="&storage.popupMenu.deleteAllSessionCookiesLabel;"/>
--- a/devtools/client/storage/ui.js
+++ b/devtools/client/storage/ui.js
@@ -33,16 +33,17 @@ loader.lazyRequireGetter(this, "validato
 const STORAGE_STRINGS = "devtools/client/locales/storage.properties";
 const L10N = new LocalizationHelper(STORAGE_STRINGS);
 
 const GENERIC_VARIABLES_VIEW_SETTINGS = {
   lazyEmpty: true,
    // ms
   lazyEmptyDelay: 10,
   searchEnabled: true,
+  contextMenuId: "variable-view-popup",
   searchPlaceholder: L10N.getStr("storage.search.placeholder"),
   preventDescriptorModifiers: true,
 };
 
 const REASON = {
   NEW_ROW: "new-row",
   NEXT_50_ITEMS: "next-50-items",
   POPULATE: "populate",
@@ -175,32 +176,42 @@ class StorageUI {
     this.onTreePopupShowing = this.onTreePopupShowing.bind(this);
     this._treePopup = this._panelDoc.getElementById("storage-tree-popup");
     this._treePopup.addEventListener("popupshowing", this.onTreePopupShowing);
 
     this.onTablePopupShowing = this.onTablePopupShowing.bind(this);
     this._tablePopup = this._panelDoc.getElementById("storage-table-popup");
     this._tablePopup.addEventListener("popupshowing", this.onTablePopupShowing);
 
+    this.onVariableViewPopupShowing = this.onVariableViewPopupShowing.bind(this);
+    this._variableViewPopup = this._panelDoc.getElementById("variable-view-popup");
+    this._variableViewPopup.addEventListener("popupshowing",
+      this.onVariableViewPopupShowing);
+
     this.onRefreshTable = this.onRefreshTable.bind(this);
     this.onAddItem = this.onAddItem.bind(this);
+    this.onCopyItem = this.onCopyItem.bind(this);
     this.onRemoveItem = this.onRemoveItem.bind(this);
     this.onRemoveAllFrom = this.onRemoveAllFrom.bind(this);
     this.onRemoveAll = this.onRemoveAll.bind(this);
     this.onRemoveAllSessionCookies = this.onRemoveAllSessionCookies.bind(this);
     this.onRemoveTreeItem = this.onRemoveTreeItem.bind(this);
 
     this._refreshButton = this._panelDoc.getElementById("refresh-button");
     this._refreshButton.addEventListener("command", this.onRefreshTable);
     this._refreshButton.setAttribute("tooltiptext",
     L10N.getFormatStr("storage.popupMenu.refreshItemLabel"));
 
     this._addButton = this._panelDoc.getElementById("add-button");
     this._addButton.addEventListener("command", this.onAddItem);
 
+    this._variableViewPopupCopy = this._panelDoc.getElementById(
+      "variable-view-popup-copy");
+    this._variableViewPopupCopy.addEventListener("command", this.onCopyItem);
+
     this._tablePopupAddItem = this._panelDoc.getElementById(
       "storage-table-popup-add");
     this._tablePopupAddItem.addEventListener("command", this.onAddItem);
 
     this._tablePopupDelete = this._panelDoc.getElementById(
       "storage-table-popup-delete");
     this._tablePopupDelete.addEventListener("command", this.onRemoveItem);
 
@@ -309,17 +320,16 @@ class StorageUI {
    */
   hideSidebar() {
     this.sidebar.hidden = true;
     this.updateSidebarToggleButton();
   }
 
   getCurrentFront() {
     const type = this.table.datatype;
-
     return this.storageTypes[type];
   }
 
   /**
    *  Make column fields editable
    *
    *  @param {Array} editableFields
    *         An array of keys of columns to be made editable
@@ -1276,16 +1286,21 @@ class StorageUI {
       showMenu = showDeleteAll || showDelete;
     }
 
     if (!showMenu) {
       event.preventDefault();
     }
   }
 
+  onVariableViewPopupShowing(event) {
+    const item = this.view.getFocusedItem();
+    this._variableViewPopupCopy.setAttribute("disabled", !item);
+  }
+
   /**
    * Handles refreshing the selected storage
    */
   async onRefreshTable() {
     await this.onHostSelect(this.tree.selectedItem);
   }
 
   /**
@@ -1302,16 +1317,23 @@ class StorageUI {
 
     // Prepare to scroll into view.
     this.table.scrollIntoViewOnUpdate = true;
     this.table.editBookmark = createGUID();
     front.addItem(this.table.editBookmark, host);
   }
 
   /**
+   * Handles copy an item from the storage
+   */
+  onCopyItem() {
+    this.view._copyItem();
+  }
+
+  /**
    * Handles removing an item from the storage
    */
   onRemoveItem() {
     const [, host, ...path] = this.tree.selectedItem;
     const front = this.getCurrentFront();
     const uniqueId = this.table.uniqueId;
     const rowId = this.table.contextMenuRowId || this.table.selectedRow[uniqueId];
     const data = this.table.items.get(rowId);