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.VBox}
33 * @param {!WebInspector.SplitView} splitView
35 WebInspector.Drawer = function(splitView)
37 WebInspector.VBox.call(this);
38 this.element.id = "drawer-contents";
40 this._splitView = splitView;
41 splitView.hideDefaultResizer();
42 this.show(splitView.sidebarElement());
44 this._drawerEditorSplitView = new WebInspector.SplitView(true, true, "editorInDrawerSplitViewState", 0.5, 0.5);
45 this._drawerEditorSplitView.hideSidebar();
46 this._drawerEditorSplitView.addEventListener(WebInspector.SplitView.Events.ShowModeChanged, this._drawerEditorSplitViewShowModeChanged, this);
47 this._drawerEditorShownSetting = WebInspector.settings.createSetting("drawerEditorShown", true);
48 this._drawerEditorSplitView.show(this.element);
50 this._toggleDrawerButton = new WebInspector.StatusBarButton(WebInspector.UIString("Show drawer."), "console-status-bar-item");
51 this._toggleDrawerButton.addEventListener("click", this.toggle, this);
53 this._tabbedPane = new WebInspector.TabbedPane();
54 this._tabbedPane.element.id = "drawer-tabbed-pane";
55 this._tabbedPane.closeableTabs = false;
56 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
57 new WebInspector.ExtensibleTabbedPaneController(this._tabbedPane, "drawer-view");
59 this._toggleDrawerEditorButton = this._drawerEditorSplitView.createShowHideSidebarButton("editor in drawer", "drawer-editor-show-hide-button");
60 this._tabbedPane.element.appendChild(this._toggleDrawerEditorButton.element);
61 if (!WebInspector.experimentsSettings.showEditorInDrawer.isEnabled())
62 this.setDrawerEditorAvailable(false);
64 splitView.installResizer(this._tabbedPane.headerElement());
65 this._lastSelectedViewSetting = WebInspector.settings.createSetting("WebInspector.Drawer.lastSelectedView", "console");
66 this._tabbedPane.show(this._drawerEditorSplitView.mainElement());
69 WebInspector.Drawer.prototype = {
73 toggleButtonElement: function()
75 return this._toggleDrawerButton.element;
81 closeView: function(id)
83 this._tabbedPane.closeTab(id);
88 * @param {boolean=} immediate
90 showView: function(id, immediate)
92 if (!this._tabbedPane.hasTab(id)) {
94 this._innerShow(immediate);
97 this._innerShow(immediate);
98 this._tabbedPane.selectTab(id, true);
99 // In case this id is already selected, anyways persist it as the last saved value.
100 this._lastSelectedViewSetting.set(id);
105 * @param {string} title
106 * @param {!WebInspector.View} view
108 showCloseableView: function(id, title, view)
110 if (!this._tabbedPane.hasTab(id)) {
111 this._tabbedPane.appendTab(id, title, view, undefined, false, true);
113 this._tabbedPane.changeTabView(id, view);
114 this._tabbedPane.changeTabTitle(id, title);
117 this._tabbedPane.selectTab(id, true);
120 showDrawer: function()
122 this.showView(this._lastSelectedViewSetting.get());
127 this.showView(this._lastSelectedViewSetting.get());
128 this._toggleDrawerButton.toggled = true;
129 this._toggleDrawerButton.title = WebInspector.UIString("Hide drawer.");
130 this._ensureDrawerEditorExistsIfNeeded();
135 this._toggleDrawerButton.toggled = false;
136 this._toggleDrawerButton.title = WebInspector.UIString("Show drawer.");
140 * @param {boolean=} immediate
142 _innerShow: function(immediate)
144 if (this.isShowing())
147 this._splitView.showBoth(!immediate);
149 if (this._visibleView())
150 this._visibleView().focus();
153 closeDrawer: function()
155 if (!this.isShowing())
158 WebInspector.restoreFocusFromElement(this.element);
159 this._splitView.hideSidebar(true);
163 * @return {!WebInspector.View} view
165 _visibleView: function()
167 return this._tabbedPane.visibleView;
171 * @param {!WebInspector.Event} event
173 _tabSelected: function(event)
175 var tabId = this._tabbedPane.selectedTabId;
176 if (event.data["isUserGesture"] && !this._tabbedPane.isTabCloseable(tabId))
177 this._lastSelectedViewSetting.set(tabId);
182 if (this._toggleDrawerButton.toggled)
193 return this._toggleDrawerButton.toggled;
199 selectedViewId: function()
201 return this._tabbedPane.selectedTabId;
205 * @param {!WebInspector.Event} event
207 _drawerEditorSplitViewShowModeChanged: function(event)
209 var mode = /** @type {string} */ (event.data);
210 var shown = mode === WebInspector.SplitView.ShowMode.Both;
212 if (this._isHidingDrawerEditor)
215 this._drawerEditorShownSetting.set(shown);
220 this._ensureDrawerEditor();
221 this._drawerEditor.view().show(this._drawerEditorSplitView.sidebarElement());
224 initialPanelShown: function()
226 this._initialPanelWasShown = true;
227 this._ensureDrawerEditorExistsIfNeeded();
230 _ensureDrawerEditorExistsIfNeeded: function()
232 if (!this._initialPanelWasShown || !this.isShowing() || !this._drawerEditorShownSetting.get() || !WebInspector.experimentsSettings.showEditorInDrawer.isEnabled())
234 this._ensureDrawerEditor();
237 _ensureDrawerEditor: function()
239 if (this._drawerEditor)
241 this._drawerEditor = WebInspector.moduleManager.instance(WebInspector.DrawerEditor);
242 this._drawerEditor.installedIntoDrawer();
246 * @param {boolean} available
248 setDrawerEditorAvailable: function(available)
250 if (!WebInspector.experimentsSettings.showEditorInDrawer.isEnabled())
252 this._toggleDrawerEditorButton.element.classList.toggle("hidden", !available);
255 showDrawerEditor: function()
257 if (!WebInspector.experimentsSettings.showEditorInDrawer.isEnabled())
260 this._splitView.showBoth();
261 this._drawerEditorSplitView.showBoth();
264 hideDrawerEditor: function()
266 this._isHidingDrawerEditor = true;
267 this._drawerEditorSplitView.hideSidebar();
268 this._isHidingDrawerEditor = false;
274 isDrawerEditorShown: function()
276 return this._drawerEditorShownSetting.get();
279 __proto__: WebInspector.VBox.prototype
285 WebInspector.Drawer.ViewFactory = function()
289 WebInspector.Drawer.ViewFactory.prototype = {
291 * @return {!WebInspector.View}
293 createView: function() {}
298 * @implements {WebInspector.Drawer.ViewFactory}
299 * @param {function(new:T)} constructor
302 WebInspector.Drawer.SingletonViewFactory = function(constructor)
304 this._constructor = constructor;
307 WebInspector.Drawer.SingletonViewFactory.prototype = {
309 * @return {!WebInspector.View}
311 createView: function()
314 this._instance = /** @type {!WebInspector.View} */(new this._constructor());
315 return this._instance;
322 WebInspector.DrawerEditor = function()
326 WebInspector.DrawerEditor.prototype = {
328 * @return {!WebInspector.View}
330 view: function() { },
332 installedIntoDrawer: function() { },