2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @extends {WebInspector.Object}
32 * @param {!WebInspector.Workspace} workspace
34 WebInspector.SourcesNavigator = function(workspace)
36 WebInspector.Object.call(this);
37 this._workspace = workspace;
39 this._tabbedPane = new WebInspector.TabbedPane();
40 this._tabbedPane.shrinkableTabs = true;
41 this._tabbedPane.element.classList.add("navigator-tabbed-pane");
42 new WebInspector.ExtensibleTabbedPaneController(this._tabbedPane, "navigator-view", this._navigatorViewCreated.bind(this));
43 /** @type {!StringMap.<?WebInspector.NavigatorView>} */
44 this._navigatorViews = new StringMap();
47 WebInspector.SourcesNavigator.Events = {
48 SourceSelected: "SourceSelected",
49 SourceRenamed: "SourceRenamed"
52 WebInspector.SourcesNavigator.prototype = {
54 * @param {!WebInspector.View} view
56 _navigatorViewCreated: function(id, view)
58 var navigatorView = /** @type {!WebInspector.NavigatorView} */ (view);
59 navigatorView.addEventListener(WebInspector.NavigatorView.Events.ItemSelected, this._sourceSelected, this);
60 navigatorView.addEventListener(WebInspector.NavigatorView.Events.ItemRenamed, this._sourceRenamed, this);
61 this._navigatorViews.put(id, navigatorView);
62 navigatorView.setWorkspace(this._workspace);
66 * @return {!WebInspector.View}
70 return this._tabbedPane;
74 * @param {!WebInspector.UISourceCode} uiSourceCode
75 * @return {string|null}
77 _navigatorViewIdForUISourceCode: function(uiSourceCode)
79 var ids = this._navigatorViews.keys();
80 for (var i = 0; i < ids.length; ++i) {
82 var navigatorView = this._navigatorViews.get(id);
83 if (navigatorView.accept(uiSourceCode))
90 * @param {!WebInspector.UISourceCode} uiSourceCode
92 revealUISourceCode: function(uiSourceCode)
94 var id = this._navigatorViewIdForUISourceCode(uiSourceCode);
97 var navigatorView = this._navigatorViews.get(id);
98 console.assert(navigatorView);
99 navigatorView.revealUISourceCode(uiSourceCode, true);
100 this._tabbedPane.selectTab(id);
104 * @param {!WebInspector.Event} event
106 _sourceSelected: function(event)
108 this.dispatchEventToListeners(WebInspector.SourcesNavigator.Events.SourceSelected, event.data);
112 * @param {!WebInspector.Event} event
114 _sourceRenamed: function(event)
116 this.dispatchEventToListeners(WebInspector.SourcesNavigator.Events.SourceRenamed, event.data);
119 __proto__: WebInspector.Object.prototype
124 * @extends {WebInspector.NavigatorView}
126 WebInspector.SnippetsNavigatorView = function()
128 WebInspector.NavigatorView.call(this);
131 WebInspector.SnippetsNavigatorView.prototype = {
134 * @param {!WebInspector.UISourceCode} uiSourceCode
137 accept: function(uiSourceCode)
139 if (!WebInspector.NavigatorView.prototype.accept(uiSourceCode))
141 return uiSourceCode.project().type() === WebInspector.projectTypes.Snippets;
145 * @param {!Event} event
147 handleContextMenu: function(event)
149 var contextMenu = new WebInspector.ContextMenu(event);
150 contextMenu.appendItem(WebInspector.UIString("New"), this._handleCreateSnippet.bind(this));
155 * @param {!Event} event
156 * @param {!WebInspector.UISourceCode} uiSourceCode
158 handleFileContextMenu: function(event, uiSourceCode)
160 var contextMenu = new WebInspector.ContextMenu(event);
161 contextMenu.appendItem(WebInspector.UIString("Run"), this._handleEvaluateSnippet.bind(this, uiSourceCode));
162 contextMenu.appendItem(WebInspector.UIString("Rename"), this.rename.bind(this, uiSourceCode));
163 contextMenu.appendItem(WebInspector.UIString("Remove"), this._handleRemoveSnippet.bind(this, uiSourceCode));
164 contextMenu.appendSeparator();
165 contextMenu.appendItem(WebInspector.UIString("New"), this._handleCreateSnippet.bind(this));
170 * @param {!WebInspector.UISourceCode} uiSourceCode
172 _handleEvaluateSnippet: function(uiSourceCode)
174 if (uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets)
176 WebInspector.scriptSnippetModel.evaluateScriptSnippet(uiSourceCode);
180 * @param {!WebInspector.UISourceCode} uiSourceCode
182 _handleRemoveSnippet: function(uiSourceCode)
184 if (uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets)
186 uiSourceCode.remove();
189 _handleCreateSnippet: function()
191 this.create(WebInspector.scriptSnippetModel.project(), "")
197 sourceDeleted: function(uiSourceCode)
199 this._handleRemoveSnippet(uiSourceCode);
202 __proto__: WebInspector.NavigatorView.prototype