1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var domutils_1 = require("@phosphor/domutils");
|
24 | var messaging_1 = require("@phosphor/messaging");
|
25 | var signaling_1 = require("@phosphor/signaling");
|
26 | var boxlayout_1 = require("./boxlayout");
|
27 | var stackedpanel_1 = require("./stackedpanel");
|
28 | var tabbar_1 = require("./tabbar");
|
29 | var widget_1 = require("./widget");
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | var TabPanel = (function (_super) {
|
42 | __extends(TabPanel, _super);
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 | function TabPanel(options) {
|
49 | if (options === void 0) { options = {}; }
|
50 | var _this = _super.call(this) || this;
|
51 | _this._currentChanged = new signaling_1.Signal(_this);
|
52 | _this.addClass('p-TabPanel');
|
53 |
|
54 | _this.tabBar = new tabbar_1.TabBar(options);
|
55 | _this.tabBar.addClass('p-TabPanel-tabBar');
|
56 | _this.stackedPanel = new stackedpanel_1.StackedPanel();
|
57 | _this.stackedPanel.addClass('p-TabPanel-stackedPanel');
|
58 |
|
59 | _this.tabBar.tabMoved.connect(_this._onTabMoved, _this);
|
60 | _this.tabBar.currentChanged.connect(_this._onCurrentChanged, _this);
|
61 | _this.tabBar.tabCloseRequested.connect(_this._onTabCloseRequested, _this);
|
62 | _this.tabBar.tabActivateRequested.connect(_this._onTabActivateRequested, _this);
|
63 |
|
64 | _this.stackedPanel.widgetRemoved.connect(_this._onWidgetRemoved, _this);
|
65 |
|
66 | _this._tabPlacement = options.tabPlacement || 'top';
|
67 | var direction = Private.directionFromPlacement(_this._tabPlacement);
|
68 | var orientation = Private.orientationFromPlacement(_this._tabPlacement);
|
69 |
|
70 | _this.tabBar.orientation = orientation;
|
71 | _this.tabBar.dataset['placement'] = _this._tabPlacement;
|
72 |
|
73 | var layout = new boxlayout_1.BoxLayout({ direction: direction, spacing: 0 });
|
74 |
|
75 | boxlayout_1.BoxLayout.setStretch(_this.tabBar, 0);
|
76 | boxlayout_1.BoxLayout.setStretch(_this.stackedPanel, 1);
|
77 |
|
78 | layout.addWidget(_this.tabBar);
|
79 | layout.addWidget(_this.stackedPanel);
|
80 |
|
81 | _this.layout = layout;
|
82 | return _this;
|
83 | }
|
84 | Object.defineProperty(TabPanel.prototype, "currentChanged", {
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | get: function () {
|
97 | return this._currentChanged;
|
98 | },
|
99 | enumerable: true,
|
100 | configurable: true
|
101 | });
|
102 | Object.defineProperty(TabPanel.prototype, "currentIndex", {
|
103 | |
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | get: function () {
|
110 | return this.tabBar.currentIndex;
|
111 | },
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | set: function (value) {
|
119 | this.tabBar.currentIndex = value;
|
120 | },
|
121 | enumerable: true,
|
122 | configurable: true
|
123 | });
|
124 | Object.defineProperty(TabPanel.prototype, "currentWidget", {
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | get: function () {
|
132 | var title = this.tabBar.currentTitle;
|
133 | return title ? title.owner : null;
|
134 | },
|
135 | |
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | set: function (value) {
|
142 | this.tabBar.currentTitle = value ? value.title : null;
|
143 | },
|
144 | enumerable: true,
|
145 | configurable: true
|
146 | });
|
147 | Object.defineProperty(TabPanel.prototype, "tabsMovable", {
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | get: function () {
|
155 | return this.tabBar.tabsMovable;
|
156 | },
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | set: function (value) {
|
164 | this.tabBar.tabsMovable = value;
|
165 | },
|
166 | enumerable: true,
|
167 | configurable: true
|
168 | });
|
169 | Object.defineProperty(TabPanel.prototype, "tabPlacement", {
|
170 | |
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | get: function () {
|
177 | return this._tabPlacement;
|
178 | },
|
179 | |
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | set: function (value) {
|
186 |
|
187 | if (this._tabPlacement === value) {
|
188 | return;
|
189 | }
|
190 |
|
191 | this._tabPlacement = value;
|
192 |
|
193 | var direction = Private.directionFromPlacement(value);
|
194 | var orientation = Private.orientationFromPlacement(value);
|
195 |
|
196 | this.tabBar.orientation = orientation;
|
197 | this.tabBar.dataset['placement'] = value;
|
198 |
|
199 | this.layout.direction = direction;
|
200 | },
|
201 | enumerable: true,
|
202 | configurable: true
|
203 | });
|
204 | Object.defineProperty(TabPanel.prototype, "widgets", {
|
205 | |
206 |
|
207 |
|
208 | get: function () {
|
209 | return this.stackedPanel.widgets;
|
210 | },
|
211 | enumerable: true,
|
212 | configurable: true
|
213 | });
|
214 | |
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | TabPanel.prototype.addWidget = function (widget) {
|
225 | this.insertWidget(this.widgets.length, widget);
|
226 | };
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | TabPanel.prototype.insertWidget = function (index, widget) {
|
240 | if (widget !== this.currentWidget) {
|
241 | widget.hide();
|
242 | }
|
243 | this.stackedPanel.insertWidget(index, widget);
|
244 | this.tabBar.insertTab(index, widget.title);
|
245 | };
|
246 | |
247 |
|
248 |
|
249 | TabPanel.prototype._onCurrentChanged = function (sender, args) {
|
250 |
|
251 | var previousIndex = args.previousIndex, previousTitle = args.previousTitle, currentIndex = args.currentIndex, currentTitle = args.currentTitle;
|
252 |
|
253 | var previousWidget = previousTitle ? previousTitle.owner : null;
|
254 | var currentWidget = currentTitle ? currentTitle.owner : null;
|
255 |
|
256 | if (previousWidget) {
|
257 | previousWidget.hide();
|
258 | }
|
259 |
|
260 | if (currentWidget) {
|
261 | currentWidget.show();
|
262 | }
|
263 |
|
264 | this._currentChanged.emit({
|
265 | previousIndex: previousIndex, previousWidget: previousWidget, currentIndex: currentIndex, currentWidget: currentWidget
|
266 | });
|
267 |
|
268 | if (domutils_1.Platform.IS_EDGE || domutils_1.Platform.IS_IE) {
|
269 | messaging_1.MessageLoop.flush();
|
270 | }
|
271 | };
|
272 | |
273 |
|
274 |
|
275 | TabPanel.prototype._onTabActivateRequested = function (sender, args) {
|
276 | args.title.owner.activate();
|
277 | };
|
278 | |
279 |
|
280 |
|
281 | TabPanel.prototype._onTabCloseRequested = function (sender, args) {
|
282 | args.title.owner.close();
|
283 | };
|
284 | |
285 |
|
286 |
|
287 | TabPanel.prototype._onTabMoved = function (sender, args) {
|
288 | this.stackedPanel.insertWidget(args.toIndex, args.title.owner);
|
289 | };
|
290 | |
291 |
|
292 |
|
293 | TabPanel.prototype._onWidgetRemoved = function (sender, widget) {
|
294 | this.tabBar.removeTab(widget.title);
|
295 | };
|
296 | return TabPanel;
|
297 | }(widget_1.Widget));
|
298 | exports.TabPanel = TabPanel;
|
299 |
|
300 |
|
301 |
|
302 | var Private;
|
303 | (function (Private) {
|
304 | |
305 |
|
306 |
|
307 | function orientationFromPlacement(plc) {
|
308 | return placementToOrientationMap[plc];
|
309 | }
|
310 | Private.orientationFromPlacement = orientationFromPlacement;
|
311 | |
312 |
|
313 |
|
314 | function directionFromPlacement(plc) {
|
315 | return placementToDirectionMap[plc];
|
316 | }
|
317 | Private.directionFromPlacement = directionFromPlacement;
|
318 | |
319 |
|
320 |
|
321 | var placementToOrientationMap = {
|
322 | 'top': 'horizontal',
|
323 | 'left': 'vertical',
|
324 | 'right': 'vertical',
|
325 | 'bottom': 'horizontal'
|
326 | };
|
327 | |
328 |
|
329 |
|
330 | var placementToDirectionMap = {
|
331 | 'top': 'top-to-bottom',
|
332 | 'left': 'left-to-right',
|
333 | 'right': 'right-to-left',
|
334 | 'bottom': 'bottom-to-top'
|
335 | };
|
336 | })(Private || (Private = {}));
|