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

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

Issue 2679483002: DevTools: Create extensible QuickOpen control (Closed)
Patch Set: it is much smaller now 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 QuickOpen.QuickOpen = class {
6 /**
7 * @param {!QuickOpen.FilteredListWidget} filtedListWidget
8 */
9 constructor(filtedListWidget) {
10 this._prefix = null;
einbinder 2017/03/08 22:39:57 I could expose _prefix on the filteredListWidget,
11 this._query = '';
12 /** @type {!Map<string, function():!Promise<!QuickOpen.FilteredListWidget.Pr ovider>>} */
13 this._providers = new Map();
14 /** @type {!Array<string>} */
15 this._prefixes = [];
16 this._filteredListWidget = filtedListWidget;
17 self.runtime.extensions(QuickOpen.FilteredListWidget.Provider).forEach(this. _addProvider.bind(this));
18 }
19
20 /**
21 * @param {string} query
22 */
23 static show(query) {
24 var filteredListWidget = new QuickOpen.FilteredListWidget(null, this._histor y);
25 new this(filteredListWidget);
26 filteredListWidget.showAsDialog();
27 filteredListWidget.setQuery(query);
28 }
29
30 /**
31 * @param {!Runtime.Extension} extension
32 */
33 _addProvider(extension) {
34 var prefix = extension.descriptor()['prefix'];
35 this._prefixes.splice(this._prefixes.lowerBound((a, b) => b.length - a.lengt h), 0, prefix);
36 this._providers.set(
37 prefix, /** @type {function():!Promise<!QuickOpen.FilteredListWidget.Pro vider>} */
38 (extension.instance.bind(extension)));
39 }
40
41 /**
42 * @param {string} query
43 */
44 _queryChanged(query) {
45 var prefix = this._prefixes.find(prefix => query.startsWith(prefix));
46 if (typeof prefix !== 'string' || this._prefix === prefix)
47 return;
48
49 this._prefix = prefix;
50 this._filteredListWidget.setPrefix(prefix);
51 this._filteredListWidget.setProvider(null);
52 this._providers.get(prefix)().then(provider => {
53 if (this._prefix !== prefix)
54 return;
55 this._filteredListWidget.setProvider(provider);
56 this._providerLoadedForTest(provider);
57 });
58 }
59
60 /**
61 * @param {!QuickOpen.FilteredListWidget.Provider} provider
62 */
63 _providerLoadedForTest(provider) {
64 }
65 };
66
67 QuickOpen.QuickOpen._history = [];
68
69 /**
70 * @implements {UI.ActionDelegate}
71 */
72 QuickOpen.QuickOpen.ShowActionDelegate = class {
73 /**
74 * @override
75 * @param {!UI.Context} context
76 * @param {string} actionId
77 * @return {boolean}
78 */
79 handleAction(context, actionId) {
80 switch (actionId) {
81 case 'quickOpen.show':
82 QuickOpen.QuickOpen.show('');
83 return true;
84 }
85 return false;
86 }
87 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698