Created
April 5, 2015 22:14
-
-
Save jasonLaster/2f85087d61ce6ca7e0d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 42fdea2cf023b5be78f5ac6af8777f5e166fd93c | |
Author: Jason Laster <jason.laster.11@gmail.com> | |
Date: Fri Apr 3 20:02:27 2015 -0400 | |
Add "save to Global Variable" to element nodes | |
diff --git a/Source/devtools/front_end/common/module.json b/Source/devtools/front_end/common/module.json | |
index 634dcae..7f56dcf 100644 | |
--- a/Source/devtools/front_end/common/module.json | |
+++ b/Source/devtools/front_end/common/module.json | |
@@ -15,6 +15,7 @@ | |
"ParsedURL.js", | |
"Progress.js", | |
"ResourceType.js", | |
+ "saveToTempVariable.js", | |
"Settings.js", | |
"StaticContentProvider.js", | |
"Streams.js", | |
diff --git a/Source/devtools/front_end/common/saveToTempVariable.js b/Source/devtools/front_end/common/saveToTempVariable.js | |
new file mode 100644 | |
index 0000000..4faed95 | |
--- /dev/null | |
+++ b/Source/devtools/front_end/common/saveToTempVariable.js | |
@@ -0,0 +1,95 @@ | |
+/* | |
+ * Copyright (C) 2009 Apple Inc. All rights reserved. | |
+ * Copyright (C) 2009 Joseph Pecoraro | |
+ * | |
+ * Redistribution and use in source and binary forms, with or without | |
+ * modification, are permitted provided that the following conditions | |
+ * are met: | |
+ * | |
+ * 1. Redistributions of source code must retain the above copyright | |
+ * notice, this list of conditions and the following disclaimer. | |
+ * 2. Redistributions in binary form must reproduce the above copyright | |
+ * notice, this list of conditions and the following disclaimer in the | |
+ * documentation and/or other materials provided with the distribution. | |
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
+ * its contributors may be used to endorse or promote products derived | |
+ * from this software without specific prior written permission. | |
+ * | |
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
+ */ | |
+ | |
+/** | |
+ * @param {!WebInspector.RemoteObject} remoteObject | |
+ */ | |
+WebInspector.saveToTempVariable = function(remoteObject) { | |
+ var currentExecutionContext = WebInspector.context.flavor(WebInspector.ExecutionContext); | |
+ if (!currentExecutionContext) | |
+ return; | |
+ | |
+ currentExecutionContext.globalObject("", false, false, didGetGlobalObject); | |
+ /** | |
+ * @param {?WebInspector.RemoteObject} global | |
+ * @param {boolean=} wasThrown | |
+ */ | |
+ function didGetGlobalObject(global, wasThrown) | |
+ { | |
+ /** | |
+ * @suppressReceiverCheck | |
+ * @this {Window} | |
+ */ | |
+ function remoteFunction(value) | |
+ { | |
+ console.log('temp ya ya ya ', value); | |
+ var prefix = "temp"; | |
+ var index = 1; | |
+ while ((prefix + index) in this) | |
+ ++index; | |
+ var name = prefix + index; | |
+ this[name] = value; | |
+ return name; | |
+ } | |
+ | |
+ if (wasThrown || !global) | |
+ failedToSave(global); | |
+ else | |
+ global.callFunction(remoteFunction, [WebInspector.RemoteObject.toCallArgument(remoteObject)], didSave.bind(null, global)); | |
+ } | |
+ | |
+ /** | |
+ * @param {!WebInspector.RemoteObject} global | |
+ * @param {?WebInspector.RemoteObject} result | |
+ * @param {boolean=} wasThrown | |
+ */ | |
+ function didSave(global, result, wasThrown) | |
+ { | |
+ console.log('did save', result, result.value); | |
+ global.release(); | |
+ if (wasThrown || !result || result.type !== "string") | |
+ failedToSave(result); | |
+ else | |
+ WebInspector.ConsoleModel.evaluateCommandInConsole(currentExecutionContext, result.value); | |
+ } | |
+ | |
+ /** | |
+ * @param {?WebInspector.RemoteObject} result | |
+ */ | |
+ function failedToSave(result) | |
+ { | |
+ console.log('failed to save', result); | |
+ var message = WebInspector.UIString("Failed to save to temp variable."); | |
+ if (result) { | |
+ message += " " + result.description; | |
+ result.release(); | |
+ } | |
+ WebInspector.console.error(message); | |
+ } | |
+}; | |
\ No newline at end of file | |
diff --git a/Source/devtools/front_end/elements/ElementsTreeOutline.js b/Source/devtools/front_end/elements/ElementsTreeOutline.js | |
index 3593ae8..cdb99e7 100644 | |
--- a/Source/devtools/front_end/elements/ElementsTreeOutline.js | |
+++ b/Source/devtools/front_end/elements/ElementsTreeOutline.js | |
@@ -943,6 +943,9 @@ WebInspector.ElementsTreeOutline.prototype = { | |
treeElement.populateScrollIntoView(contextMenu); | |
} | |
+ | |
+ contextMenu.appendItem(WebInspector.UIString.capitalize("Store as ^global ^variable"), WebInspector.saveToTempVariable.bind(this, treeElement.node())); | |
+ | |
contextMenu.appendApplicableItems(treeElement.node()); | |
contextMenu.show(); | |
}, | |
diff --git a/Source/devtools/front_end/sources/SourcesPanel.js b/Source/devtools/front_end/sources/SourcesPanel.js | |
index db815a3..161fdd3 100644 | |
--- a/Source/devtools/front_end/sources/SourcesPanel.js | |
+++ b/Source/devtools/front_end/sources/SourcesPanel.js | |
@@ -955,7 +955,7 @@ WebInspector.SourcesPanel.prototype = { | |
if (!(target instanceof WebInspector.RemoteObject)) | |
return; | |
var remoteObject = /** @type {!WebInspector.RemoteObject} */ (target); | |
- contextMenu.appendItem(WebInspector.UIString.capitalize("Store as ^global ^variable"), this._saveToTempVariable.bind(this, remoteObject)); | |
+ contextMenu.appendItem(WebInspector.UIString.capitalize("Store as ^global ^variable"), WebInspector.saveToTempVariable.bind(this, remoteObject)); | |
if (remoteObject.type === "function") | |
contextMenu.appendItem(WebInspector.UIString.capitalize("Show ^function ^definition"), this._showFunctionDefinition.bind(this, remoteObject)); | |
if (remoteObject.subtype === "generator") | |
@@ -978,70 +978,7 @@ WebInspector.SourcesPanel.prototype = { | |
contextMenu.appendItem(openText, this.showUILocation.bind(this, uiSourceCode.uiLocation(0, 0))); | |
}, | |
- /** | |
- * @param {!WebInspector.RemoteObject} remoteObject | |
- */ | |
- _saveToTempVariable: function(remoteObject) | |
- { | |
- var currentExecutionContext = WebInspector.context.flavor(WebInspector.ExecutionContext); | |
- if (!currentExecutionContext) | |
- return; | |
- currentExecutionContext.globalObject("", false, false, didGetGlobalObject); | |
- /** | |
- * @param {?WebInspector.RemoteObject} global | |
- * @param {boolean=} wasThrown | |
- */ | |
- function didGetGlobalObject(global, wasThrown) | |
- { | |
- /** | |
- * @suppressReceiverCheck | |
- * @this {Window} | |
- */ | |
- function remoteFunction(value) | |
- { | |
- var prefix = "temp"; | |
- var index = 1; | |
- while ((prefix + index) in this) | |
- ++index; | |
- var name = prefix + index; | |
- this[name] = value; | |
- return name; | |
- } | |
- | |
- if (wasThrown || !global) | |
- failedToSave(global); | |
- else | |
- global.callFunction(remoteFunction, [WebInspector.RemoteObject.toCallArgument(remoteObject)], didSave.bind(null, global)); | |
- } | |
- | |
- /** | |
- * @param {!WebInspector.RemoteObject} global | |
- * @param {?WebInspector.RemoteObject} result | |
- * @param {boolean=} wasThrown | |
- */ | |
- function didSave(global, result, wasThrown) | |
- { | |
- global.release(); | |
- if (wasThrown || !result || result.type !== "string") | |
- failedToSave(result); | |
- else | |
- WebInspector.ConsoleModel.evaluateCommandInConsole(currentExecutionContext, result.value); | |
- } | |
- | |
- /** | |
- * @param {?WebInspector.RemoteObject} result | |
- */ | |
- function failedToSave(result) | |
- { | |
- var message = WebInspector.UIString("Failed to save to temp variable."); | |
- if (result) { | |
- message += " " + result.description; | |
- result.release(); | |
- } | |
- WebInspector.console.error(message); | |
- } | |
- }, | |
/** | |
* @param {!WebInspector.RemoteObject} remoteObject |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment