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

Side by Side Diff: Source/devtools/front_end/InplaceFormatterEditorAction.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 1
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 5
6 /** 6 /**
7 * @constructor 7 * @constructor
8 * @implements {WebInspector.SourcesPanel.EditorAction} 8 * @implements {WebInspector.SourcesEditor.EditorAction}
9 */ 9 */
10 WebInspector.InplaceFormatterEditorAction = function() 10 WebInspector.InplaceFormatterEditorAction = function()
11 { 11 {
12 } 12 }
13 13
14 WebInspector.InplaceFormatterEditorAction.prototype = { 14 WebInspector.InplaceFormatterEditorAction.prototype = {
15 /** 15 /**
16 * @param {!WebInspector.Event} event 16 * @param {!WebInspector.Event} event
17 */ 17 */
18 _editorSelected: function(event) 18 _editorSelected: function(event)
(...skipping 14 matching lines...) Expand all
33 33
34 /** 34 /**
35 * @param {?WebInspector.UISourceCode} uiSourceCode 35 * @param {?WebInspector.UISourceCode} uiSourceCode
36 */ 36 */
37 _updateButton: function(uiSourceCode) 37 _updateButton: function(uiSourceCode)
38 { 38 {
39 this._button.element.classList.toggle("hidden", !this._isFormattable(uiS ourceCode)); 39 this._button.element.classList.toggle("hidden", !this._isFormattable(uiS ourceCode));
40 }, 40 },
41 41
42 /** 42 /**
43 * @param {!WebInspector.SourcesPanel} panel 43 * @param {!WebInspector.SourcesEditor} sourcesEditor
44 * @return {!Element} 44 * @return {!Element}
45 */ 45 */
46 button: function(panel) 46 button: function(sourcesEditor)
47 { 47 {
48 if (this._button) 48 if (this._button)
49 return this._button.element; 49 return this._button.element;
50 50
51 this._panel = panel; 51 this._sourcesEditor = sourcesEditor;
52 this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorSele cted, this._editorSelected.bind(this)); 52 this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.E ditorSelected, this._editorSelected.bind(this));
53 this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorClos ed, this._editorClosed.bind(this)); 53 this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.E ditorClosed, this._editorClosed.bind(this));
54 54
55 this._button = new WebInspector.StatusBarButton(WebInspector.UIString("F ormat"), "sources-toggle-pretty-print-status-bar-item"); 55 this._button = new WebInspector.StatusBarButton(WebInspector.UIString("F ormat"), "sources-toggle-pretty-print-status-bar-item");
56 this._button.toggled = false; 56 this._button.toggled = false;
57 this._button.addEventListener("click", this._formatSourceInPlace, this); 57 this._button.addEventListener("click", this._formatSourceInPlace, this);
58 this._updateButton(null); 58 this._updateButton(null);
59 59
60 return this._button.element; 60 return this._button.element;
61 }, 61 },
62 62
63 /** 63 /**
64 * @param {?WebInspector.UISourceCode} uiSourceCode 64 * @param {?WebInspector.UISourceCode} uiSourceCode
65 * @return {boolean} 65 * @return {boolean}
66 */ 66 */
67 _isFormattable: function(uiSourceCode) 67 _isFormattable: function(uiSourceCode)
68 { 68 {
69 if (!uiSourceCode) 69 if (!uiSourceCode)
70 return false; 70 return false;
71 return uiSourceCode.contentType() === WebInspector.resourceTypes.Stylesh eet 71 return uiSourceCode.contentType() === WebInspector.resourceTypes.Stylesh eet
72 || uiSourceCode.project().type() === WebInspector.projectTypes.Snipp ets; 72 || uiSourceCode.project().type() === WebInspector.projectTypes.Snipp ets;
73 }, 73 },
74 74
75 _formatSourceInPlace: function() 75 _formatSourceInPlace: function()
76 { 76 {
77 var uiSourceCode = this._panel.selectedUISourceCode(); 77 var uiSourceCode = this._sourcesEditor.currentUISourceCode();
78 if (!this._isFormattable(uiSourceCode)) 78 if (!this._isFormattable(uiSourceCode))
79 return; 79 return;
80 80
81 if (uiSourceCode.isDirty()) 81 if (uiSourceCode.isDirty())
82 contentLoaded.call(this, uiSourceCode.workingCopy()); 82 contentLoaded.call(this, uiSourceCode.workingCopy());
83 else 83 else
84 uiSourceCode.requestContent(contentLoaded.bind(this)); 84 uiSourceCode.requestContent(contentLoaded.bind(this));
85 85
86 /** 86 /**
87 * @this {WebInspector.InplaceFormatterEditorAction} 87 * @this {WebInspector.InplaceFormatterEditorAction}
88 * @param {?string} content 88 * @param {?string} content
89 */ 89 */
90 function contentLoaded(content) 90 function contentLoaded(content)
91 { 91 {
92 var formatter = WebInspector.Formatter.createFormatter(uiSourceCode. contentType()); 92 var formatter = WebInspector.Formatter.createFormatter(uiSourceCode. contentType());
93 formatter.formatContent(uiSourceCode.highlighterType(), content || " ", innerCallback.bind(this)); 93 formatter.formatContent(uiSourceCode.highlighterType(), content || " ", innerCallback.bind(this));
94 } 94 }
95 95
96 /** 96 /**
97 * @this {WebInspector.InplaceFormatterEditorAction} 97 * @this {WebInspector.InplaceFormatterEditorAction}
98 * @param {string} formattedContent 98 * @param {string} formattedContent
99 * @param {!WebInspector.FormatterSourceMapping} formatterMapping 99 * @param {!WebInspector.FormatterSourceMapping} formatterMapping
100 */ 100 */
101 function innerCallback(formattedContent, formatterMapping) 101 function innerCallback(formattedContent, formatterMapping)
102 { 102 {
103 if (uiSourceCode.workingCopy() === formattedContent) 103 if (uiSourceCode.workingCopy() === formattedContent)
104 return; 104 return;
105 var sourceFrame = this._panel.viewForFile(uiSourceCode); 105 var sourceFrame = this._sourcesEditor.viewForFile(uiSourceCode);
106 var start = [0, 0]; 106 var start = [0, 0];
107 if (sourceFrame) { 107 if (sourceFrame) {
108 var selection = sourceFrame.selection(); 108 var selection = sourceFrame.selection();
109 start = formatterMapping.originalToFormatted(selection.startLine , selection.startColumn); 109 start = formatterMapping.originalToFormatted(selection.startLine , selection.startColumn);
110 } 110 }
111 uiSourceCode.setWorkingCopy(formattedContent); 111 uiSourceCode.setWorkingCopy(formattedContent);
112 this._panel.showUISourceCode(uiSourceCode, start[0], start[1]); 112 this._sourcesEditor.showSourceLocation(uiSourceCode, start[0], start [1]);
113 } 113 }
114 }, 114 },
115 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698