Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Unified Diff: third_party/WebKit/Source/devtools/front_end/quick_open/QuickOpen.js

Issue 2679483002: DevTools: Create extensible QuickOpen control (Closed)
Patch Set: format Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/quick_open/QuickOpen.js
diff --git a/third_party/WebKit/Source/devtools/front_end/quick_open/QuickOpen.js b/third_party/WebKit/Source/devtools/front_end/quick_open/QuickOpen.js
new file mode 100644
index 0000000000000000000000000000000000000000..65a76042fe4e2594b34b1c90a6981d2efa8b5a08
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/quick_open/QuickOpen.js
@@ -0,0 +1,86 @@
+// 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));
+ }
+
+ /**
+ * @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.splice(this._prefixes.lowerBound(prefix, (a, b) => b.length - a.length), 0, prefix);
pfeldman 2017/03/22 01:29:51 Sorting it afterwards the fact is actually cheaper
einbinder 2017/03/23 06:28:12 Done.
+ 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;
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698