Commit 5732b0d9 authored by semeny@google.com's avatar semeny@google.com

DevTools: Show doc context menu items for matching methods on all objects

If a few target objects have a method with the same name as the selection,
we should create context menu items for all of them.

BUG=391593

Review URL: https://codereview.chromium.org/466743002

git-svn-id: svn://svn.chromium.org/blink/trunk@180161 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8846c7d0
This test verifies URL created by WebInspector.DocumentationURLProvider
Property max:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Math/max&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Math/max&prop=revisions&rvprop=timestamp|content&format=json
Property insertBefore:
http://docs.webplatform.org/w/api.php?action=query&titles=dom/Node/insertBefore&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=dom/Node/insertBefore&prop=revisions&rvprop=timestamp|content&format=json
Property eval:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/eval&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/eval&prop=revisions&rvprop=timestamp|content&format=json
Property stringify:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/JSON/stringify&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/JSON/stringify&prop=revisions&rvprop=timestamp|content&format=json
Property isArray:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Array/isArray&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Array/isArray&prop=revisions&rvprop=timestamp|content&format=json
Property now:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Date/now&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Date/now&prop=revisions&rvprop=timestamp|content&format=json
Property fromCharCode:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/String/fromCharCode&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/String/fromCharCode&prop=revisions&rvprop=timestamp|content&format=json
Property keys:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Object/keys&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Object/keys&prop=revisions&rvprop=timestamp|content&format=json
1: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Array/keys&prop=revisions&rvprop=timestamp|content&format=json
Property notExist:
null
null
Property indexOf:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Array/indexOf&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Array/indexOf&prop=revisions&rvprop=timestamp|content&format=json
1: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/String/indexOf&prop=revisions&rvprop=timestamp|content&format=json
Property setDate:
http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Date/setDate&prop=revisions&rvprop=timestamp|content&format=json
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Date/setDate&prop=revisions&rvprop=timestamp|content&format=json
Property parse:
0: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/Date/parse&prop=revisions&rvprop=timestamp|content&format=json
1: http://docs.webplatform.org/w/api.php?action=query&titles=javascript/JSON/parse&prop=revisions&rvprop=timestamp|content&format=json
......@@ -17,12 +17,19 @@ function test()
"keys",
"notExist",
"indexOf",
"setDate"
];
"setDate",
"parse"
];
var urlFormer = new WebInspector.DocumentationURLProvider();
for (var i = 0; i < testCases.length; ++i) {
InspectorTest.addResult("Property " + testCases[i] + ":");
InspectorTest.addResult(urlFormer.itemPath(testCases[i]));
var properties = urlFormer.itemDescriptors(testCases[i]);
if (properties.length === 0) {
InspectorTest.addResult(" null");
continue;
}
for (var j = 0; j < properties.length; ++j)
InspectorTest.addResult(" " + j + ": " + properties[j].url);
}
InspectorTest.completeTest();
}
......
......@@ -11,22 +11,22 @@ WebInspector.DocumentationURLProvider = function()
/**
* @const
* @type {!Array.<!Object, string>}
* @type {!Array.<{source: !Object, url: string, name: string}>}
*/
WebInspector.DocumentationURLProvider._sources = [
{ source: window, url: "javascript/" },
{ source: window.Node.prototype, url: "dom/Node/" },
{ source: window.Node, url: "dom/Node/" },
{ source: window.Object.prototype, url: "javascript/Object/" },
{ source: window.Object, url: "javascript/Object/" },
{ source: window.Math, url: "javascript/Math/" },
{ source: window.Array.prototype, url: "javascript/Array/" },
{ source: window.Array, url: "javascript/Array/" },
{ source: window.String.prototype, url: "javascript/String/" },
{ source: window.String, url: "javascript/String/" },
{ source: window.Date.prototype, url: "javascript/Date/" },
{ source: window.Date, url: "javascript/Date/" },
{ source: window.JSON, url: "javascript/JSON/" }
{ source: window, url: "javascript/", name: "Global" },
{ source: window.Node.prototype, url: "dom/Node/", name: "Node.prototype" },
{ source: window.Node, url: "dom/Node/", name: "Node" },
{ source: window.Object.prototype, url: "javascript/Object/", name: "Object.prototype" },
{ source: window.Object, url: "javascript/Object/", name: "Object" },
{ source: window.Math, url: "javascript/Math/", name: "Math" },
{ source: window.Array.prototype, url: "javascript/Array/", name: "Array.prototype" },
{ source: window.Array, url: "javascript/Array/", name: "Array" },
{ source: window.String.prototype, url: "javascript/String/", name: "String.prototype" },
{ source: window.String, url: "javascript/String/", name: "String" },
{ source: window.Date.prototype, url: "javascript/Date/", name: "Date.prototype" },
{ source: window.Date, url: "javascript/Date/", name: "Date" },
{ source: window.JSON, url: "javascript/JSON/", name: "JSON" }
];
/**
......@@ -37,15 +37,21 @@ WebInspector.DocumentationURLProvider._urlFormat = "http://docs.webplatform.org/
WebInspector.DocumentationURLProvider.prototype = {
/**
* @param {string} searchTerm
* @return {?string}
* @return {!Array.<{url: string, name: string}>}
*/
itemPath: function(searchTerm)
itemDescriptors: function(searchTerm)
{
var possibleProperties = [];
for (var i = 0; i < WebInspector.DocumentationURLProvider._sources.length; ++i) {
var sourceRef = WebInspector.DocumentationURLProvider._sources[i];
if (sourceRef.source[searchTerm] instanceof Function)
return String.sprintf(WebInspector.DocumentationURLProvider._urlFormat, sourceRef.url, searchTerm);
if (sourceRef.source[searchTerm] instanceof Function) {
var property = {
url: String.sprintf(WebInspector.DocumentationURLProvider._urlFormat, sourceRef.url, searchTerm),
name: sourceRef.name
};
possibleProperties.push(property);
}
}
return null;
return possibleProperties;
}
}
......@@ -12,9 +12,9 @@ WebInspector.DocumentationView = function()
}
/**
* @param {string} searchTerm
* @param {string} url
*/
WebInspector.DocumentationView.showSearchTerm = function(searchTerm)
WebInspector.DocumentationView.showDocumentationURL = function(url)
{
if (!WebInspector.DocumentationView._view)
WebInspector.DocumentationView._view = new WebInspector.DocumentationView();
......@@ -50,9 +50,16 @@ WebInspector.DocumentationView.ContextMenuProvider.prototype = {
return;
var selectedText = textEditor.copyRange(selection);
var urlProvider = new WebInspector.DocumentationURLProvider();
var itemPath = urlProvider.itemPath(selectedText);
if (!itemPath)
var possibleProperties = urlProvider.itemDescriptors(selectedText);
if (!possibleProperties.length)
return;
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show documentation" : "Show Documentation"), WebInspector.DocumentationView.showSearchTerm.bind(null, selectedText));
if (possibleProperties.length === 1) {
var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show documentation for %s.%s" : "Show Documentation for %s.%s";
contextMenu.appendItem(WebInspector.UIString(formatString, possibleProperties[0].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.bind(null, possibleProperties[0].url));
return;
}
var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Documentation for..."));
for (var i = 0; i < possibleProperties.length; ++i)
subMenuItem.appendItem(String.sprintf("%s.%s", possibleProperties[i].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.bind(null, possibleProperties[i].url));
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment