Commit 64eeaf6f authored by einbinder's avatar einbinder Committed by Commit bot

DevTools: Create extensible QuickOpen control

GoToLineDialog and QuickOpen are spun off from OpenResourceDialog.
QuickOpen switches between GoToLineDialog and OpenResourceDialog depending on
whether the query starts with ':'.
QuickOpen loads delegates through the runtime system.

BUG=662081

Review-Url: https://codereview.chromium.org/2679483002
Cr-Commit-Position: refs/heads/master@{#460536}
parent 1c59eda4
...@@ -36,9 +36,9 @@ Selected item index: 0 ...@@ -36,9 +36,9 @@ Selected item index: 0
History:["","aB","ab","aab","^[]{}()\\.$*+?|"] History:["","aB","ab","aab","^[]{}()\\.$*+?|"]
test: itemIndexIsNotReportedInGoToLine test: itemIndexIsNotReportedInGoToLine
Input:[":1:2:3.js"] Input:[]
Query:":1" Query:":1"
Output:[":1:2:3.js"] Output:[]
Selected item index: null Selected item index: null
History:["","aB","ab","aab","^[]{}()\\.$*+?|",":1"] History:["","aB","ab","aab","^[]{}()\\.$*+?|",":1"]
......
...@@ -3,7 +3,6 @@ function test() { ...@@ -3,7 +3,6 @@ function test() {
TestRunner.addResult("Check to see that FilteredItemSelectionDialog uses proper regex to filter results."); TestRunner.addResult("Check to see that FilteredItemSelectionDialog uses proper regex to filter results.");
var overridenInput = []; var overridenInput = [];
var overrideShowMatchingItems = true;
var history = []; var history = [];
var StubProvider = class extends QuickOpen.FilteredListWidget.Provider { var StubProvider = class extends QuickOpen.FilteredListWidget.Provider {
...@@ -14,15 +13,13 @@ function test() { ...@@ -14,15 +13,13 @@ function test() {
{ {
TestRunner.addResult("Selected item index: " + itemIndex); TestRunner.addResult("Selected item index: " + itemIndex);
} }
shouldShowMatchingItems () { return overrideShowMatchingItems; }
}; };
var provider = new StubProvider(); var provider = new StubProvider();
function checkQuery(query, input, hideMatchingItems) function checkQuery(query, input)
{ {
overridenInput = input; overridenInput = input;
overrideShowMatchingItems = !hideMatchingItems;
TestRunner.addResult("Input:" + JSON.stringify(input)); TestRunner.addResult("Input:" + JSON.stringify(input));
...@@ -67,22 +64,22 @@ function test() { ...@@ -67,22 +64,22 @@ function test() {
return checkQuery("ab", ["abc", "bac", "a_B"]); return checkQuery("ab", ["abc", "bac", "a_B"]);
}, },
function dumplicateSymbolsInQuery(next) function dumplicateSymbolsInQuery()
{ {
return checkQuery("aab", ["abab", "abaa", "caab", "baac", "fooaab"]); return checkQuery("aab", ["abab", "abaa", "caab", "baac", "fooaab"]);
}, },
function dangerousInputEscaping(next) function dangerousInputEscaping()
{ {
return checkQuery("^[]{}()\\.$*+?|", ["^[]{}()\\.$*+?|", "0123456789abcdef"]); return checkQuery("^[]{}()\\.$*+?|", ["^[]{}()\\.$*+?|", "0123456789abcdef"]);
}, },
function itemIndexIsNotReportedInGoToLine(next) function itemIndexIsNotReportedInGoToLine()
{ {
return checkQuery(":1", [":1:2:3.js"], true, next); return checkQuery(":1", []);
}, },
function autoCompleteIsLast(next) function autoCompleteIsLast()
{ {
return checkQuery("", ["abc", "abcd"]); return checkQuery("", ["abc", "abcd"]);
} }
......
...@@ -25,8 +25,7 @@ function test() ...@@ -25,8 +25,7 @@ function test()
function goToSourceDialogBeforeBinding(next) function goToSourceDialogBeforeBinding(next)
{ {
dumpGoToSourceDialog(); dumpGoToSourceDialog(next);
next();
}, },
function addFileSystemMapping(next) function addFileSystemMapping(next)
...@@ -37,21 +36,22 @@ function test() ...@@ -37,21 +36,22 @@ function test()
function goToSourceAfterBinding(next) function goToSourceAfterBinding(next)
{ {
dumpGoToSourceDialog(); dumpGoToSourceDialog(next);
next();
}, },
]); ]);
function dumpGoToSourceDialog() function dumpGoToSourceDialog(next)
{ {
UI.panels.sources._sourcesView.showOpenResourceDialog(); QuickOpen.QuickOpen.show('');
var dialog = Sources.OpenResourceDialog._instanceForTest; InspectorTest.addSnifferPromise(QuickOpen.QuickOpen.prototype, '_providerLoadedForTest').then(provider => {
var keys = []; var keys = [];
for (var i = 0; i < dialog.itemCount(); ++i) for (var i = 0; i < provider.itemCount(); ++i)
keys.push(dialog.itemKeyAt(i)); keys.push(provider.itemKeyAt(i));
keys.sort(); keys.sort();
InspectorTest.addResult(keys.join("\n")); InspectorTest.addResult(keys.join("\n"));
UI.Dialog._instance.hide(); UI.Dialog._instance.hide();
next();
});
} }
}; };
</script> </script>
......
...@@ -402,6 +402,7 @@ all_devtools_files = [ ...@@ -402,6 +402,7 @@ all_devtools_files = [
"front_end/quick_open/CommandMenu.js", "front_end/quick_open/CommandMenu.js",
"front_end/quick_open/filteredListWidget.css", "front_end/quick_open/filteredListWidget.css",
"front_end/quick_open/FilteredListWidget.js", "front_end/quick_open/FilteredListWidget.js",
"front_end/quick_open/QuickOpen.js",
"front_end/quick_open/module.json", "front_end/quick_open/module.json",
"front_end/resources/ApplicationCacheModel.js", "front_end/resources/ApplicationCacheModel.js",
"front_end/resources/ApplicationCacheItemsView.js", "front_end/resources/ApplicationCacheItemsView.js",
...@@ -524,6 +525,7 @@ all_devtools_files = [ ...@@ -524,6 +525,7 @@ all_devtools_files = [
"front_end/sources/FileBasedSearchResultsPane.js", "front_end/sources/FileBasedSearchResultsPane.js",
"front_end/sources/FilePathScoreFunction.js", "front_end/sources/FilePathScoreFunction.js",
"front_end/sources/FilteredUISourceCodeListProvider.js", "front_end/sources/FilteredUISourceCodeListProvider.js",
"front_end/sources/GoToLineQuickOpen.js",
"front_end/sources/InplaceFormatterEditorAction.js", "front_end/sources/InplaceFormatterEditorAction.js",
"front_end/sources/JavaScriptBreakpointsSidebarPane.js", "front_end/sources/JavaScriptBreakpointsSidebarPane.js",
"front_end/sources/JavaScriptCompiler.js", "front_end/sources/JavaScriptCompiler.js",
...@@ -534,7 +536,7 @@ all_devtools_files = [ ...@@ -534,7 +536,7 @@ all_devtools_files = [
"front_end/sources/navigatorView.css", "front_end/sources/navigatorView.css",
"front_end/sources/NavigatorView.js", "front_end/sources/NavigatorView.js",
"front_end/sources/ObjectEventListenersSidebarPane.js", "front_end/sources/ObjectEventListenersSidebarPane.js",
"front_end/sources/OpenResourceDialog.js", "front_end/sources/OpenFileQuickOpen.js",
"front_end/sources/revisionHistory.css", "front_end/sources/revisionHistory.css",
"front_end/sources/RevisionHistoryView.js", "front_end/sources/RevisionHistoryView.js",
"front_end/sources/ScopeChainSidebarPane.js", "front_end/sources/ScopeChainSidebarPane.js",
......
...@@ -11,8 +11,9 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -11,8 +11,9 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
/** /**
* @param {?QuickOpen.FilteredListWidget.Provider} provider * @param {?QuickOpen.FilteredListWidget.Provider} provider
* @param {!Array<string>=} promptHistory * @param {!Array<string>=} promptHistory
* @param {function(string)=} queryChangedCallback
*/ */
constructor(provider, promptHistory) { constructor(provider, promptHistory, queryChangedCallback) {
super(true); super(true);
this._promptHistory = promptHistory || []; this._promptHistory = promptHistory || [];
...@@ -46,7 +47,9 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -46,7 +47,9 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
this.setDefaultFocusedElement(this._promptElement); this.setDefaultFocusedElement(this._promptElement);
this._prefix = '';
this._provider = provider; this._provider = provider;
this._queryChangedCallback = queryChangedCallback;
} }
/** /**
...@@ -117,6 +120,13 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -117,6 +120,13 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
this._dialog.show(); this._dialog.show();
} }
/**
* @param {string} prefix
*/
setPrefix(prefix) {
this._prefix = prefix;
}
/** /**
* @param {?QuickOpen.FilteredListWidget.Provider} provider * @param {?QuickOpen.FilteredListWidget.Provider} provider
*/ */
...@@ -139,7 +149,6 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -139,7 +149,6 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
this._provider.attach(); this._provider.attach();
} }
this._itemsLoaded(this._provider); this._itemsLoaded(this._provider);
this._updateShowMatchingItems();
} }
/** /**
...@@ -149,6 +158,10 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -149,6 +158,10 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
return this._prompt.text().trim(); return this._prompt.text().trim();
} }
_cleanValue() {
return this._value().substring(this._prefix.length);
}
/** /**
* @override * @override
*/ */
...@@ -181,14 +194,14 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -181,14 +194,14 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
*/ */
_onEnter(event) { _onEnter(event) {
event.preventDefault(); event.preventDefault();
if (!this._provider || !this._provider.itemCount()) if (!this._provider)
return; return;
var selectedIndexInProvider = this._shouldShowMatchingItems() ? this._list.selectedItem() : null; var selectedIndexInProvider = this._provider.itemCount() ? this._list.selectedItem() : null;
// Detach dialog before allowing provider to override focus. // Detach dialog before allowing provider to override focus.
if (this._dialog) if (this._dialog)
this._dialog.hide(); this._dialog.hide();
this._selectItemWithQuery(selectedIndexInProvider, this._value()); this._selectItem(selectedIndexInProvider);
} }
/** /**
...@@ -216,7 +229,7 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -216,7 +229,7 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
var titleElement = itemElement.createChild('div', 'filtered-list-widget-title'); var titleElement = itemElement.createChild('div', 'filtered-list-widget-title');
var subtitleElement = itemElement.createChild('div', 'filtered-list-widget-subtitle'); var subtitleElement = itemElement.createChild('div', 'filtered-list-widget-subtitle');
subtitleElement.textContent = '\u200B'; subtitleElement.textContent = '\u200B';
this._provider.renderItem(item, this._value(), titleElement, subtitleElement); this._provider.renderItem(item, this._cleanValue(), titleElement, subtitleElement);
return itemElement; return itemElement;
} }
...@@ -265,7 +278,7 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -265,7 +278,7 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
// Detach dialog before allowing provider to override focus. // Detach dialog before allowing provider to override focus.
if (this._dialog) if (this._dialog)
this._dialog.hide(); this._dialog.hide();
this._selectItemWithQuery(item, this._value()); this._selectItem(item);
} }
/** /**
...@@ -273,9 +286,9 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -273,9 +286,9 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
*/ */
setQuery(query) { setQuery(query) {
this._prompt.setText(query); this._prompt.setText(query);
this._queryChanged();
this._prompt.autoCompleteSoon(true); this._prompt.autoCompleteSoon(true);
this._scheduleFilter(); this._scheduleFilter();
this._updateShowMatchingItems();
} }
_tabKeyPressed() { _tabKeyPressed() {
...@@ -309,15 +322,18 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -309,15 +322,18 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
} }
if (!this._provider) { if (!this._provider) {
this._bottomElementsContainer.classList.toggle('hidden', true);
this._itemsFilteredForTest(); this._itemsFilteredForTest();
return; return;
} }
this._bottomElementsContainer.classList.toggle('hidden', false);
this._progressBarElement.style.transform = 'scaleX(0)'; this._progressBarElement.style.transform = 'scaleX(0)';
this._progressBarElement.classList.remove('filtered-widget-progress-fade'); this._progressBarElement.classList.remove('filtered-widget-progress-fade');
this._progressBarElement.classList.remove('hidden'); this._progressBarElement.classList.remove('hidden');
var query = this._provider.rewriteQuery(this._value()); var query = this._provider.rewriteQuery(this._cleanValue());
this._query = query; this._query = query;
var filterRegex = query ? QuickOpen.FilteredListWidget.filterRegex(query) : null; var filterRegex = query ? QuickOpen.FilteredListWidget.filterRegex(query) : null;
...@@ -423,24 +439,19 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -423,24 +439,19 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
this._list.element.classList.toggle('hidden', !hasItems); this._list.element.classList.toggle('hidden', !hasItems);
this._notFoundElement.classList.toggle('hidden', hasItems); this._notFoundElement.classList.toggle('hidden', hasItems);
if (!hasItems) if (!hasItems)
this._notFoundElement.textContent = this._provider.notFoundText(); this._notFoundElement.textContent = this._provider.notFoundText(this._cleanValue());
}
/**
* @return {boolean}
*/
_shouldShowMatchingItems() {
return !!this._provider && this._provider.shouldShowMatchingItems(this._value());
} }
_onInput() { _onInput() {
this._updateShowMatchingItems(); this._queryChanged();
this._scheduleFilter(); this._scheduleFilter();
} }
_updateShowMatchingItems() { _queryChanged() {
var shouldShowMatchingItems = this._shouldShowMatchingItems(); if (this._queryChangedCallback)
this._bottomElementsContainer.classList.toggle('hidden', !shouldShowMatchingItems); this._queryChangedCallback(this._value());
if (this._provider)
this._provider.queryChanged(this._cleanValue());
} }
/** /**
...@@ -480,13 +491,12 @@ QuickOpen.FilteredListWidget = class extends UI.VBox { ...@@ -480,13 +491,12 @@ QuickOpen.FilteredListWidget = class extends UI.VBox {
/** /**
* @param {?number} itemIndex * @param {?number} itemIndex
* @param {string} promptValue
*/ */
_selectItemWithQuery(itemIndex, promptValue) { _selectItem(itemIndex) {
this._promptHistory.push(promptValue); this._promptHistory.push(this._value());
if (this._promptHistory.length > 100) if (this._promptHistory.length > 100)
this._promptHistory.shift(); this._promptHistory.shift();
this._provider.selectItem(itemIndex, promptValue); this._provider.selectItem(itemIndex, this._cleanValue());
} }
}; };
...@@ -505,14 +515,6 @@ QuickOpen.FilteredListWidget.Provider = class { ...@@ -505,14 +515,6 @@ QuickOpen.FilteredListWidget.Provider = class {
attach() { attach() {
} }
/**
* @param {string} query
* @return {boolean}
*/
shouldShowMatchingItems(query) {
return true;
}
/** /**
* @return {number} * @return {number}
*/ */
...@@ -573,9 +575,16 @@ QuickOpen.FilteredListWidget.Provider = class { ...@@ -573,9 +575,16 @@ QuickOpen.FilteredListWidget.Provider = class {
} }
/** /**
* @param {string} query
*/
queryChanged(query) {
}
/**
* @param {string} query
* @return {string} * @return {string}
*/ */
notFoundText() { notFoundText(query) {
return Common.UIString('No results found'); return Common.UIString('No results found');
} }
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
QuickOpen.QuickOpen = class {
constructor() {
this._prefix = null;
this._query = '';
/** @type {!Map<string, function():!Promise<!QuickOpen.FilteredListWidget.Provider>>} */
this._providers = new Map();
/** @type {!Array<string>} */
this._prefixes = [];
this._filteredListWidget = null;
self.runtime.extensions(QuickOpen.FilteredListWidget.Provider).forEach(this._addProvider.bind(this));
this._prefixes.sort((a, b) => b.length - a.length);
}
/**
* @param {string} query
*/
static show(query) {
var quickOpen = new this();
var filteredListWidget =
new QuickOpen.FilteredListWidget(null, this._history, quickOpen._queryChanged.bind(quickOpen));
quickOpen._filteredListWidget = filteredListWidget;
filteredListWidget.showAsDialog();
filteredListWidget.setQuery(query);
}
/**
* @param {!Runtime.Extension} extension
*/
_addProvider(extension) {
var prefix = extension.descriptor()['prefix'];
this._prefixes.push(prefix);
this._providers.set(
prefix, /** @type {function():!Promise<!QuickOpen.FilteredListWidget.Provider>} */
(extension.instance.bind(extension)));
}
/**
* @param {string} query
*/
_queryChanged(query) {
var prefix = this._prefixes.find(prefix => query.startsWith(prefix));
if (typeof prefix !== 'string' || this._prefix === prefix)
return;
this._prefix = prefix;
this._filteredListWidget.setPrefix(prefix);
this._filteredListWidget.setProvider(null);
this._providers.get(prefix)().then(provider => {
if (this._prefix !== prefix)
return;
this._filteredListWidget.setProvider(provider);
this._providerLoadedForTest(provider);
});
}
/**
* @param {!QuickOpen.FilteredListWidget.Provider} provider
*/
_providerLoadedForTest(provider) {
}
};
QuickOpen.QuickOpen._history = [];
/**
* @implements {UI.ActionDelegate}
*/
QuickOpen.QuickOpen.ShowActionDelegate = class {
/**
* @override
* @param {!UI.Context} context
* @param {string} actionId
* @return {boolean}
*/
handleAction(context, actionId) {
switch (actionId) {
case 'quickOpen.show':
QuickOpen.QuickOpen.show('');
return true;
}
return false;
}
};
...@@ -14,6 +14,23 @@ ...@@ -14,6 +14,23 @@
"shortcut": "Meta+Shift+P" "shortcut": "Meta+Shift+P"
} }
] ]
},
{
"type": "@UI.ActionDelegate",
"actionId": "quickOpen.show",
"title": "Go to file...",
"className": "QuickOpen.QuickOpen.ShowActionDelegate",
"order": 100,
"bindings": [
{
"platform": "mac",
"shortcut": "Meta+P Meta+O"
},
{
"platform": "windows,linux",
"shortcut": "Ctrl+P Ctrl+O"
}
]
} }
], ],
"dependencies": [ "dependencies": [
...@@ -22,6 +39,7 @@ ...@@ -22,6 +39,7 @@
], ],
"scripts": [ "scripts": [
"FilteredListWidget.js", "FilteredListWidget.js",
"QuickOpen.js",
"CommandMenu.js" "CommandMenu.js"
], ],
"resources": [ "resources": [
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
*/ */
Sources.FilteredUISourceCodeListProvider = class extends QuickOpen.FilteredListWidget.Provider { Sources.FilteredUISourceCodeListProvider = class extends QuickOpen.FilteredListWidget.Provider {
/** /**
* @param {!Map.<!Workspace.UISourceCode, number>=} defaultScores * @param {?Map.<!Workspace.UISourceCode, number>=} defaultScores
*/ */
constructor(defaultScores) { constructor(defaultScores) {
super(); super();
this._defaultScores = defaultScores; this._defaultScores = defaultScores || null;
this._scorer = new Sources.FilePathScoreFunction(''); this._scorer = new Sources.FilePathScoreFunction('');
} }
...@@ -86,6 +86,14 @@ Sources.FilteredUISourceCodeListProvider = class extends QuickOpen.FilteredListW ...@@ -86,6 +86,14 @@ Sources.FilteredUISourceCodeListProvider = class extends QuickOpen.FilteredListW
return this._uiSourceCodes[itemIndex].url(); return this._uiSourceCodes[itemIndex].url();
} }
/**
* @protected
* @param {?Map.<!Workspace.UISourceCode, number>} defaultScores
*/
setDefaultScores(defaultScores) {
this._defaultScores = defaultScores;
}
/** /**
* @override * @override
* @param {number} itemIndex * @param {number} itemIndex
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Sources.GoToLineQuickOpen = class extends QuickOpen.FilteredListWidget.Provider {
/**
* @override
* @param {?number} itemIndex
* @param {string} promptValue
*/
selectItem(itemIndex, promptValue) {
var uiSourceCode = this._currentUISourceCode();
if (!uiSourceCode)
return;
var position = this._parsePosition(promptValue);
if (!position)
return;
Common.Revealer.reveal(uiSourceCode.uiLocation(position.line - 1, position.column - 1));
}
/**
* @override
* @param {string} query
* @return {string}
*/
notFoundText(query) {
if (!this._currentUISourceCode())
return Common.UIString('No file selected.');
var position = this._parsePosition(query);
if (!position)
return Common.UIString('Type a number to go to that line.');
var text = Common.UIString('Go to line ') + position.line;
if (position.column && position.column > 1)
text += Common.UIString(' and column ') + position.column;
text += '.';
return text;
}
/**
* @param {string} query
* @return {?{line: number, column: number}}
*/
_parsePosition(query) {
var parts = query.match(/([0-9]+)(\:[0-9]*)?/);
if (!parts || !parts[0] || parts[0].length !== query.length)
return null;
var line = parseInt(parts[1], 10);
var column;
if (parts[2])
column = parseInt(parts[2].substring(1), 10);
return {line: Math.max(line | 0, 1), column: Math.max(column | 0, 1)};
}
/**
* @return {?Workspace.UISourceCode}
*/
_currentUISourceCode() {
var sourcesView = UI.context.flavor(Sources.SourcesView);
if (!sourcesView)
return null;
return sourcesView.currentUISourceCode();
}
};
...@@ -1176,7 +1176,7 @@ Sources.JavaScriptSourceFrame = class extends SourceFrame.UISourceCodeFrame { ...@@ -1176,7 +1176,7 @@ Sources.JavaScriptSourceFrame = class extends SourceFrame.UISourceCodeFrame {
'Associated files should be added to the file tree. You can debug these resolved source files as regular JavaScript files.')); 'Associated files should be added to the file tree. You can debug these resolved source files as regular JavaScript files.'));
sourceMapInfobar.createDetailsRowMessage(Common.UIString( sourceMapInfobar.createDetailsRowMessage(Common.UIString(
'Associated files are available via file tree or %s.', 'Associated files are available via file tree or %s.',
UI.shortcutRegistry.shortcutTitleForAction('sources.go-to-source'))); UI.shortcutRegistry.shortcutTitleForAction('quickOpen.show')));
this.attachInfobars([sourceMapInfobar]); this.attachInfobars([sourceMapInfobar]);
} }
} }
......
...@@ -4,32 +4,13 @@ ...@@ -4,32 +4,13 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
/** Sources.OpenFileQuickOpen = class extends Sources.FilteredUISourceCodeListProvider {
* @unrestricted
*/
Sources.OpenResourceDialog = class extends Sources.FilteredUISourceCodeListProvider {
/**
* @param {!Sources.SourcesView} sourcesView
* @param {!Map.<!Workspace.UISourceCode, number>} defaultScores
*/
constructor(sourcesView, defaultScores) {
super(defaultScores);
this._sourcesView = sourcesView;
}
/** /**
* @param {!Sources.SourcesView} sourcesView * @override
* @param {string} query
* @param {!Map.<!Workspace.UISourceCode, number>} defaultScores
* @param {!Array<string>} history
*/ */
static show(sourcesView, query, defaultScores, history) { attach() {
var dialog = new Sources.OpenResourceDialog(sourcesView, defaultScores); this.setDefaultScores(Sources.SourcesView.defaultUISourceCodeScores());
if (InspectorFrontendHost.isUnderTest()) super.attach();
Sources.OpenResourceDialog._instanceForTest = dialog;
var filteredItemSelectionDialog = new QuickOpen.FilteredListWidget(dialog, history);
filteredItemSelectionDialog.showAsDialog();
filteredItemSelectionDialog.setQuery(query);
} }
/** /**
...@@ -41,20 +22,9 @@ Sources.OpenResourceDialog = class extends Sources.FilteredUISourceCodeListProvi ...@@ -41,20 +22,9 @@ Sources.OpenResourceDialog = class extends Sources.FilteredUISourceCodeListProvi
uiSourceCodeSelected(uiSourceCode, lineNumber, columnNumber) { uiSourceCodeSelected(uiSourceCode, lineNumber, columnNumber) {
Host.userMetrics.actionTaken(Host.UserMetrics.Action.SelectFileFromFilePicker); Host.userMetrics.actionTaken(Host.UserMetrics.Action.SelectFileFromFilePicker);
if (!uiSourceCode)
uiSourceCode = this._sourcesView.currentUISourceCode();
if (!uiSourceCode) if (!uiSourceCode)
return; return;
this._sourcesView.showSourceLocation(uiSourceCode, lineNumber, columnNumber); Common.Revealer.reveal(uiSourceCode.uiLocation((lineNumber || 0), columnNumber));
}
/**
* @override
* @param {string} query
* @return {boolean}
*/
shouldShowMatchingItems(query) {
return !query.startsWith(':');
} }
/** /**
...@@ -75,10 +45,6 @@ Sources.OpenResourceDialog = class extends Sources.FilteredUISourceCodeListProvi ...@@ -75,10 +45,6 @@ Sources.OpenResourceDialog = class extends Sources.FilteredUISourceCodeListProvi
} }
}; };
/**
* @unrestricted
*/
Sources.SelectUISourceCodeForProjectTypesDialog = class extends Sources.FilteredUISourceCodeListProvider { Sources.SelectUISourceCodeForProjectTypesDialog = class extends Sources.FilteredUISourceCodeListProvider {
/** /**
* @param {!Array.<string>} types * @param {!Array.<string>} types
......
...@@ -998,10 +998,6 @@ Sources.SourcesPanel = class extends UI.Panel { ...@@ -998,10 +998,6 @@ Sources.SourcesPanel = class extends UI.Panel {
this.showUILocation(uiLocation); this.showUILocation(uiLocation);
} }
showGoToSourceDialog() {
this._sourcesView.showOpenResourceDialog();
}
_revealNavigatorSidebar() { _revealNavigatorSidebar() {
this._setAsCurrentPanel(); this._setAsCurrentPanel();
this.editorView.showBoth(true); this.editorView.showBoth(true);
...@@ -1225,9 +1221,6 @@ Sources.SourcesPanel.RevealingActionDelegate = class { ...@@ -1225,9 +1221,6 @@ Sources.SourcesPanel.RevealingActionDelegate = class {
case 'debugger.toggle-pause': case 'debugger.toggle-pause':
panel._togglePause(); panel._togglePause();
return true; return true;
case 'sources.go-to-source':
panel.showGoToSourceDialog();
return true;
} }
return false; return false;
} }
......
...@@ -94,6 +94,21 @@ Sources.SourcesView = class extends UI.VBox { ...@@ -94,6 +94,21 @@ Sources.SourcesView = class extends UI.VBox {
this.element.addEventListener('keydown', this._handleKeyDown.bind(this), false); this.element.addEventListener('keydown', this._handleKeyDown.bind(this), false);
} }
/**
* @return {!Map.<!Workspace.UISourceCode, number>}
*/
static defaultUISourceCodeScores() {
/** @type {!Map.<!Workspace.UISourceCode, number>} */
var defaultScores = new Map();
var sourcesView = UI.context.flavor(Sources.SourcesView);
if (sourcesView) {
var uiSourceCodes = sourcesView._editorContainer.historyUISourceCodes();
for (var i = 1; i < uiSourceCodes.length; ++i) // Skip current element
defaultScores.set(uiSourceCodes[i], uiSourceCodes.length - i);
}
return defaultScores;
}
/** /**
* @param {function(!Array.<!UI.KeyboardShortcut.Descriptor>, function(!Event=):boolean)} registerShortcutDelegate * @param {function(!Array.<!UI.KeyboardShortcut.Descriptor>, function(!Event=):boolean)} registerShortcutDelegate
*/ */
...@@ -115,7 +130,8 @@ Sources.SourcesView = class extends UI.VBox { ...@@ -115,7 +130,8 @@ Sources.SourcesView = class extends UI.VBox {
this, UI.ShortcutsScreen.SourcesPanelShortcuts.JumpToNextLocation, this._onJumpToNextLocation.bind(this)); this, UI.ShortcutsScreen.SourcesPanelShortcuts.JumpToNextLocation, this._onJumpToNextLocation.bind(this));
registerShortcut.call( registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.CloseEditorTab, this._onCloseEditorTab.bind(this)); this, UI.ShortcutsScreen.SourcesPanelShortcuts.CloseEditorTab, this._onCloseEditorTab.bind(this));
registerShortcut.call(this, UI.ShortcutsScreen.SourcesPanelShortcuts.GoToLine, this._showGoToLineDialog.bind(this)); registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.GoToLine, this._showGoToLineQuickOpen.bind(this));
registerShortcut.call( registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.GoToMember, this._showOutlineDialog.bind(this)); this, UI.ShortcutsScreen.SourcesPanelShortcuts.GoToMember, this._showOutlineDialog.bind(this));
registerShortcut.call( registerShortcut.call(
...@@ -603,27 +619,13 @@ Sources.SourcesView = class extends UI.VBox { ...@@ -603,27 +619,13 @@ Sources.SourcesView = class extends UI.VBox {
return true; return true;
} }
/**
* @param {string=} query
*/
showOpenResourceDialog(query) {
var uiSourceCodes = this._editorContainer.historyUISourceCodes();
/** @type {!Map.<!Workspace.UISourceCode, number>} */
var defaultScores = new Map();
for (var i = 1; i < uiSourceCodes.length; ++i) // Skip current element
defaultScores.set(uiSourceCodes[i], uiSourceCodes.length - i);
if (!this._openResourceDialogHistory)
this._openResourceDialogHistory = [];
Sources.OpenResourceDialog.show(this, query || '', defaultScores, this._openResourceDialogHistory);
}
/** /**
* @param {!Event=} event * @param {!Event=} event
* @return {boolean} * @return {boolean}
*/ */
_showGoToLineDialog(event) { _showGoToLineQuickOpen(event) {
if (this._editorContainer.currentFile()) if (this._editorContainer.currentFile())
this.showOpenResourceDialog(':'); QuickOpen.QuickOpen.show(':');
return true; return true;
} }
......
...@@ -214,6 +214,18 @@ ...@@ -214,6 +214,18 @@
} }
] ]
}, },
{
"type": "@QuickOpen.FilteredListWidget.Provider",
"title": "Open file",
"prefix": "",
"className": "Sources.OpenFileQuickOpen"
},
{
"type": "@QuickOpen.FilteredListWidget.Provider",
"title": "Go to line",
"prefix": ":",
"className": "Sources.GoToLineQuickOpen"
},
{ {
"type": "context-menu-item", "type": "context-menu-item",
"location": "mainMenu/navigate", "location": "mainMenu/navigate",
...@@ -222,7 +234,7 @@ ...@@ -222,7 +234,7 @@
{ {
"type": "context-menu-item", "type": "context-menu-item",
"location": "navigatorMenu/navigate", "location": "navigatorMenu/navigate",
"actionId": "sources.go-to-source" "actionId": "quickOpen.show"
}, },
{ {
"type": "@Common.Revealer", "type": "@Common.Revealer",
...@@ -336,23 +348,6 @@ ...@@ -336,23 +348,6 @@
"viewId": "navigator-snippets", "viewId": "navigator-snippets",
"className": "Sources.SnippetsNavigatorView" "className": "Sources.SnippetsNavigatorView"
}, },
{
"type": "@UI.ActionDelegate",
"actionId": "sources.go-to-source",
"title": "Go to file...",
"className": "Sources.SourcesPanel.RevealingActionDelegate",
"order": 100,
"bindings": [
{
"platform": "mac",
"shortcut": "Meta+P Meta+O"
},
{
"platform": "windows,linux",
"shortcut": "Ctrl+P Ctrl+O"
}
]
},
{ {
"type": "@UI.ActionDelegate", "type": "@UI.ActionDelegate",
"actionId": "sources.switch-file", "actionId": "sources.switch-file",
...@@ -628,6 +623,7 @@ ...@@ -628,6 +623,7 @@
"EventListenerBreakpointsSidebarPane.js", "EventListenerBreakpointsSidebarPane.js",
"FilePathScoreFunction.js", "FilePathScoreFunction.js",
"FilteredUISourceCodeListProvider.js", "FilteredUISourceCodeListProvider.js",
"GoToLineQuickOpen.js",
"SourceMapNamesResolver.js", "SourceMapNamesResolver.js",
"JavaScriptBreakpointsSidebarPane.js", "JavaScriptBreakpointsSidebarPane.js",
"JavaScriptOutlineDialog.js", "JavaScriptOutlineDialog.js",
...@@ -644,7 +640,7 @@ ...@@ -644,7 +640,7 @@
"ScriptFormatterEditorAction.js", "ScriptFormatterEditorAction.js",
"InplaceFormatterEditorAction.js", "InplaceFormatterEditorAction.js",
"ScriptFormatter.js", "ScriptFormatter.js",
"OpenResourceDialog.js", "OpenFileQuickOpen.js",
"SourcesView.js", "SourcesView.js",
"AdvancedSearchView.js", "AdvancedSearchView.js",
"FileBasedSearchResultsPane.js", "FileBasedSearchResultsPane.js",
......
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