OLD | NEW |
---|---|
(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 extends QuickOpen.FilteredListWidget.Delegate { | |
6 /** | |
7 * @param {!QuickOpen.FilteredListWidget} filtedListWidget | |
8 */ | |
9 constructor(filtedListWidget) { | |
10 super(); | |
11 /** @type {!Array<{ | |
12 * prefix: string, | |
13 * instance: function():!Promise<!QuickOpen.FilteredListWidget.Delegate>, | |
14 * delegate: ?QuickOpen.FilteredListWidget.Delegate | |
15 * }>} */ | |
16 this._descriptors = []; | |
17 self.runtime.extensions(QuickOpen.FilteredListWidget.Delegate).forEach(this. _addProvider.bind(this)); | |
18 this._delegate = this._loadingDelegate = new QuickOpen.QuickOpen.Loading(); | |
19 this._prefix = null; | |
pfeldman
2017/03/06 18:37:18
It is funny how you have this in both places - is
| |
20 this._query = ''; | |
21 this._disposed = false; | |
22 this._filteredListWidget = filtedListWidget; | |
23 this._filteredListWidget.on(QuickOpen.FilteredListWidget.QueryChangedEvent, this._queryChanged, this); | |
24 this._filteredListWidget.on(QuickOpen.FilteredListWidget.DisposeEvent, this. _dispose, this); | |
pfeldman
2017/03/06 18:37:18
Ah, so you kind-of have both, a lifetime-long dele
einbinder
2017/03/08 22:39:56
Removed dispose, queryChange is a callback.
| |
25 this._filteredListWidget.setDelegate(this._delegate); | |
26 } | |
27 | |
28 /** | |
29 * @param {string} query | |
30 */ | |
31 static show(query) { | |
32 var filteredListWidget = new QuickOpen.FilteredListWidget(null, this._histor y); | |
33 new this(filteredListWidget); | |
34 filteredListWidget.showAsDialog(); | |
35 filteredListWidget.setQuery(query); | |
36 } | |
37 | |
38 /** | |
39 * @param {!Runtime.Extension} extension | |
40 */ | |
41 _addProvider(extension) { | |
42 var descriptor = { | |
43 prefix: extension.descriptor().prefix, | |
pfeldman
2017/03/06 18:37:18
Everything not defined in the jsdoc should be acce
einbinder
2017/03/08 22:39:56
Done.
| |
44 delegate: null, | |
45 instance: extension.instance.bind(extension) | |
46 }; | |
47 var index = this._descriptors.lowerBound(descriptor, (a, b) => b.prefix.leng th - a.prefix.length); | |
48 this._descriptors.splice(index, 0, descriptor); | |
pfeldman
2017/03/06 18:37:18
How is it better than array of extension.descripto
einbinder
2017/03/08 22:39:56
Replaced with a map.
| |
49 } | |
50 | |
51 _updateProvider() { | |
52 var descriptor = this._descriptors.find(descriptor => this._query.startsWith (descriptor.prefix)); | |
53 if (!descriptor || this._prefix === descriptor.prefix) | |
54 return; | |
55 | |
56 this._prefix = descriptor.prefix; | |
57 this._filteredListWidget.setPrefix(this._prefix); | |
58 if (descriptor.delegate) { | |
pfeldman
2017/03/06 18:37:18
There is no reason to split promise and sync behav
einbinder
2017/03/08 22:39:57
Done.
| |
59 this._filteredListWidget.setDelegate(descriptor.delegate); | |
60 return; | |
61 } | |
62 descriptor.instance().then(instance => { | |
63 if (this._disposed) | |
64 instance.dispose(); | |
pfeldman
2017/03/06 18:37:18
return after?
einbinder
2017/03/08 22:39:57
n/a
| |
65 descriptor.delegate = instance; | |
66 if (this._prefix !== descriptor.prefix) | |
67 return; | |
68 this._filteredListWidget.setDelegate(instance); | |
69 this._delegateLoadedForTest(instance); | |
70 }); | |
71 this._filteredListWidget.setDelegate(this._loadingDelegate); | |
pfeldman
2017/03/06 18:37:18
This is going to be instantaneous in most of the c
einbinder
2017/03/08 22:39:56
For the cases where it is not instantaneous.
| |
72 } | |
73 | |
74 /** | |
75 * @param {!QuickOpen.FilteredListWidget.QueryChangedEvent} event | |
76 */ | |
77 _queryChanged(event) { | |
78 this._query = event.query; | |
79 this._updateProvider(); | |
80 } | |
81 | |
82 /** | |
83 * @param {!QuickOpen.FilteredListWidget.Delegate} delegate | |
84 */ | |
85 _delegateLoadedForTest(delegate) { | |
86 } | |
87 | |
88 _dispose() { | |
89 this._disposed = true; | |
90 this._filteredListWidget.off(QuickOpen.FilteredListWidget.QueryChangedEvent, this._queryChanged, this); | |
91 this._filteredListWidget.off(QuickOpen.FilteredListWidget.DisposeEvent, this ._dispose, this); | |
92 for (var descriptor of this._descriptors) { | |
93 if (descriptor.delegate) | |
94 descriptor.delegate.dispose(); | |
95 } | |
96 this._filteredListWidget.setDelegate(null); | |
97 } | |
98 }; | |
99 | |
100 QuickOpen.QuickOpen._history = []; | |
101 | |
102 /** | |
103 * @implements {UI.ActionDelegate} | |
104 */ | |
105 QuickOpen.QuickOpen.ShowActionDelegate = class { | |
106 /** | |
107 * @override | |
108 * @param {!UI.Context} context | |
109 * @param {string} actionId | |
110 * @return {boolean} | |
111 */ | |
112 handleAction(context, actionId) { | |
113 switch (actionId) { | |
114 case 'quickOpen.show': | |
115 QuickOpen.QuickOpen.show(''); | |
116 return true; | |
117 } | |
118 return false; | |
119 } | |
120 }; | |
121 | |
122 QuickOpen.QuickOpen.Loading = class extends QuickOpen.FilteredListWidget.Delegat e { | |
123 /** | |
124 * @override | |
125 */ | |
126 notFoundText() { | |
127 return Common.UIString('Loading...'); | |
128 } | |
129 }; | |
OLD | NEW |