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 * @implements {Sources.SourcesView.EditorAction} | 5 * @implements {Sources.SourcesView.EditorAction} |
6 * @unrestricted | 6 * @unrestricted |
7 */ | 7 */ |
8 Sources.InplaceFormatterEditorAction = class { | 8 Sources.InplaceFormatterEditorAction = class { |
9 /** | 9 /** |
10 * @param {!Common.Event} event | 10 * @param {!Common.Event} event |
(...skipping 26 matching lines...) Expand all Loading... |
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(Sources.SourcesView.Events.EditorSelected
, this._editorSelected.bind(this)); | 43 this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorSelected
, this._editorSelected.bind(this)); |
44 this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorClosed,
this._editorClosed.bind(this)); | 44 this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorClosed,
this._editorClosed.bind(this)); |
45 | 45 |
46 this._button = new UI.ToolbarButton(Common.UIString('Format'), 'largeicon-pr
etty-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(UI.ToolbarButton.Events.Click, this._formatSou
rceInPlace, 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 {?Workspace.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().canSetFileContent()) | 60 if (uiSourceCode.project().canSetFileContent()) |
61 return true; | 61 return true; |
62 if (Persistence.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 } | 65 } |
66 | 66 |
67 _formatSourceInPlace() { | 67 /** |
| 68 * @param {!Common.Event} event |
| 69 */ |
| 70 _formatSourceInPlace(event) { |
68 var uiSourceCode = this._sourcesView.currentUISourceCode(); | 71 var uiSourceCode = this._sourcesView.currentUISourceCode(); |
69 if (!this._isFormattable(uiSourceCode)) | 72 if (!this._isFormattable(uiSourceCode)) |
70 return; | 73 return; |
71 | 74 |
72 if (uiSourceCode.isDirty()) | 75 if (uiSourceCode.isDirty()) |
73 contentLoaded.call(this, uiSourceCode.workingCopy()); | 76 contentLoaded.call(this, uiSourceCode.workingCopy()); |
74 else | 77 else |
75 uiSourceCode.requestContent().then(contentLoaded.bind(this)); | 78 uiSourceCode.requestContent().then(contentLoaded.bind(this)); |
76 | 79 |
77 /** | 80 /** |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 var range = decoration.range(); | 122 var range = decoration.range(); |
120 var startLocation = sourceMapping.originalToFormatted(range.startLine, ran
ge.startColumn); | 123 var startLocation = sourceMapping.originalToFormatted(range.startLine, ran
ge.startColumn); |
121 var endLocation = sourceMapping.originalToFormatted(range.endLine, range.e
ndColumn); | 124 var endLocation = sourceMapping.originalToFormatted(range.endLine, range.e
ndColumn); |
122 | 125 |
123 uiSourceCode.addDecoration( | 126 uiSourceCode.addDecoration( |
124 new Common.TextRange(...startLocation, ...endLocation), | 127 new Common.TextRange(...startLocation, ...endLocation), |
125 /** @type {string} */ (decoration.type()), decoration.data()); | 128 /** @type {string} */ (decoration.type()), decoration.data()); |
126 } | 129 } |
127 } | 130 } |
128 }; | 131 }; |
OLD | NEW |