Web Inspector: Should include "Log Value" context menu item in Preview and Collapsed...
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Apr 2015 01:00:21 +0000 (01:00 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Apr 2015 01:00:21 +0000 (01:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143845

Reviewed by Timothy Hatcher.

Give previews the same "Log Value" context menu so that if you just log
a bunch of objects to the console you can quickly turn that entire object
into a $n reference in the console to interact with.

* UserInterface/Views/ObjectPreviewView.js:
(WebInspector.ObjectPreviewView.prototype.setOriginatingObjectInfo):
(WebInspector.ObjectPreviewView.prototype._contextMenuHandler):
Provide API to refer to a RemoteObject and optional PropertyPath
that can be used to give the preview a "Log Value" context menu.

* UserInterface/Views/ConsoleMessageView.js:
(WebInspector.ConsoleMessageView.prototype._appendFormattedArguments):
Include the RemoteObject without a path for a preview context menu.

* UserInterface/Views/ObjectTreeView.js:
(WebInspector.ObjectTreeView):
Include the RemoteObject with a path if we knew it for a preview context menu.

* UserInterface/Views/ObjectTreeBaseTreeElement.js:
(WebInspector.ObjectTreeBaseTreeElement.prototype.createGetterElement):
The context menu can never be empty, since we always added at least one item above.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182933 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js
Source/WebInspectorUI/UserInterface/Views/ObjectPreviewView.js
Source/WebInspectorUI/UserInterface/Views/ObjectTreeBaseTreeElement.js
Source/WebInspectorUI/UserInterface/Views/ObjectTreeView.js

index 7979665f0036a3a35eebd307b13d6a56c8117671..0a8f5c7c6f969123c3a27501059217729c420ea5 100644 (file)
@@ -1,3 +1,33 @@
+2015-04-16  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Should include "Log Value" context menu item in Preview and Collapsed ObjectTree
+        https://bugs.webkit.org/show_bug.cgi?id=143845
+
+        Reviewed by Timothy Hatcher.
+
+        Give previews the same "Log Value" context menu so that if you just log
+        a bunch of objects to the console you can quickly turn that entire object
+        into a $n reference in the console to interact with.
+
+        * UserInterface/Views/ObjectPreviewView.js:
+        (WebInspector.ObjectPreviewView.prototype.setOriginatingObjectInfo):
+        (WebInspector.ObjectPreviewView.prototype._contextMenuHandler):
+        Provide API to refer to a RemoteObject and optional PropertyPath
+        that can be used to give the preview a "Log Value" context menu.
+
+        * UserInterface/Views/ConsoleMessageView.js:
+        (WebInspector.ConsoleMessageView.prototype._appendFormattedArguments):
+        Include the RemoteObject without a path for a preview context menu.
+
+        * UserInterface/Views/ObjectTreeView.js:
+        (WebInspector.ObjectTreeView):
+        Include the RemoteObject with a path if we knew it for a preview context menu.
+
+        * UserInterface/Views/ObjectTreeBaseTreeElement.js:
+        (WebInspector.ObjectTreeBaseTreeElement.prototype.createGetterElement):
+        The context menu can never be empty, since we always added at least one item above.
+
+
 2015-04-16  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: "Log Value" of a value inside of an array, does not log the innermost value
index 057e1e2e00a7764a704b0a009963217bdef5d378..2017904b34a6f3aed15e76ac8be928f1d9f45e06 100644 (file)
@@ -390,6 +390,10 @@ WebInspector.ConsoleMessageView = class ConsoleMessageView extends WebInspector.
                 var parameter = parameters[0];
                 var preview = WebInspector.FormattedValue.createObjectPreviewOrFormattedValueForRemoteObject(parameter, WebInspector.ObjectPreviewView.Mode.Brief);
                 var isPreviewView = preview instanceof WebInspector.ObjectPreviewView;
+
+                if (isPreviewView)
+                    preview.setOriginatingObjectInfo(parameter, null);
+
                 var previewElement = isPreviewView ? preview.element : preview;
                 previewContainer.appendChild(previewElement);
 
index e81229d8ad66e3165cfcbcd5429fae2a8c49a276..490efaa919cef945b9ef9773c56d7e725eada739 100644 (file)
@@ -90,6 +90,18 @@ WebInspector.ObjectPreviewView = class ObjectPreviewView extends WebInspector.Ob
         this._previewElement.hidden = false;
     }
 
+    setOriginatingObjectInfo(remoteObject, propertyPath)
+    {
+        console.assert(!this._remoteObject);
+        console.assert(remoteObject instanceof WebInspector.RemoteObject);
+        console.assert(!propertyPath || propertyPath instanceof WebInspector.PropertyPath);
+
+        this._remoteObject = remoteObject;
+        this._propertyPath = propertyPath || null;
+
+        this.element.addEventListener("contextmenu", this._contextMenuHandler.bind(this));
+    }
+
     // Private
 
     _initTitleElement()
@@ -223,6 +235,24 @@ WebInspector.ObjectPreviewView = class ObjectPreviewView extends WebInspector.Ob
         element.appendChild(WebInspector.FormattedValue.createElementForObjectPreview(preview));
         return true;
     }
+
+    _contextMenuHandler(event)
+    {
+        var contextMenu = new WebInspector.ContextMenu(event);
+
+        contextMenu.appendItem(WebInspector.UIString("Log Value"), function() {
+            var remoteObject = this._remoteObject;
+            var isImpossible = !this._propertyPath || this._propertyPath.isFullPathImpossible();
+            var text = isImpossible ? WebInspector.UIString("Selected Value") : this._propertyPath.displayPath(WebInspector.PropertyPath.Type.Value);
+
+            if (!isImpossible)
+                WebInspector.quickConsole.prompt.pushHistoryItem(text);
+
+            WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(text, this._remoteObject);
+        }.bind(this));
+
+        contextMenu.show();        
+    }
 };
 
 WebInspector.ObjectPreviewView.Mode = {
index f494aaa26563e9f877f9ec27bf9531d21b07dc39..8ae1b77c5e34a350d6a317cf5f11293eea7fcd53 100644 (file)
@@ -204,8 +204,7 @@ WebInspector.ObjectTreeBaseTreeElement = class ObjectTreeBaseTreeElement extends
 
         this._appendMenusItemsForObject(contextMenu, resolvedValue);
 
-        if (!contextMenu.isEmpty())
-            contextMenu.show();
+        contextMenu.show();
     }
 
     _appendMenusItemsForObject(contextMenu, resolvedValue)
index cda2bd404f2bf901d1a7f26502aa0206c59aeb67..d26a76a44c65cf334648afa25045f942bebcaebd 100644 (file)
@@ -32,6 +32,8 @@ WebInspector.ObjectTreeView = class ObjectTreeView extends WebInspector.Object
         console.assert(object instanceof WebInspector.RemoteObject);
         console.assert(!propertyPath || propertyPath instanceof WebInspector.PropertyPath);
 
+        var providedPropertyPath = propertyPath instanceof WebInspector.PropertyPath;
+
         this._object = object;
         this._mode = mode || WebInspector.ObjectTreeView.defaultModeForObject(object);
         this._propertyPath = propertyPath || new WebInspector.PropertyPath(this._object, "this");
@@ -52,6 +54,7 @@ WebInspector.ObjectTreeView = class ObjectTreeView extends WebInspector.Object
 
         if (this._object.preview) {
             this._previewView = new WebInspector.ObjectPreviewView(this._object.preview);
+            this._previewView.setOriginatingObjectInfo(this._object, providedPropertyPath ? propertyPath : null);
             this._previewView.element.addEventListener("click", this._handlePreviewOrTitleElementClick.bind(this));
             this._element.appendChild(this._previewView.element);