OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @implements {WebInspector.SourceMapping} | 7 * @implements {WebInspector.SourceMapping} |
8 * @param {!WebInspector.Workspace} workspace | 8 * @param {!WebInspector.Target} target |
9 * @param {!WebInspector.DebuggerModel} debuggerModel | 9 * @param {!WebInspector.ScriptFormatterEditorAction} editorAction |
10 */ | 10 */ |
11 WebInspector.FormatterScriptMapping = function(workspace, debuggerModel) | 11 WebInspector.FormatterScriptMapping = function(target, editorAction) |
12 { | 12 { |
13 this._workspace = workspace; | 13 this._target = target; |
14 this._debuggerModel = debuggerModel; | 14 this._editorAction = editorAction; |
15 | |
16 this._init(); | |
17 | |
18 this._projectId = "formatter:"; | |
19 this._projectDelegate = new WebInspector.FormatterProjectDelegate(workspace,
this._projectId); | |
20 this._debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.Globa
lObjectCleared, this._debuggerReset, this); | |
21 } | 15 } |
22 | 16 |
23 WebInspector.FormatterScriptMapping.prototype = { | 17 WebInspector.FormatterScriptMapping.prototype = { |
24 /** | 18 /** |
25 * @param {!WebInspector.RawLocation} rawLocation | 19 * @param {!WebInspector.RawLocation} rawLocation |
26 * @return {?WebInspector.UILocation} | 20 * @return {?WebInspector.UILocation} |
27 */ | 21 */ |
28 rawLocationToUILocation: function(rawLocation) | 22 rawLocationToUILocation: function(rawLocation) |
29 { | 23 { |
30 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat
ion} */ (rawLocation); | 24 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat
ion} */ (rawLocation); |
31 var script = debuggerModelLocation.script(); | 25 var script = debuggerModelLocation.script(); |
32 var uiSourceCode = this._uiSourceCodes.get(script); | 26 var uiSourceCode = this._editorAction._uiSourceCodes.get(script); |
33 if (!uiSourceCode) | 27 if (!uiSourceCode) |
34 return null; | 28 return null; |
35 | 29 |
36 var formatData = this._formatData.get(uiSourceCode); | 30 var formatData = this._editorAction._formatData.get(uiSourceCode); |
37 if (!formatData) | 31 if (!formatData) |
38 return null; | 32 return null; |
39 var mapping = formatData.mapping; | 33 var mapping = formatData.mapping; |
40 var lineNumber = debuggerModelLocation.lineNumber; | 34 var lineNumber = debuggerModelLocation.lineNumber; |
41 var columnNumber = debuggerModelLocation.columnNumber || 0; | 35 var columnNumber = debuggerModelLocation.columnNumber || 0; |
42 var formattedLocation = mapping.originalToFormatted(lineNumber, columnNu
mber); | 36 var formattedLocation = mapping.originalToFormatted(lineNumber, columnNu
mber); |
43 return uiSourceCode.uiLocation(formattedLocation[0], formattedLocation[1
]); | 37 return uiSourceCode.uiLocation(formattedLocation[0], formattedLocation[1
]); |
44 }, | 38 }, |
45 | 39 |
46 /** | 40 /** |
47 * @param {!WebInspector.UISourceCode} uiSourceCode | 41 * @param {!WebInspector.UISourceCode} uiSourceCode |
48 * @param {number} lineNumber | 42 * @param {number} lineNumber |
49 * @param {number} columnNumber | 43 * @param {number} columnNumber |
50 * @return {?WebInspector.DebuggerModel.Location} | 44 * @return {?WebInspector.DebuggerModel.Location} |
51 */ | 45 */ |
52 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) | 46 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) |
53 { | 47 { |
54 var formatData = this._formatData.get(uiSourceCode); | 48 var formatData = this._editorAction._formatData.get(uiSourceCode); |
55 if (!formatData) | 49 if (!formatData) |
56 return null; | 50 return null; |
57 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber
, columnNumber) | 51 var originalLocation = formatData.mapping.formattedToOriginal(lineNumber
, columnNumber); |
58 return this._debuggerModel.createRawLocation(formatData.scripts[0], orig
inalLocation[0], originalLocation[1]); | 52 for (var i = 0; i < formatData.scripts.length; ++i) { |
| 53 if (formatData.scripts[i].target() === this._target) |
| 54 return this._target.debuggerModel.createRawLocation(formatData.s
cripts[i], originalLocation[0], originalLocation[1]) |
| 55 } |
| 56 return null; |
59 }, | 57 }, |
60 | 58 |
61 /** | 59 /** |
62 * @return {boolean} | 60 * @return {boolean} |
63 */ | 61 */ |
64 isIdentity: function() | 62 isIdentity: function() |
65 { | 63 { |
66 return false; | 64 return false; |
67 }, | 65 }, |
68 | 66 |
69 /** | 67 /** |
70 * @param {!WebInspector.UISourceCode} uiSourceCode | 68 * @param {!WebInspector.UISourceCode} uiSourceCode |
71 * @param {number} lineNumber | 69 * @param {number} lineNumber |
72 * @return {boolean} | 70 * @return {boolean} |
73 */ | 71 */ |
74 uiLineHasMapping: function(uiSourceCode, lineNumber) | 72 uiLineHasMapping: function(uiSourceCode, lineNumber) |
75 { | 73 { |
76 return true; | 74 return true; |
77 }, | 75 } |
78 | 76 |
79 /** | |
80 * @param {!WebInspector.UISourceCode} uiSourceCode | |
81 * @return {!Array.<!WebInspector.Script>} | |
82 */ | |
83 _scriptsForUISourceCode: function(uiSourceCode) | |
84 { | |
85 /** | |
86 * @param {!WebInspector.Script} script | |
87 * @return {boolean} | |
88 */ | |
89 function isInlineScript(script) | |
90 { | |
91 return script.isInlineScript(); | |
92 } | |
93 | |
94 if (uiSourceCode.contentType() === WebInspector.resourceTypes.Document) | |
95 return this._debuggerModel.scriptsForSourceURL(uiSourceCode.url).fil
ter(isInlineScript); | |
96 if (uiSourceCode.contentType() === WebInspector.resourceTypes.Script) { | |
97 var rawLocation = /** @type {!WebInspector.DebuggerModel.Location}
*/ (uiSourceCode.uiLocationToRawLocation(this._debuggerModel.target(), 0, 0)); | |
98 return rawLocation ? [rawLocation.script()] : []; | |
99 } | |
100 return []; | |
101 }, | |
102 | |
103 _init: function() | |
104 { | |
105 /** @type {!Map.<!WebInspector.Script, !WebInspector.UISourceCode>} */ | |
106 this._uiSourceCodes = new Map(); | |
107 /** @type {!StringMap.<string>} */ | |
108 this._formattedPaths = new StringMap(); | |
109 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.FormatterScri
ptMapping.FormatData>} */ | |
110 this._formatData = new Map(); | |
111 }, | |
112 | |
113 _debuggerReset: function() | |
114 { | |
115 var formattedPaths = this._formattedPaths.values(); | |
116 for (var i = 0; i < formattedPaths.length; ++i) | |
117 this._projectDelegate._removeFormatted(formattedPaths[i]); | |
118 this._init(); | |
119 }, | |
120 | |
121 /** | |
122 * @param {!WebInspector.UISourceCode} uiSourceCode | |
123 * @param {function(?WebInspector.UISourceCode, !WebInspector.FormatterSourc
eMapping=)} callback | |
124 */ | |
125 _performUISourceCodeScriptFormatting: function(uiSourceCode, callback) | |
126 { | |
127 var path = this._formattedPaths.get(uiSourceCode.project().id() + ":" +
uiSourceCode.path()); | |
128 if (path) { | |
129 var uiSourceCodePath = path; | |
130 var formattedUISourceCode = this._workspace.uiSourceCode(this._proje
ctId, uiSourceCodePath); | |
131 var formatData = formattedUISourceCode ? this._formatData.get(format
tedUISourceCode) : null; | |
132 if (!formatData) | |
133 callback(null); | |
134 else | |
135 callback(formattedUISourceCode, formatData.mapping); | |
136 return; | |
137 } | |
138 | |
139 uiSourceCode.requestContent(contentLoaded.bind(this)); | |
140 | |
141 /** | |
142 * @this {WebInspector.FormatterScriptMapping} | |
143 * @param {?string} content | |
144 */ | |
145 function contentLoaded(content) | |
146 { | |
147 var formatter = WebInspector.Formatter.createFormatter(uiSourceCode.
contentType()); | |
148 formatter.formatContent(uiSourceCode.highlighterType(), content || "
", innerCallback.bind(this)); | |
149 } | |
150 | |
151 /** | |
152 * @this {WebInspector.FormatterScriptMapping} | |
153 * @param {string} formattedContent | |
154 * @param {!WebInspector.FormatterSourceMapping} formatterMapping | |
155 */ | |
156 function innerCallback(formattedContent, formatterMapping) | |
157 { | |
158 var scripts = this._scriptsForUISourceCode(uiSourceCode); | |
159 if (!scripts.length) { | |
160 callback(null); | |
161 return; | |
162 } | |
163 var name; | |
164 if (uiSourceCode.contentType() === WebInspector.resourceTypes.Docume
nt) | |
165 name = uiSourceCode.displayName(); | |
166 else | |
167 name = uiSourceCode.name() || scripts[0].scriptId; | |
168 path = this._projectDelegate._addFormatted(name, uiSourceCode.url, u
iSourceCode.contentType(), formattedContent); | |
169 var formattedUISourceCode = /** @type {!WebInspector.UISourceCode} *
/ (this._workspace.uiSourceCode(this._projectId, path)); | |
170 | |
171 var formatData = new WebInspector.FormatterScriptMapping.FormatData(
uiSourceCode.project().id(), uiSourceCode.path(), formatterMapping, scripts); | |
172 this._formatData.put(formattedUISourceCode, formatData); | |
173 this._formattedPaths.put(uiSourceCode.project().id() + ":" + uiSourc
eCode.path(), path); | |
174 for (var i = 0; i < scripts.length; ++i) { | |
175 this._uiSourceCodes.put(scripts[i], formattedUISourceCode); | |
176 scripts[i].pushSourceMapping(this); | |
177 } | |
178 formattedUISourceCode.setSourceMappingForTarget(this._debuggerModel.
target(), this); | |
179 callback(formattedUISourceCode, formatterMapping); | |
180 } | |
181 }, | |
182 | |
183 /** | |
184 * @param {!WebInspector.UISourceCode} formattedUISourceCode | |
185 * @return {?WebInspector.FormatterSourceMapping} | |
186 */ | |
187 _discardFormattedUISourceCodeScript: function(formattedUISourceCode) | |
188 { | |
189 var formatData = this._formatData.get(formattedUISourceCode); | |
190 if (!formatData) | |
191 return null; | |
192 | |
193 this._formatData.remove(formattedUISourceCode); | |
194 this._formattedPaths.remove(formatData.projectId + ":" + formatData.path
); | |
195 for (var i = 0; i < formatData.scripts.length; ++i) { | |
196 this._uiSourceCodes.remove(formatData.scripts[i]); | |
197 formatData.scripts[i].popSourceMapping(); | |
198 } | |
199 this._projectDelegate._removeFormatted(formattedUISourceCode.path()); | |
200 return formatData.mapping; | |
201 } | |
202 } | 77 } |
203 | 78 |
204 /** | 79 /** |
205 * @constructor | 80 * @constructor |
206 * @param {string} projectId | 81 * @param {string} projectId |
207 * @param {string} path | 82 * @param {string} path |
208 * @param {!WebInspector.FormatterSourceMapping} mapping | 83 * @param {!WebInspector.FormatterSourceMapping} mapping |
209 * @param {!Array.<!WebInspector.Script>} scripts | 84 * @param {!Array.<!WebInspector.Script>} scripts |
210 */ | 85 */ |
211 WebInspector.FormatterScriptMapping.FormatData = function(projectId, path, mappi
ng, scripts) | 86 WebInspector.FormatterScriptMapping.FormatData = function(projectId, path, mappi
ng, scripts) |
212 { | 87 { |
213 this.projectId = projectId; | 88 this.projectId = projectId; |
214 this.path = path; | 89 this.path = path; |
215 this.mapping = mapping; | 90 this.mapping = mapping; |
216 this.scripts = scripts; | 91 this.scripts= scripts; |
217 } | 92 } |
218 | 93 |
219 /** | 94 /** |
220 * @constructor | 95 * @constructor |
221 * @param {!WebInspector.Workspace} workspace | 96 * @param {!WebInspector.Workspace} workspace |
222 * @param {string} id | 97 * @param {string} id |
223 * @extends {WebInspector.ContentProviderBasedProjectDelegate} | 98 * @extends {WebInspector.ContentProviderBasedProjectDelegate} |
224 */ | 99 */ |
225 WebInspector.FormatterProjectDelegate = function(workspace, id) | 100 WebInspector.FormatterProjectDelegate = function(workspace, id) |
226 { | 101 { |
(...skipping 29 matching lines...) Expand all Loading... |
256 { | 131 { |
257 this.removeFile(path); | 132 this.removeFile(path); |
258 }, | 133 }, |
259 | 134 |
260 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype | 135 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype |
261 } | 136 } |
262 | 137 |
263 /** | 138 /** |
264 * @constructor | 139 * @constructor |
265 * @implements {WebInspector.SourcesView.EditorAction} | 140 * @implements {WebInspector.SourcesView.EditorAction} |
| 141 * @implements {WebInspector.TargetManager.Observer} |
266 */ | 142 */ |
267 WebInspector.ScriptFormatterEditorAction = function() | 143 WebInspector.ScriptFormatterEditorAction = function() |
268 { | 144 { |
269 this._scriptMapping = new WebInspector.FormatterScriptMapping(WebInspector.w
orkspace, WebInspector.debuggerModel); | 145 this._projectId = "formatter:"; |
| 146 this._projectDelegate = new WebInspector.FormatterProjectDelegate(WebInspect
or.workspace, this._projectId); |
| 147 |
| 148 /** @type {!Map.<!WebInspector.Script, !WebInspector.UISourceCode>} */ |
| 149 this._uiSourceCodes = new Map(); |
| 150 /** @type {!StringMap.<string>} */ |
| 151 this._formattedPaths = new StringMap(); |
| 152 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.FormatterScriptMa
pping.FormatData>} */ |
| 153 this._formatData = new Map(); |
| 154 |
| 155 /** @type {!Map.<!WebInspector.Target, !WebInspector.FormatterScriptMapping>
} */ |
| 156 this._scriptMappingByTarget = new Map(); |
| 157 this._workspace = WebInspector.workspace; |
| 158 WebInspector.targetManager.observeTargets(this); |
270 } | 159 } |
271 | 160 |
272 WebInspector.ScriptFormatterEditorAction.prototype = { | 161 WebInspector.ScriptFormatterEditorAction.prototype = { |
273 /** | 162 /** |
| 163 * @param {!WebInspector.Target} target |
| 164 */ |
| 165 targetAdded: function(target) |
| 166 { |
| 167 this._scriptMappingByTarget.put(target, new WebInspector.FormatterScript
Mapping(target, this)); |
| 168 target.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.
GlobalObjectCleared, this._debuggerReset, this); |
| 169 }, |
| 170 |
| 171 /** |
| 172 * @param {!WebInspector.Target} target |
| 173 */ |
| 174 targetRemoved: function(target) |
| 175 { |
| 176 this._scriptMappingByTarget.remove(target); |
| 177 this._cleanForTarget(target); |
| 178 target.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Even
ts.GlobalObjectCleared, this._debuggerReset, this); |
| 179 }, |
| 180 |
| 181 /** |
274 * @param {!WebInspector.Event} event | 182 * @param {!WebInspector.Event} event |
275 */ | 183 */ |
276 _editorSelected: function(event) | 184 _editorSelected: function(event) |
277 { | 185 { |
278 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data
); | 186 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data
); |
279 this._updateButton(uiSourceCode); | 187 this._updateButton(uiSourceCode); |
280 }, | 188 }, |
281 | 189 |
282 /** | 190 /** |
283 * @param {!WebInspector.Event} event | 191 * @param {!WebInspector.Event} event |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 253 |
346 WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMet
rics.UserAction, { | 254 WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMet
rics.UserAction, { |
347 action: WebInspector.UserMetrics.UserActionNames.TogglePrettyPrint, | 255 action: WebInspector.UserMetrics.UserActionNames.TogglePrettyPrint, |
348 enabled: true, | 256 enabled: true, |
349 url: uiSourceCode.originURL() | 257 url: uiSourceCode.originURL() |
350 }); | 258 }); |
351 }, | 259 }, |
352 | 260 |
353 /** | 261 /** |
354 * @param {!WebInspector.UISourceCode} uiSourceCode | 262 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 263 * @param {!WebInspector.UISourceCode} formattedUISourceCode |
| 264 * @param {!WebInspector.FormatterSourceMapping} mapping |
| 265 * @private |
| 266 */ |
| 267 _showIfNeeded: function(uiSourceCode, formattedUISourceCode, mapping) |
| 268 { |
| 269 if (uiSourceCode !== this._sourcesView.currentUISourceCode()) |
| 270 return; |
| 271 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode); |
| 272 var start = [0, 0]; |
| 273 if (sourceFrame) { |
| 274 var selection = sourceFrame.selection(); |
| 275 start = mapping.originalToFormatted(selection.startLine, selection.s
tartColumn); |
| 276 } |
| 277 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0], st
art[1]); |
| 278 this._updateButton(formattedUISourceCode); |
| 279 }, |
| 280 |
| 281 /** |
| 282 * @param {!WebInspector.UISourceCode} formattedUISourceCode |
| 283 */ |
| 284 _discardFormattedUISourceCodeScript: function(formattedUISourceCode) |
| 285 { |
| 286 var formatData = this._formatData.get(formattedUISourceCode); |
| 287 if (!formatData) |
| 288 return; |
| 289 |
| 290 this._formatData.remove(formattedUISourceCode); |
| 291 this._formattedPaths.remove(formatData.projectId + ":" + formatData.path
); |
| 292 for (var i = 0; i < formatData.scripts.length; ++i) { |
| 293 this._uiSourceCodes.remove(formatData.scripts[i]); |
| 294 formatData.scripts[i].popSourceMapping(); |
| 295 } |
| 296 this._projectDelegate._removeFormatted(formattedUISourceCode.path()); |
| 297 }, |
| 298 |
| 299 /** |
| 300 * @param {!WebInspector.Target} target |
| 301 */ |
| 302 _cleanForTarget: function(target) |
| 303 { |
| 304 var uiSourceCodes = this._formatData.keys(); |
| 305 for (var i = 0; i < uiSourceCodes.length; ++i) { |
| 306 uiSourceCodes[i].setSourceMappingForTarget(target, null); |
| 307 var formatData = this._formatData.get(uiSourceCodes[i]); |
| 308 var scripts = []; |
| 309 for (var j = 0; j < formatData.scripts.length; ++j) { |
| 310 if (formatData.scripts[j].target() === target) |
| 311 this._uiSourceCodes.remove(formatData.scripts[j]); |
| 312 else |
| 313 scripts.push(formatData.scripts[j]); |
| 314 } |
| 315 |
| 316 if (scripts.length) |
| 317 formatData.scripts = scripts; |
| 318 else { |
| 319 this._formattedPaths.remove(formatData.projectId + ":" + formatD
ata.path); |
| 320 this._formatData.remove(uiSourceCodes[i]); |
| 321 this._projectDelegate._removeFormatted(uiSourceCodes[i].path()); |
| 322 } |
| 323 } |
| 324 }, |
| 325 |
| 326 /** |
| 327 * @param {!WebInspector.Event} event |
| 328 */ |
| 329 _debuggerReset: function(event) |
| 330 { |
| 331 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.ta
rget); |
| 332 this._cleanForTarget(debuggerModel.target()); |
| 333 }, |
| 334 |
| 335 /** |
| 336 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 337 * @return {!Array.<!WebInspector.Script>} |
| 338 */ |
| 339 _scriptsForUISourceCode: function(uiSourceCode) |
| 340 { |
| 341 /** |
| 342 * @param {!WebInspector.Script} script |
| 343 * @return {boolean} |
| 344 */ |
| 345 function isInlineScript(script) |
| 346 { |
| 347 return script.isInlineScript(); |
| 348 } |
| 349 |
| 350 if (uiSourceCode.contentType() === WebInspector.resourceTypes.Document)
{ |
| 351 var scripts = []; |
| 352 var targets = WebInspector.targetManager.targets(); |
| 353 for (var i = 0; i < targets.length; ++i) |
| 354 scripts.pushAll(targets[i].debuggerModel.scriptsForSourceURL(uiS
ourceCode.url)); |
| 355 return scripts.filter(isInlineScript); |
| 356 } |
| 357 if (uiSourceCode.contentType() === WebInspector.resourceTypes.Script) { |
| 358 var rawLocations = (uiSourceCode.uiLocationToRawLocations(0, 0)); |
| 359 return rawLocations.map(function(rawLocation) { return rawLocation.s
cript()}); |
| 360 } |
| 361 return []; |
| 362 }, |
| 363 |
| 364 /** |
| 365 * @param {!WebInspector.UISourceCode} uiSourceCode |
355 */ | 366 */ |
356 _formatUISourceCodeScript: function(uiSourceCode) | 367 _formatUISourceCodeScript: function(uiSourceCode) |
357 { | 368 { |
358 this._scriptMapping._performUISourceCodeScriptFormatting(uiSourceCode, i
nnerCallback.bind(this)); | 369 var path = this._formattedPaths.get(uiSourceCode.project().id() + ":" +
uiSourceCode.path()); |
| 370 if (path) { |
| 371 var uiSourceCodePath = path; |
| 372 var formattedUISourceCode = this._workspace.uiSourceCode(this._proje
ctId, uiSourceCodePath); |
| 373 var formatData = formattedUISourceCode ? this._formatData.get(format
tedUISourceCode) : null; |
| 374 if (formatData) |
| 375 this._showIfNeeded(uiSourceCode, /** @type {!WebInspector.UISou
rceCode} */ (formattedUISourceCode), formatData.mapping); |
| 376 return; |
| 377 } |
| 378 |
| 379 uiSourceCode.requestContent(contentLoaded.bind(this)); |
359 | 380 |
360 /** | 381 /** |
361 * @this {WebInspector.ScriptFormatterEditorAction} | 382 * @this {WebInspector.ScriptFormatterEditorAction} |
362 * @param {?WebInspector.UISourceCode} formattedUISourceCode | 383 * @param {?string} content |
363 * @param {!WebInspector.FormatterSourceMapping=} mapping | |
364 */ | 384 */ |
365 function innerCallback(formattedUISourceCode, mapping) | 385 function contentLoaded(content) |
366 { | 386 { |
367 if (!formattedUISourceCode) | 387 var formatter = WebInspector.Formatter.createFormatter(uiSourceCode.
contentType()); |
| 388 formatter.formatContent(uiSourceCode.highlighterType(), content || "
", innerCallback.bind(this)); |
| 389 } |
| 390 |
| 391 /** |
| 392 * @this {WebInspector.ScriptFormatterEditorAction} |
| 393 * @param {string} formattedContent |
| 394 * @param {!WebInspector.FormatterSourceMapping} formatterMapping |
| 395 */ |
| 396 function innerCallback(formattedContent, formatterMapping) |
| 397 { |
| 398 var scripts = this._scriptsForUISourceCode(uiSourceCode); |
| 399 if (!scripts.length) |
368 return; | 400 return; |
369 if (uiSourceCode !== this._sourcesView.currentUISourceCode()) | 401 |
370 return; | 402 var name; |
371 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode); | 403 if (uiSourceCode.contentType() === WebInspector.resourceTypes.Docume
nt) |
372 var start = [0, 0]; | 404 name = uiSourceCode.displayName(); |
373 if (sourceFrame) { | 405 else |
374 var selection = sourceFrame.selection(); | 406 name = uiSourceCode.name() || scripts[0].scriptId; |
375 start = mapping.originalToFormatted(selection.startLine, selecti
on.startColumn); | 407 path = this._projectDelegate._addFormatted(name, uiSourceCode.url, u
iSourceCode.contentType(), formattedContent); |
| 408 var formattedUISourceCode = /** @type {!WebInspector.UISourceCode} *
/ (this._workspace.uiSourceCode(this._projectId, path)); |
| 409 var formatData = new WebInspector.FormatterScriptMapping.FormatData(
uiSourceCode.project().id(), uiSourceCode.path(), formatterMapping, scripts); |
| 410 this._formatData.put(formattedUISourceCode, formatData); |
| 411 this._formattedPaths.put(uiSourceCode.project().id() + ":" + uiSourc
eCode.path(), path); |
| 412 for (var i = 0; i < scripts.length; ++i) { |
| 413 this._uiSourceCodes.put(scripts[i], formattedUISourceCode); |
| 414 var scriptMapping = /** @type {!WebInspector.FormatterScriptMapp
ing} */(this._scriptMappingByTarget.get(scripts[i].target())); |
| 415 scripts[i].pushSourceMapping(scriptMapping); |
376 } | 416 } |
377 this._sourcesView.showSourceLocation(formattedUISourceCode, start[0]
, start[1]); | 417 |
378 this._updateButton(formattedUISourceCode); | 418 var targets = WebInspector.targetManager.targets(); |
| 419 for (var i = 0; i < targets.length; ++i) { |
| 420 var scriptMapping = /** @type {!WebInspector.FormatterScriptMapp
ing} */(this._scriptMappingByTarget.get(targets[i])); |
| 421 formattedUISourceCode.setSourceMappingForTarget(targets[i], scri
ptMapping); |
| 422 } |
| 423 this._showIfNeeded(uiSourceCode, formattedUISourceCode, formatterMap
ping); |
379 } | 424 } |
380 }, | |
381 | |
382 /** | |
383 * @param {!WebInspector.UISourceCode} uiSourceCode | |
384 */ | |
385 _discardFormattedUISourceCodeScript: function(uiSourceCode) | |
386 { | |
387 this._scriptMapping._discardFormattedUISourceCodeScript(uiSourceCode); | |
388 } | 425 } |
389 } | 426 } |
OLD | NEW |