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
.setShrinkableTabs(true);
41 this._tabbedPane
.element
.classList
.add("navigator-tabbed-pane");
42 this._tabbedPaneController
= new WebInspector
.ExtensibleTabbedPaneController(this._tabbedPane
, "navigator-view", this._navigatorViewCreated
.bind(this));
43 /** @type {!Map.<string, ?WebInspector.NavigatorView>} */
44 this._navigatorViews
= new Map();
47 WebInspector
.SourcesNavigator
.Events
= {
48 SourceSelected
: "SourceSelected",
49 SourceRenamed
: "SourceRenamed"
52 WebInspector
.SourcesNavigator
.prototype = {
55 * @param {!WebInspector.Widget} view
57 _navigatorViewCreated: function(id
, view
)
59 var navigatorView
= /** @type {!WebInspector.NavigatorView} */ (view
);
60 navigatorView
.addEventListener(WebInspector
.NavigatorView
.Events
.ItemSelected
, this._sourceSelected
, this);
61 navigatorView
.addEventListener(WebInspector
.NavigatorView
.Events
.ItemRenamed
, this._sourceRenamed
, this);
62 this._navigatorViews
.set(id
, navigatorView
);
63 navigatorView
.setWorkspace(this._workspace
);
67 * @return {!WebInspector.Widget}
71 return this._tabbedPane
;
75 * @param {!WebInspector.UISourceCode} uiSourceCode
77 revealUISourceCode: function(uiSourceCode
)
79 var ids
= this._tabbedPaneController
.viewIds();
81 for (var i
= 0; i
< ids
.length
; ++i
)
82 promises
.push(this._tabbedPaneController
.viewForId(ids
[i
]));
83 Promise
.all(promises
).then(filterNavigators
.bind(this));
86 * @param {!Array.<!Object>} objects
87 * @this {WebInspector.SourcesNavigator}
89 function filterNavigators(objects
)
91 for (var i
= 0; i
< objects
.length
; ++i
) {
92 var navigatorView
= /** @type {!WebInspector.NavigatorView} */ (objects
[i
]);
93 if (navigatorView
.accept(uiSourceCode
)) {
94 this._tabbedPane
.selectTab(ids
[i
]);
95 navigatorView
.revealUISourceCode(uiSourceCode
, true);
102 * @param {!WebInspector.Event} event
104 _sourceSelected: function(event
)
106 this.dispatchEventToListeners(WebInspector
.SourcesNavigator
.Events
.SourceSelected
, event
.data
);
110 * @param {!WebInspector.Event} event
112 _sourceRenamed: function(event
)
114 this.dispatchEventToListeners(WebInspector
.SourcesNavigator
.Events
.SourceRenamed
, event
.data
);
117 __proto__
: WebInspector
.Object
.prototype
122 * @extends {WebInspector.NavigatorView}
124 WebInspector
.SnippetsNavigatorView = function()
126 WebInspector
.NavigatorView
.call(this);
129 WebInspector
.SnippetsNavigatorView
.prototype = {
132 * @param {!WebInspector.UISourceCode} uiSourceCode
135 accept: function(uiSourceCode
)
137 if (!WebInspector
.NavigatorView
.prototype.accept(uiSourceCode
))
139 return uiSourceCode
.project().type() === WebInspector
.projectTypes
.Snippets
;
144 * @param {!Event} event
146 handleContextMenu: function(event
)
148 var contextMenu
= new WebInspector
.ContextMenu(event
);
149 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 var executionContext
= WebInspector
.context
.flavor(WebInspector
.ExecutionContext
);
175 if (uiSourceCode
.project().type() !== WebInspector
.projectTypes
.Snippets
|| !executionContext
)
177 WebInspector
.scriptSnippetModel
.evaluateScriptSnippet(executionContext
, uiSourceCode
);
181 * @param {!WebInspector.UISourceCode} uiSourceCode
183 _handleRemoveSnippet: function(uiSourceCode
)
185 if (uiSourceCode
.project().type() !== WebInspector
.projectTypes
.Snippets
)
187 uiSourceCode
.remove();
190 _handleCreateSnippet: function()
192 this.create(WebInspector
.scriptSnippetModel
.project(), "");
198 sourceDeleted: function(uiSourceCode
)
200 this._handleRemoveSnippet(uiSourceCode
);
203 __proto__
: WebInspector
.NavigatorView
.prototype