2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * @extends {WebInspector.View}
33 * @param {!WebInspector.SplitView} splitView
35 WebInspector.Drawer = function(splitView)
37 WebInspector.View.call(this);
38 this.element.id = "drawer-contents";
40 this._splitView = splitView;
41 splitView.hideDefaultResizer();
42 this.show(splitView.sidebarElement());
43 splitView.hideSidebar();
45 this._toggleDrawerButton = new WebInspector.StatusBarButton(WebInspector.UIString("Show drawer."), "console-status-bar-item");
46 this._toggleDrawerButton.addEventListener("click", this.toggle, this);
48 this._tabbedPane = new WebInspector.TabbedPane();
49 this._tabbedPane.closeableTabs = false;
50 this._tabbedPane.setRetainTabOrder(true, WebInspector.moduleManager.orderComparator(WebInspector.Drawer.ViewFactory, "name", "order"));
52 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
53 splitView.installResizer(this._tabbedPane.headerElement());
54 this._showDrawerOnLoadSetting = WebInspector.settings.createSetting("WebInspector.Drawer.showOnLoad", false);
55 this._lastSelectedViewSetting = WebInspector.settings.createSetting("WebInspector.Drawer.lastSelectedView", "console");
56 this._initializeViewFactories();
59 WebInspector.Drawer.prototype = {
60 _initializeViewFactories: function()
62 this._viewFactories = {};
63 var extensions = WebInspector.moduleManager.extensions(WebInspector.Drawer.ViewFactory);
65 for (var i = 0; i < extensions.length; ++i) {
66 var descriptor = extensions[i].descriptor();
67 var id = descriptor["name"];
68 var title = WebInspector.UIString(descriptor["title"]);
69 var settingName = descriptor["setting"];
70 var setting = settingName ? /** @type {!WebInspector.Setting|undefined} */ (WebInspector.settings[settingName]) : null;
72 this._viewFactories[id] = extensions[i];
75 setting.addChangeListener(this._toggleSettingBasedView.bind(this, id, title, setting));
77 this._tabbedPane.appendTab(id, title, new WebInspector.View());
79 this._tabbedPane.appendTab(id, title, new WebInspector.View());
82 this._tabbedPane.show(this.element);
87 * @param {string} title
88 * @param {!WebInspector.Setting} setting
90 _toggleSettingBasedView: function(id, title, setting)
92 this._tabbedPane.closeTab(id);
94 this._tabbedPane.appendTab(id, title, new WebInspector.View());
100 toggleButtonElement: function()
102 return this._toggleDrawerButton.element;
106 * @param {string} tabId
107 * @param {string} title
108 * @param {!WebInspector.View} view
110 _addView: function(tabId, title, view)
112 if (!this._tabbedPane.hasTab(tabId)) {
113 this._tabbedPane.appendTab(tabId, title, view, undefined, false);
115 this._tabbedPane.changeTabTitle(tabId, title);
116 this._tabbedPane.changeTabView(tabId, view);
123 closeView: function(id)
125 this._tabbedPane.closeTab(id);
130 * @param {boolean=} immediate
132 showView: function(id, immediate)
134 if (!this._toggleDrawerButton.enabled())
136 if (!this._tabbedPane.hasTab(id)) {
138 this._innerShow(immediate);
141 var viewFactory = this._viewFactory(id);
143 this._tabbedPane.changeTabView(id, viewFactory.createView());
144 this._innerShow(immediate);
145 this._tabbedPane.selectTab(id, true);
146 // In case this id is already selected, anyways persist it as the last saved value.
147 this._lastSelectedViewSetting.set(id);
152 * @param {string} title
153 * @param {!WebInspector.View} view
155 showCloseableView: function(id, title, view)
157 if (!this._toggleDrawerButton.enabled())
159 if (!this._tabbedPane.hasTab(id)) {
160 this._tabbedPane.appendTab(id, title, view, undefined, false, true);
162 this._tabbedPane.changeTabView(id, view);
163 this._tabbedPane.changeTabTitle(id, title);
166 this._tabbedPane.selectTab(id, true);
169 showDrawer: function()
171 this.showView(this._lastSelectedViewSetting.get());
174 showOnLoadIfNecessary: function()
176 if (this._showDrawerOnLoadSetting.get())
177 this.showView(this._lastSelectedViewSetting.get(), true);
181 * @param {boolean=} immediate
183 _innerShow: function(immediate)
185 if (this._toggleDrawerButton.toggled)
188 this._showDrawerOnLoadSetting.set(true);
189 this._toggleDrawerButton.toggled = true;
190 this._toggleDrawerButton.title = WebInspector.UIString("Hide drawer.");
192 this._splitView.showBoth(!immediate);
194 if (this._visibleView())
195 this._visibleView().focus();
198 closeDrawer: function()
200 if (!this._toggleDrawerButton.toggled)
202 this._showDrawerOnLoadSetting.set(false);
203 this._toggleDrawerButton.toggled = false;
204 this._toggleDrawerButton.title = WebInspector.UIString("Show console.");
206 WebInspector.restoreFocusFromElement(this.element);
207 this._splitView.hideSidebar(true);
211 * @return {!WebInspector.View} view
213 _visibleView: function()
215 return this._tabbedPane.visibleView;
219 * @param {!WebInspector.Event} event
221 _tabSelected: function(event)
223 var tabId = this._tabbedPane.selectedTabId;
224 if (event.data["isUserGesture"] && !this._tabbedPane.isTabCloseable(tabId))
225 this._lastSelectedViewSetting.set(tabId);
226 var viewFactory = this._viewFactory(tabId);
228 this._tabbedPane.changeTabView(tabId, viewFactory.createView());
233 if (this._toggleDrawerButton.toggled)
244 return this._toggleDrawerButton.toggled;
250 selectedViewId: function()
252 return this._tabbedPane.selectedTabId;
256 * @return {?WebInspector.Drawer.ViewFactory}
258 _viewFactory: function(id)
260 return this._viewFactories[id] ? /** @type {!WebInspector.Drawer.ViewFactory} */ (this._viewFactories[id].instance()) : null;
263 __proto__: WebInspector.View.prototype
269 WebInspector.Drawer.ViewFactory = function()
273 WebInspector.Drawer.ViewFactory.prototype = {
275 * @return {!WebInspector.View}
277 createView: function() {}
282 * @implements {WebInspector.Drawer.ViewFactory}
283 * @param {function(new:T)} constructor
286 WebInspector.Drawer.SingletonViewFactory = function(constructor)
288 this._constructor = constructor;
291 WebInspector.Drawer.SingletonViewFactory.prototype = {
293 * @return {!WebInspector.View}
295 createView: function()
298 this._instance = /** @type {!WebInspector.View} */(new this._constructor());
299 return this._instance;