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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/InplaceFormatterEditorAction.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
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 * @implements {WebInspector.SourcesView.EditorAction} 5 * @implements {Sources.SourcesView.EditorAction}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 WebInspector.InplaceFormatterEditorAction = class { 8 Sources.InplaceFormatterEditorAction = class {
9 /** 9 /**
10 * @param {!WebInspector.Event} event 10 * @param {!Common.Event} event
11 */ 11 */
12 _editorSelected(event) { 12 _editorSelected(event) {
13 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); 13 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
14 this._updateButton(uiSourceCode); 14 this._updateButton(uiSourceCode);
15 } 15 }
16 16
17 /** 17 /**
18 * @param {!WebInspector.Event} event 18 * @param {!Common.Event} event
19 */ 19 */
20 _editorClosed(event) { 20 _editorClosed(event) {
21 var wasSelected = /** @type {boolean} */ (event.data.wasSelected); 21 var wasSelected = /** @type {boolean} */ (event.data.wasSelected);
22 if (wasSelected) 22 if (wasSelected)
23 this._updateButton(null); 23 this._updateButton(null);
24 } 24 }
25 25
26 /** 26 /**
27 * @param {?WebInspector.UISourceCode} uiSourceCode 27 * @param {?Workspace.UISourceCode} uiSourceCode
28 */ 28 */
29 _updateButton(uiSourceCode) { 29 _updateButton(uiSourceCode) {
30 this._button.element.classList.toggle('hidden', !this._isFormattable(uiSourc eCode)); 30 this._button.element.classList.toggle('hidden', !this._isFormattable(uiSourc eCode));
31 } 31 }
32 32
33 /** 33 /**
34 * @override 34 * @override
35 * @param {!WebInspector.SourcesView} sourcesView 35 * @param {!Sources.SourcesView} sourcesView
36 * @return {!WebInspector.ToolbarButton} 36 * @return {!UI.ToolbarButton}
37 */ 37 */
38 button(sourcesView) { 38 button(sourcesView) {
39 if (this._button) 39 if (this._button)
40 return this._button; 40 return this._button;
41 41
42 this._sourcesView = sourcesView; 42 this._sourcesView = sourcesView;
43 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorSel ected, this._editorSelected.bind(this)); 43 this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorSelected , this._editorSelected.bind(this));
44 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorClo sed, this._editorClosed.bind(this)); 44 this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorClosed, this._editorClosed.bind(this));
45 45
46 this._button = new WebInspector.ToolbarButton(WebInspector.UIString('Format' ), 'largeicon-pretty-print'); 46 this._button = new UI.ToolbarButton(Common.UIString('Format'), 'largeicon-pr etty-print');
47 this._button.addEventListener('click', this._formatSourceInPlace, this); 47 this._button.addEventListener('click', this._formatSourceInPlace, this);
48 this._updateButton(sourcesView.currentUISourceCode()); 48 this._updateButton(sourcesView.currentUISourceCode());
49 49
50 return this._button; 50 return this._button;
51 } 51 }
52 52
53 /** 53 /**
54 * @param {?WebInspector.UISourceCode} uiSourceCode 54 * @param {?Workspace.UISourceCode} uiSourceCode
55 * @return {boolean} 55 * @return {boolean}
56 */ 56 */
57 _isFormattable(uiSourceCode) { 57 _isFormattable(uiSourceCode) {
58 if (!uiSourceCode) 58 if (!uiSourceCode)
59 return false; 59 return false;
60 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSystem) 60 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem)
61 return true; 61 return true;
62 if (WebInspector.persistence.binding(uiSourceCode)) 62 if (Persistence.persistence.binding(uiSourceCode))
63 return true; 63 return true;
64 return uiSourceCode.contentType().isStyleSheet() || 64 return uiSourceCode.contentType().isStyleSheet() ||
65 uiSourceCode.project().type() === WebInspector.projectTypes.Snippets; 65 uiSourceCode.project().type() === Workspace.projectTypes.Snippets;
66 } 66 }
67 67
68 _formatSourceInPlace() { 68 _formatSourceInPlace() {
69 var uiSourceCode = this._sourcesView.currentUISourceCode(); 69 var uiSourceCode = this._sourcesView.currentUISourceCode();
70 if (!this._isFormattable(uiSourceCode)) 70 if (!this._isFormattable(uiSourceCode))
71 return; 71 return;
72 72
73 if (uiSourceCode.isDirty()) 73 if (uiSourceCode.isDirty())
74 contentLoaded.call(this, uiSourceCode.workingCopy()); 74 contentLoaded.call(this, uiSourceCode.workingCopy());
75 else 75 else
76 uiSourceCode.requestContent().then(contentLoaded.bind(this)); 76 uiSourceCode.requestContent().then(contentLoaded.bind(this));
77 77
78 /** 78 /**
79 * @this {WebInspector.InplaceFormatterEditorAction} 79 * @this {Sources.InplaceFormatterEditorAction}
80 * @param {?string} content 80 * @param {?string} content
81 */ 81 */
82 function contentLoaded(content) { 82 function contentLoaded(content) {
83 var highlighterType = WebInspector.NetworkProject.uiSourceCodeMimeType(uiS ourceCode); 83 var highlighterType = Bindings.NetworkProject.uiSourceCodeMimeType(uiSourc eCode);
84 WebInspector.Formatter.format( 84 Sources.Formatter.format(
85 uiSourceCode.contentType(), highlighterType, content || '', innerCallb ack.bind(this)); 85 uiSourceCode.contentType(), highlighterType, content || '', innerCallb ack.bind(this));
86 } 86 }
87 87
88 /** 88 /**
89 * @this {WebInspector.InplaceFormatterEditorAction} 89 * @this {Sources.InplaceFormatterEditorAction}
90 * @param {string} formattedContent 90 * @param {string} formattedContent
91 * @param {!WebInspector.FormatterSourceMapping} formatterMapping 91 * @param {!Sources.FormatterSourceMapping} formatterMapping
92 */ 92 */
93 function innerCallback(formattedContent, formatterMapping) { 93 function innerCallback(formattedContent, formatterMapping) {
94 if (uiSourceCode.workingCopy() === formattedContent) 94 if (uiSourceCode.workingCopy() === formattedContent)
95 return; 95 return;
96 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode); 96 var sourceFrame = this._sourcesView.viewForFile(uiSourceCode);
97 var start = [0, 0]; 97 var start = [0, 0];
98 if (sourceFrame) { 98 if (sourceFrame) {
99 var selection = sourceFrame.selection(); 99 var selection = sourceFrame.selection();
100 start = formatterMapping.originalToFormatted(selection.startLine, select ion.startColumn); 100 start = formatterMapping.originalToFormatted(selection.startLine, select ion.startColumn);
101 } 101 }
102 uiSourceCode.setWorkingCopy(formattedContent); 102 uiSourceCode.setWorkingCopy(formattedContent);
103 this._sourcesView.showSourceLocation(uiSourceCode, start[0], start[1]); 103 this._sourcesView.showSourceLocation(uiSourceCode, start[0], start[1]);
104 } 104 }
105 } 105 }
106 }; 106 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698