| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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().type() === Workspace.projectTypes.FileSystem) | 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 uiSourceCode.project().type() === Workspace.projectTypes.Snippets; | |
| 66 } | 65 } |
| 67 | 66 |
| 68 _formatSourceInPlace() { | 67 _formatSourceInPlace() { |
| 69 var uiSourceCode = this._sourcesView.currentUISourceCode(); | 68 var uiSourceCode = this._sourcesView.currentUISourceCode(); |
| 70 if (!this._isFormattable(uiSourceCode)) | 69 if (!this._isFormattable(uiSourceCode)) |
| 71 return; | 70 return; |
| 72 | 71 |
| 73 if (uiSourceCode.isDirty()) | 72 if (uiSourceCode.isDirty()) |
| 74 contentLoaded.call(this, uiSourceCode.workingCopy()); | 73 contentLoaded.call(this, uiSourceCode.workingCopy()); |
| 75 else | 74 else |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 var range = decoration.range(); | 119 var range = decoration.range(); |
| 121 var startLocation = sourceMapping.originalToFormatted(range.startLine, ran
ge.startColumn); | 120 var startLocation = sourceMapping.originalToFormatted(range.startLine, ran
ge.startColumn); |
| 122 var endLocation = sourceMapping.originalToFormatted(range.endLine, range.e
ndColumn); | 121 var endLocation = sourceMapping.originalToFormatted(range.endLine, range.e
ndColumn); |
| 123 | 122 |
| 124 uiSourceCode.addDecoration( | 123 uiSourceCode.addDecoration( |
| 125 new Common.TextRange(...startLocation, ...endLocation), | 124 new Common.TextRange(...startLocation, ...endLocation), |
| 126 /** @type {string} */ (decoration.type()), decoration.data()); | 125 /** @type {string} */ (decoration.type()), decoration.data()); |
| 127 } | 126 } |
| 128 } | 127 } |
| 129 }; | 128 }; |
| OLD | NEW |