OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
8 */ | 8 */ |
9 WebInspector.DocumentationView = function() | 9 WebInspector.DocumentationView = function() |
10 { | 10 { |
(...skipping 27 matching lines...) Expand all Loading... | |
38 /** | 38 /** |
39 * @param {!Event} event | 39 * @param {!Event} event |
40 * @param {!WebInspector.ContextMenu} contextMenu | 40 * @param {!WebInspector.ContextMenu} contextMenu |
41 * @param {!Object} target | 41 * @param {!Object} target |
42 */ | 42 */ |
43 appendApplicableItems: function(event, contextMenu, target) | 43 appendApplicableItems: function(event, contextMenu, target) |
44 { | 44 { |
45 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) | 45 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) |
46 return; | 46 return; |
47 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); | 47 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); |
48 var selection = textEditor.selection(); | 48 var descriptors = this._determineDescriptors(textEditor); |
49 if (!selection || selection.isEmpty() || selection.startLine !== selecti on.endLine) | 49 |
50 return; | |
51 var selectedText = textEditor.copyRange(selection); | |
52 var urlProvider = new WebInspector.DocumentationURLProvider(); | |
53 var descriptors = urlProvider.itemDescriptors(selectedText); | |
54 if (!descriptors.length) | 50 if (!descriptors.length) |
55 return; | 51 return; |
56 if (descriptors.length === 1) { | 52 if (descriptors.length === 1) { |
57 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc umentation for %s.%s" : "Show Documentation for %s.%s"; | 53 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc umentation for %s.%s" : "Show Documentation for %s.%s"; |
58 contextMenu.appendItem(WebInspector.UIString(formatString, descripto rs[0].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.b ind(null, descriptors[0].url)); | 54 contextMenu.appendItem(WebInspector.UIString(formatString, descripto rs[0].name, descriptors[0].searchItem), WebInspector.DocumentationView.showDocum entationURL.bind(null, descriptors[0].url)); |
59 return; | 55 return; |
60 } | 56 } |
61 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume ntation for...")); | 57 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume ntation for...")); |
62 for (var i = 0; i < descriptors.length; ++i) | 58 for (var i = 0; i < descriptors.length; ++i) |
63 subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name, selectedText), WebInspector.DocumentationView.showDocumentationURL.bind(null, de scriptors[i].url)); | 59 subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name, descriptors[i].searchItem), WebInspector.DocumentationView.showDocumentationURL. bind(null, descriptors[i].url)); |
60 }, | |
61 /** | |
apavlov
2014/08/15 10:48:58
blank line above
semeny
2014/08/15 11:00:57
Done.
| |
62 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | |
63 * @return {!Array.<{url: string, name: string, searchItem: string}>} | |
64 */ | |
65 _determineDescriptors: function(textEditor) | |
66 { | |
67 var urlProvider = new WebInspector.DocumentationURLProvider(); | |
68 var textSelection = textEditor.selection().normalize(); | |
69 | |
70 if (!textSelection.isEmpty()) { | |
71 if (textSelection.startLine !== textSelection.endLine) | |
72 return []; | |
73 return urlProvider.itemDescriptors(textEditor.copyRange(textSelectio n)); | |
74 } | |
75 | |
76 var descriptors = computeDescriptors(textSelection.startColumn); | |
77 if (descriptors && descriptors.length) | |
apavlov
2014/08/15 10:48:58
|descriptors| is never null, please remove the fir
semeny
2014/08/15 11:00:57
Done.
| |
78 return descriptors; | |
79 | |
80 return computeDescriptors(textSelection.startColumn - 1); | |
81 | |
82 function computeDescriptors(column) | |
apavlov
2014/08/15 10:48:58
Please annotate
semeny
2014/08/15 11:00:57
Done.
| |
83 { | |
84 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); | |
85 if (!token) | |
86 return []; | |
87 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); | |
88 return urlProvider.itemDescriptors(tokenText); | |
89 } | |
64 } | 90 } |
65 } | 91 } |
OLD | NEW |