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

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

Issue 2573323002: Revert of [DevTools] Remove methods on Common.Event. (Closed)
Patch Set: Created 4 years 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 {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
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(UI.ToolbarButton.Events.Click, this._formatSou rceInPlace, 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 {?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 /** 67 _formatSourceInPlace() {
68 * @param {!Common.Event} event
69 */
70 _formatSourceInPlace(event) {
71 var uiSourceCode = this._sourcesView.currentUISourceCode(); 68 var uiSourceCode = this._sourcesView.currentUISourceCode();
72 if (!this._isFormattable(uiSourceCode)) 69 if (!this._isFormattable(uiSourceCode))
73 return; 70 return;
74 71
75 if (uiSourceCode.isDirty()) 72 if (uiSourceCode.isDirty())
76 contentLoaded.call(this, uiSourceCode.workingCopy()); 73 contentLoaded.call(this, uiSourceCode.workingCopy());
77 else 74 else
78 uiSourceCode.requestContent().then(contentLoaded.bind(this)); 75 uiSourceCode.requestContent().then(contentLoaded.bind(this));
79 76
80 /** 77 /**
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 var range = decoration.range(); 119 var range = decoration.range();
123 var startLocation = sourceMapping.originalToFormatted(range.startLine, ran ge.startColumn); 120 var startLocation = sourceMapping.originalToFormatted(range.startLine, ran ge.startColumn);
124 var endLocation = sourceMapping.originalToFormatted(range.endLine, range.e ndColumn); 121 var endLocation = sourceMapping.originalToFormatted(range.endLine, range.e ndColumn);
125 122
126 uiSourceCode.addDecoration( 123 uiSourceCode.addDecoration(
127 new Common.TextRange(...startLocation, ...endLocation), 124 new Common.TextRange(...startLocation, ...endLocation),
128 /** @type {string} */ (decoration.type()), decoration.data()); 125 /** @type {string} */ (decoration.type()), decoration.data());
129 } 126 }
130 } 127 }
131 }; 128 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698