OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * | |
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 | |
14 * distribution. | |
15 * | |
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. | |
27 */ | |
28 | |
29 /** | |
30 * @extends {WebInspector.Object} | |
31 * @constructor | |
32 */ | |
33 WebInspector.ScriptsNavigator = function() | |
34 { | |
35 WebInspector.Object.call(this); | |
36 | |
37 this._tabbedPane = new WebInspector.TabbedPane(); | |
38 this._tabbedPane.shrinkableTabs = true; | |
39 this._tabbedPane.element.addStyleClass("navigator-tabbed-pane"); | |
40 | |
41 this._scriptsView = new WebInspector.NavigatorView(); | |
42 this._scriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemSel
ected, this._scriptSelected, this); | |
43 this._scriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemSea
rchStarted, this._itemSearchStarted, this); | |
44 this._scriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemRen
amingRequested, this._itemRenamingRequested, this); | |
45 this._scriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemCre
ationRequested, this._itemCreationRequested, this); | |
46 | |
47 this._contentScriptsView = new WebInspector.NavigatorView(); | |
48 this._contentScriptsView.addEventListener(WebInspector.NavigatorView.Events.
ItemSelected, this._scriptSelected, this); | |
49 this._contentScriptsView.addEventListener(WebInspector.NavigatorView.Events.
ItemSearchStarted, this._itemSearchStarted, this); | |
50 this._contentScriptsView.addEventListener(WebInspector.NavigatorView.Events.
ItemRenamingRequested, this._itemRenamingRequested, this); | |
51 this._contentScriptsView.addEventListener(WebInspector.NavigatorView.Events.
ItemCreationRequested, this._itemCreationRequested, this); | |
52 | |
53 this._snippetsView = new WebInspector.SnippetsNavigatorView(); | |
54 this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.ItemSe
lected, this._scriptSelected, this); | |
55 this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.ItemSe
archStarted, this._itemSearchStarted, this); | |
56 this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.ItemRe
namingRequested, this._itemRenamingRequested, this); | |
57 this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.ItemCr
eationRequested, this._itemCreationRequested, this); | |
58 | |
59 this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.ScriptsTab, WebInsp
ector.UIString("Sources"), this._scriptsView); | |
60 this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ScriptsTab); | |
61 this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.ContentScriptsTab,
WebInspector.UIString("Content scripts"), this._contentScriptsView); | |
62 this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.SnippetsTab, WebIns
pector.UIString("Snippets"), this._snippetsView); | |
63 } | |
64 | |
65 WebInspector.ScriptsNavigator.Events = { | |
66 ScriptSelected: "ScriptSelected", | |
67 ItemCreationRequested: "ItemCreationRequested", | |
68 ItemRenamingRequested: "ItemRenamingRequested", | |
69 ItemSearchStarted: "ItemSearchStarted", | |
70 } | |
71 | |
72 WebInspector.ScriptsNavigator.ScriptsTab = "scripts"; | |
73 WebInspector.ScriptsNavigator.ContentScriptsTab = "contentScripts"; | |
74 WebInspector.ScriptsNavigator.SnippetsTab = "snippets"; | |
75 | |
76 WebInspector.ScriptsNavigator.prototype = { | |
77 /* | |
78 * @return {WebInspector.View} | |
79 */ | |
80 get view() | |
81 { | |
82 return this._tabbedPane; | |
83 }, | |
84 | |
85 /** | |
86 * @param {WebInspector.UISourceCode} uiSourceCode | |
87 */ | |
88 _navigatorViewForUISourceCode: function(uiSourceCode) | |
89 { | |
90 if (uiSourceCode.isContentScript) | |
91 return this._contentScriptsView; | |
92 else if (uiSourceCode.project().type() === WebInspector.projectTypes.Sni
ppets) | |
93 return this._snippetsView; | |
94 else | |
95 return this._scriptsView; | |
96 }, | |
97 | |
98 /** | |
99 * @param {WebInspector.UISourceCode} uiSourceCode | |
100 */ | |
101 addUISourceCode: function(uiSourceCode) | |
102 { | |
103 this._navigatorViewForUISourceCode(uiSourceCode).addUISourceCode(uiSourc
eCode); | |
104 }, | |
105 | |
106 /** | |
107 * @param {WebInspector.UISourceCode} uiSourceCode | |
108 */ | |
109 removeUISourceCode: function(uiSourceCode) | |
110 { | |
111 this._navigatorViewForUISourceCode(uiSourceCode).removeUISourceCode(uiSo
urceCode); | |
112 }, | |
113 | |
114 /** | |
115 * @param {WebInspector.UISourceCode} uiSourceCode | |
116 * @param {boolean=} select | |
117 */ | |
118 revealUISourceCode: function(uiSourceCode, select) | |
119 { | |
120 this._navigatorViewForUISourceCode(uiSourceCode).revealUISourceCode(uiSo
urceCode, select); | |
121 if (uiSourceCode.isContentScript) | |
122 this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ContentScri
ptsTab); | |
123 else if (uiSourceCode.project().type() !== WebInspector.projectTypes.Sni
ppets) | |
124 this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ScriptsTab)
; | |
125 }, | |
126 | |
127 /** | |
128 * @param {WebInspector.UISourceCode} uiSourceCode | |
129 * @param {function(boolean)=} callback | |
130 */ | |
131 rename: function(uiSourceCode, callback) | |
132 { | |
133 this._navigatorViewForUISourceCode(uiSourceCode).rename(uiSourceCode, ca
llback); | |
134 }, | |
135 | |
136 /** | |
137 * @param {WebInspector.Event} event | |
138 */ | |
139 _scriptSelected: function(event) | |
140 { | |
141 this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.Scrip
tSelected, event.data); | |
142 }, | |
143 | |
144 /** | |
145 * @param {WebInspector.Event} event | |
146 */ | |
147 _itemSearchStarted: function(event) | |
148 { | |
149 this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemS
earchStarted, event.data); | |
150 }, | |
151 | |
152 /** | |
153 * @param {WebInspector.Event} event | |
154 */ | |
155 _itemRenamingRequested: function(event) | |
156 { | |
157 this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemR
enamingRequested, event.data); | |
158 }, | |
159 | |
160 /** | |
161 * @param {WebInspector.Event} event | |
162 */ | |
163 _itemCreationRequested: function(event) | |
164 { | |
165 this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemC
reationRequested, event.data); | |
166 }, | |
167 | |
168 __proto__: WebInspector.Object.prototype | |
169 } | |
170 | |
171 /** | |
172 * @constructor | |
173 * @extends {WebInspector.NavigatorView} | |
174 */ | |
175 WebInspector.SnippetsNavigatorView = function() | |
176 { | |
177 WebInspector.NavigatorView.call(this); | |
178 } | |
179 | |
180 WebInspector.SnippetsNavigatorView.prototype = { | |
181 /** | |
182 * @param {Event} event | |
183 */ | |
184 handleContextMenu: function(event) | |
185 { | |
186 var contextMenu = new WebInspector.ContextMenu(event); | |
187 contextMenu.appendItem(WebInspector.UIString("New"), this._handleCreateS
nippet.bind(this)); | |
188 contextMenu.show(); | |
189 }, | |
190 | |
191 /** | |
192 * @param {Event} event | |
193 * @param {WebInspector.UISourceCode} uiSourceCode | |
194 */ | |
195 handleFileContextMenu: function(event, uiSourceCode) | |
196 { | |
197 var contextMenu = new WebInspector.ContextMenu(event); | |
198 contextMenu.appendItem(WebInspector.UIString("Run"), this._handleEvaluat
eSnippet.bind(this, uiSourceCode)); | |
199 contextMenu.appendItem(WebInspector.UIString("Rename"), this.requestRena
me.bind(this, uiSourceCode)); | |
200 contextMenu.appendItem(WebInspector.UIString("Remove"), this._handleRemo
veSnippet.bind(this, uiSourceCode)); | |
201 contextMenu.appendSeparator(); | |
202 contextMenu.appendItem(WebInspector.UIString("New"), this._handleCreateS
nippet.bind(this)); | |
203 contextMenu.show(); | |
204 }, | |
205 | |
206 /** | |
207 * @param {WebInspector.UISourceCode} uiSourceCode | |
208 */ | |
209 _handleEvaluateSnippet: function(uiSourceCode) | |
210 { | |
211 if (uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets
) | |
212 return; | |
213 WebInspector.scriptSnippetModel.evaluateScriptSnippet(uiSourceCode); | |
214 }, | |
215 | |
216 /** | |
217 * @param {WebInspector.UISourceCode} uiSourceCode | |
218 */ | |
219 _handleRemoveSnippet: function(uiSourceCode) | |
220 { | |
221 if (uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets
) | |
222 return; | |
223 uiSourceCode.project().deleteFile(uiSourceCode); | |
224 }, | |
225 | |
226 _handleCreateSnippet: function() | |
227 { | |
228 var data = {}; | |
229 data.project = WebInspector.scriptSnippetModel.project(); | |
230 data.path = ""; | |
231 this.dispatchEventToListeners(WebInspector.NavigatorView.Events.ItemCrea
tionRequested, data); | |
232 }, | |
233 | |
234 __proto__: WebInspector.NavigatorView.prototype | |
235 } | |
OLD | NEW |