Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/ui/View.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/View.js b/third_party/WebKit/Source/devtools/front_end/ui/View.js |
| index 6e910f7bb55c043878ffd0a7108bc4ccd0c9f955..ae4c734439e8602bec5e6242f376d6b9018aecf5 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/View.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/View.js |
| @@ -42,6 +42,7 @@ WebInspector.View.prototype = { |
| } |
| WebInspector.View._symbol = Symbol("view"); |
| +WebInspector.View._widgetSymbol = Symbol("widget"); |
| /** |
| * @constructor |
| @@ -330,6 +331,16 @@ WebInspector.ViewManager.prototype = { |
| /** |
| * @param {string} viewId |
| + * @return {?WebInspector.Widget} |
| + */ |
| + materializedWidget: function(viewId) |
| + { |
| + var view = this.view(viewId); |
| + return view ? view[WebInspector.View._widgetSymbol] : null; |
| + }, |
| + |
| + /** |
| + * @param {string} viewId |
| * @return {!Promise} |
| */ |
| showView: function(viewId) |
| @@ -378,11 +389,12 @@ WebInspector.ViewManager.prototype = { |
| * @param {function()=} revealCallback |
| * @param {string=} location |
| * @param {boolean=} restoreSelection |
| + * @param {boolean=} allowReorder |
| * @return {!WebInspector.TabbedViewLocation} |
| */ |
| - createTabbedLocation: function(revealCallback, location, restoreSelection) |
| + createTabbedLocation: function(revealCallback, location, restoreSelection, allowReorder) |
| { |
| - return new WebInspector.ViewManager._TabbedLocation(this, revealCallback, location, restoreSelection); |
| + return new WebInspector.ViewManager._TabbedLocation(this, revealCallback, location, restoreSelection, allowReorder); |
| }, |
| /** |
| @@ -447,7 +459,10 @@ WebInspector.ViewManager._ContainerWidget.prototype = { |
| return this._materializePromise; |
| var promises = []; |
| promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._populateToolbar.bind(WebInspector.ViewManager, this.element))); |
| - promises.push(this._view.widget().then(widget => widget.show(this.element))); |
| + promises.push(this._view.widget().then(widget => { |
| + widget.show(this.element); |
| + this._view[WebInspector.View._widgetSymbol] = widget; |
|
dgozman
2016/10/12 04:47:40
Let's set symbol before showing widget.
pfeldman
2016/10/12 19:02:33
Done.
|
| + })); |
| this._materializePromise = Promise.all(promises); |
| return this._materializePromise; |
| }, |
| @@ -492,6 +507,7 @@ WebInspector.ViewManager._ExpandableContainerWidget.prototype = { |
| promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._populateToolbar.bind(WebInspector.ViewManager, this._titleElement))); |
| promises.push(this._view.widget().then(widget => { |
| this._widget = widget; |
| + this._view[WebInspector.View._widgetSymbol] = widget; |
| widget.show(this.element); |
| })); |
| this._materializePromise = Promise.all(promises); |
| @@ -576,15 +592,21 @@ WebInspector.ViewManager._Location.prototype = { |
| * @param {function()=} revealCallback |
| * @param {string=} location |
| * @param {boolean=} restoreSelection |
| + * @param {boolean=} allowReorder |
| */ |
| -WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, location, restoreSelection) |
| +WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, location, restoreSelection, allowReorder) |
| { |
| this._tabbedPane = new WebInspector.TabbedPane(); |
| + if (allowReorder) |
| + this._tabbedPane.setAllowTabReorder(true); |
| + this._allowReorder = allowReorder; |
| WebInspector.ViewManager._Location.call(this, manager, this._tabbedPane, revealCallback); |
| this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected, this._tabSelected, this); |
| this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed, this._tabClosed, this); |
| this._closeableTabSetting = WebInspector.settings.createSetting(location + "-closeableTabs", {}); |
| + this._tabOrderSetting = WebInspector.settings.createSetting(location + "-tabOrder", {}); |
| + this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabOrderChanged, this._persistTabOrder, this); |
| if (restoreSelection) |
| this._lastSelectedTabSetting = WebInspector.settings.createSetting(location + "-selectedTab", ""); |
| @@ -595,6 +617,8 @@ WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, loc |
| this.appendApplicableItems(location); |
| } |
| +WebInspector.ViewManager._TabbedLocation.orderStep = 10; // Keep in sync with descriptors. |
| + |
| WebInspector.ViewManager._TabbedLocation.prototype = { |
| /** |
| * @override |
| @@ -629,7 +653,17 @@ WebInspector.ViewManager._TabbedLocation.prototype = { |
| */ |
| appendApplicableItems: function(locationName) |
| { |
| - for (var view of this._manager._viewsForLocation(locationName)) { |
| + var views = this._manager._viewsForLocation(locationName); |
| + if (this._allowReorder) { |
| + var i = 0; |
| + var persistedOrders = this._tabOrderSetting.get(); |
| + var orders = new Map(); |
| + for (var view of views) |
| + orders.set(view.viewId(), persistedOrders[view.viewId()] || (++i) * 10); |
|
dgozman
2016/10/12 04:47:41
Either use constant defined above or remove it.
pfeldman
2016/10/12 19:02:33
Done.
|
| + views.sort((a, b) => orders.get(a.viewId()) - orders.get(b.viewId())); |
| + } |
| + |
| + for (var view of views) { |
| var id = view.viewId(); |
| this._views.set(id, view); |
| view[WebInspector.ViewManager._Location.symbol] = this; |
| @@ -664,10 +698,11 @@ WebInspector.ViewManager._TabbedLocation.prototype = { |
| /** |
| * @param {!WebInspector.View} view |
| + * @param {number=} index |
| */ |
| - _appendTab: function(view) |
| + _appendTab: function(view, index) |
| { |
| - this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector.ViewManager._ContainerWidget(view), undefined, false, view.isCloseable() || view.isTransient()); |
| + this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector.ViewManager._ContainerWidget(view), undefined, false, view.isCloseable() || view.isTransient(), index); |
| }, |
| /** |
| @@ -677,14 +712,32 @@ WebInspector.ViewManager._TabbedLocation.prototype = { |
| */ |
| appendView: function(view, insertBefore) |
| { |
| - if (insertBefore) |
| - throw new Error("Insert before in tabbed pane is not supported"); |
| - if (!this._tabbedPane.hasTab(view.viewId())) { |
| - view[WebInspector.ViewManager._Location.symbol] = this; |
| - this._manager._views.set(view.viewId(), view); |
| - this._views.set(view.viewId(), view); |
| - this._appendTab(view); |
| + if (this._tabbedPane.hasTab(view.viewId())) |
| + return; |
| + view[WebInspector.ViewManager._Location.symbol] = this; |
| + this._manager._views.set(view.viewId(), view); |
| + this._views.set(view.viewId(), view); |
| + |
| + var index = undefined; |
| + var tabIds = this._tabbedPane.tabIds(); |
| + if (this._allowReorder) { |
| + var orderSetting = this._tabOrderSetting.get(); |
| + var order = orderSetting[view.viewId()]; |
| + for (var i = 0; order && i < tabIds.length; ++i) { |
| + if (orderSetting[tabIds[i]] && orderSetting[tabIds[i]] > order) { |
| + index = i; |
| + break; |
| + } |
| + } |
| + } else if (insertBefore) { |
| + for (var i = 0; i < tabIds.length; ++i) { |
| + if (tabIds[i] === insertBefore.viewId()) { |
| + index = i; |
| + break; |
| + } |
| + } |
| } |
| + this._appendTab(view, index); |
| }, |
| /** |
| @@ -763,6 +816,20 @@ WebInspector.ViewManager._TabbedLocation.prototype = { |
| return widget._materialize(); |
| }, |
| + /** |
| + * @param {!WebInspector.Event} event |
| + */ |
| + _persistTabOrder: function(event) |
| + { |
| + var tabIds = this._tabbedPane.tabIds(); |
| + var tabOrders = {}; |
| + for (var i = 0; i < tabIds.length; i++) |
| + tabOrders[tabIds[i]] = (i + 1) * WebInspector.ViewManager._TabbedLocation.orderStep; |
| + if (Object.keys(tabOrders).length) |
|
dgozman
2016/10/12 04:47:41
Remove this debugging code.
pfeldman
2016/10/12 19:02:33
Done.
|
| + this._tabOrderSetting.set(tabOrders); |
| + else debugger; |
| + }, |
| + |
| __proto__: WebInspector.ViewManager._Location.prototype |
| } |