Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: Source/devtools/front_end/ScriptFormatterEditorAction.js

Issue 206063003: DevTools: Extract SourcesEditor from SourcesPanel. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.Workspace} workspace
9 * @param {!WebInspector.DebuggerModel} debuggerModel 9 * @param {!WebInspector.DebuggerModel} debuggerModel
10 */ 10 */
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 _removeFormatted: function(path) 255 _removeFormatted: function(path)
256 { 256 {
257 this.removeFile(path); 257 this.removeFile(path);
258 }, 258 },
259 259
260 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype 260 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype
261 } 261 }
262 262
263 /** 263 /**
264 * @constructor 264 * @constructor
265 * @implements {WebInspector.SourcesPanel.EditorAction} 265 * @implements {WebInspector.SourcesEditor.EditorAction}
266 */ 266 */
267 WebInspector.ScriptFormatterEditorAction = function() 267 WebInspector.ScriptFormatterEditorAction = function()
268 { 268 {
269 this._scriptMapping = new WebInspector.FormatterScriptMapping(WebInspector.w orkspace, WebInspector.debuggerModel); 269 this._scriptMapping = new WebInspector.FormatterScriptMapping(WebInspector.w orkspace, WebInspector.debuggerModel);
270 } 270 }
271 271
272 WebInspector.ScriptFormatterEditorAction.prototype = { 272 WebInspector.ScriptFormatterEditorAction.prototype = {
273 /** 273 /**
274 * @param {!WebInspector.Event} event 274 * @param {!WebInspector.Event} event
275 */ 275 */
(...skipping 18 matching lines...) Expand all
294 294
295 /** 295 /**
296 * @param {?WebInspector.UISourceCode} uiSourceCode 296 * @param {?WebInspector.UISourceCode} uiSourceCode
297 */ 297 */
298 _updateButton: function(uiSourceCode) 298 _updateButton: function(uiSourceCode)
299 { 299 {
300 this._button.element.classList.toggle("hidden", !this._isFormatableScrip t(uiSourceCode)); 300 this._button.element.classList.toggle("hidden", !this._isFormatableScrip t(uiSourceCode));
301 }, 301 },
302 302
303 /** 303 /**
304 * @param {!WebInspector.SourcesPanel} panel 304 * @param {!WebInspector.SourcesEditor} sourcesEditor
305 * @return {!Element} 305 * @return {!Element}
306 */ 306 */
307 button: function(panel) 307 button: function(sourcesEditor)
308 { 308 {
309 if (this._button) 309 if (this._button)
310 return this._button.element; 310 return this._button.element;
311 311
312 this._panel = panel; 312 this._sourcesEditor = sourcesEditor;
313 this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorSele cted, this._editorSelected.bind(this)); 313 this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.E ditorSelected, this._editorSelected.bind(this));
314 this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorClos ed, this._editorClosed.bind(this)); 314 this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.E ditorClosed, this._editorClosed.bind(this));
315 315
316 this._button = new WebInspector.StatusBarButton(WebInspector.UIString("P retty print"), "sources-toggle-pretty-print-status-bar-item"); 316 this._button = new WebInspector.StatusBarButton(WebInspector.UIString("P retty print"), "sources-toggle-pretty-print-status-bar-item");
317 this._button.toggled = false; 317 this._button.toggled = false;
318 this._button.addEventListener("click", this._toggleFormatScriptSource, t his); 318 this._button.addEventListener("click", this._toggleFormatScriptSource, t his);
319 this._updateButton(null); 319 this._updateButton(null);
320 320
321 return this._button.element; 321 return this._button.element;
322 }, 322 },
323 323
324 /** 324 /**
325 * @param {?WebInspector.UISourceCode} uiSourceCode 325 * @param {?WebInspector.UISourceCode} uiSourceCode
326 * @return {boolean} 326 * @return {boolean}
327 */ 327 */
328 _isFormatableScript: function(uiSourceCode) 328 _isFormatableScript: function(uiSourceCode)
329 { 329 {
330 if (!uiSourceCode) 330 if (!uiSourceCode)
331 return false; 331 return false;
332 var projectType = uiSourceCode.project().type(); 332 var projectType = uiSourceCode.project().type();
333 if (projectType !== WebInspector.projectTypes.Network && projectType !== WebInspector.projectTypes.Debugger) 333 if (projectType !== WebInspector.projectTypes.Network && projectType !== WebInspector.projectTypes.Debugger)
334 return false; 334 return false;
335 var contentType = uiSourceCode.contentType(); 335 var contentType = uiSourceCode.contentType();
336 return contentType === WebInspector.resourceTypes.Script || contentType === WebInspector.resourceTypes.Document; 336 return contentType === WebInspector.resourceTypes.Script || contentType === WebInspector.resourceTypes.Document;
337 }, 337 },
338 338
339 _toggleFormatScriptSource: function() 339 _toggleFormatScriptSource: function()
340 { 340 {
341 var uiSourceCode = this._panel.selectedUISourceCode(); 341 var uiSourceCode = this._sourcesEditor.currentUISourceCode();
342 if (!this._isFormatableScript(uiSourceCode)) 342 if (!this._isFormatableScript(uiSourceCode))
343 return; 343 return;
344 this._formatUISourceCodeScript(uiSourceCode); 344 this._formatUISourceCodeScript(uiSourceCode);
345 345
346 WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMet rics.UserAction, { 346 WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMet rics.UserAction, {
347 action: WebInspector.UserMetrics.UserActionNames.TogglePrettyPrint, 347 action: WebInspector.UserMetrics.UserActionNames.TogglePrettyPrint,
348 enabled: true, 348 enabled: true,
349 url: uiSourceCode.originURL() 349 url: uiSourceCode.originURL()
350 }); 350 });
351 }, 351 },
352 352
353 /** 353 /**
354 * @param {!WebInspector.UISourceCode} uiSourceCode 354 * @param {!WebInspector.UISourceCode} uiSourceCode
355 */ 355 */
356 _formatUISourceCodeScript: function(uiSourceCode) 356 _formatUISourceCodeScript: function(uiSourceCode)
357 { 357 {
358 this._scriptMapping._performUISourceCodeScriptFormatting(uiSourceCode, i nnerCallback.bind(this)); 358 this._scriptMapping._performUISourceCodeScriptFormatting(uiSourceCode, i nnerCallback.bind(this));
359 359
360 /** 360 /**
361 * @this {WebInspector.ScriptFormatterEditorAction} 361 * @this {WebInspector.ScriptFormatterEditorAction}
362 * @param {?WebInspector.UISourceCode} formattedUISourceCode 362 * @param {?WebInspector.UISourceCode} formattedUISourceCode
363 * @param {!WebInspector.FormatterSourceMapping=} mapping 363 * @param {!WebInspector.FormatterSourceMapping=} mapping
364 */ 364 */
365 function innerCallback(formattedUISourceCode, mapping) 365 function innerCallback(formattedUISourceCode, mapping)
366 { 366 {
367 if (!formattedUISourceCode) 367 if (!formattedUISourceCode)
368 return; 368 return;
369 if (uiSourceCode !== this._panel.selectedUISourceCode()) 369 if (uiSourceCode !== this._sourcesEditor.currentUISourceCode())
370 return; 370 return;
371 var sourceFrame = this._panel.viewForFile(uiSourceCode); 371 var sourceFrame = this._sourcesEditor.viewForFile(uiSourceCode);
372 var start = [0, 0]; 372 var start = [0, 0];
373 if (sourceFrame) { 373 if (sourceFrame) {
374 var selection = sourceFrame.selection(); 374 var selection = sourceFrame.selection();
375 start = mapping.originalToFormatted(selection.startLine, selecti on.startColumn); 375 start = mapping.originalToFormatted(selection.startLine, selecti on.startColumn);
376 } 376 }
377 this._panel.showUISourceCode(formattedUISourceCode, start[0], start[ 1]); 377 this._sourcesEditor.showSourceLocation(formattedUISourceCode, start[ 0], start[1]);
378 this._updateButton(formattedUISourceCode); 378 this._updateButton(formattedUISourceCode);
379 } 379 }
380 }, 380 },
381 381
382 /** 382 /**
383 * @param {!WebInspector.UISourceCode} uiSourceCode 383 * @param {!WebInspector.UISourceCode} uiSourceCode
384 */ 384 */
385 _discardFormattedUISourceCodeScript: function(uiSourceCode) 385 _discardFormattedUISourceCodeScript: function(uiSourceCode)
386 { 386 {
387 this._scriptMapping._discardFormattedUISourceCodeScript(uiSourceCode); 387 this._scriptMapping._discardFormattedUISourceCodeScript(uiSourceCode);
388 } 388 }
389 } 389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698