mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 13:44:39 +08:00
Move and rename files. NOAUTOREVERT=true NOPRESUBMIT=true NOTREECHECKS=true Bug: 768828 TBR=darin@chromium.org NOTRY=true Change-Id: I66d3b155808bc5bdbf237b80208e1e552bcf7f28 Reviewed-on: https://chromium-review.googlesource.com/1001153 Reviewed-by: Blink Reformat <blink-reformat@chromium.org> Commit-Queue: Blink Reformat <blink-reformat@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#549061} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 0aee4434a4dba42a42abaea9bfbc0cd196a63bc1
89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
// 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) {
|
|
const quickOpen = new this();
|
|
const filteredListWidget =
|
|
new QuickOpen.FilteredListWidget(null, this._history, quickOpen._queryChanged.bind(quickOpen));
|
|
quickOpen._filteredListWidget = filteredListWidget;
|
|
filteredListWidget.setPlaceholder(Common.UIString('Type \'?\' to see available commands'));
|
|
filteredListWidget.showAsDialog();
|
|
filteredListWidget.setQuery(query);
|
|
}
|
|
|
|
/**
|
|
* @param {!Runtime.Extension} extension
|
|
*/
|
|
_addProvider(extension) {
|
|
const 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) {
|
|
const 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;
|
|
}
|
|
};
|