| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 /** |
| 31 * @unrestricted |
| 32 */ |
| 33 WebInspector.EditingLocationHistoryManager = class { |
| 34 /** |
| 35 * @param {!WebInspector.SourcesView} sourcesView |
| 36 * @param {function():?WebInspector.SourceFrame} currentSourceFrameCallback |
| 37 */ |
| 38 constructor(sourcesView, currentSourceFrameCallback) { |
| 39 this._sourcesView = sourcesView; |
| 40 this._historyManager = |
| 41 new WebInspector.SimpleHistoryManager(WebInspector.EditingLocationHistor
yManager.HistoryDepth); |
| 42 this._currentSourceFrameCallback = currentSourceFrameCallback; |
| 43 } |
| 30 | 44 |
| 31 /** | 45 /** |
| 32 * @constructor | 46 * @param {!WebInspector.UISourceCodeFrame} sourceFrame |
| 33 * @param {!WebInspector.SourcesView} sourcesView | 47 */ |
| 34 * @param {function():?WebInspector.SourceFrame} currentSourceFrameCallback | 48 trackSourceFrameCursorJumps(sourceFrame) { |
| 35 */ | 49 sourceFrame.textEditor.addEventListener( |
| 36 WebInspector.EditingLocationHistoryManager = function(sourcesView, currentSource
FrameCallback) | 50 WebInspector.SourcesTextEditor.Events.JumpHappened, this._onJumpHappened
.bind(this)); |
| 37 { | 51 } |
| 38 this._sourcesView = sourcesView; | 52 |
| 39 this._historyManager = new WebInspector.SimpleHistoryManager(WebInspector.Ed
itingLocationHistoryManager.HistoryDepth); | 53 /** |
| 40 this._currentSourceFrameCallback = currentSourceFrameCallback; | 54 * @param {!WebInspector.Event} event |
| 55 */ |
| 56 _onJumpHappened(event) { |
| 57 if (event.data.from) |
| 58 this._updateActiveState(event.data.from); |
| 59 if (event.data.to) |
| 60 this._pushActiveState(event.data.to); |
| 61 } |
| 62 |
| 63 rollback() { |
| 64 this._historyManager.rollback(); |
| 65 } |
| 66 |
| 67 rollover() { |
| 68 this._historyManager.rollover(); |
| 69 } |
| 70 |
| 71 updateCurrentState() { |
| 72 var sourceFrame = this._currentSourceFrameCallback(); |
| 73 if (!sourceFrame) |
| 74 return; |
| 75 this._updateActiveState(sourceFrame.textEditor.selection()); |
| 76 } |
| 77 |
| 78 pushNewState() { |
| 79 var sourceFrame = this._currentSourceFrameCallback(); |
| 80 if (!sourceFrame) |
| 81 return; |
| 82 this._pushActiveState(sourceFrame.textEditor.selection()); |
| 83 } |
| 84 |
| 85 /** |
| 86 * @param {!WebInspector.TextRange} selection |
| 87 */ |
| 88 _updateActiveState(selection) { |
| 89 var active = this._historyManager.active(); |
| 90 if (!active) |
| 91 return; |
| 92 var sourceFrame = this._currentSourceFrameCallback(); |
| 93 if (!sourceFrame) |
| 94 return; |
| 95 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesView,
this, sourceFrame, selection); |
| 96 active.merge(entry); |
| 97 } |
| 98 |
| 99 /** |
| 100 * @param {!WebInspector.TextRange} selection |
| 101 */ |
| 102 _pushActiveState(selection) { |
| 103 var sourceFrame = this._currentSourceFrameCallback(); |
| 104 if (!sourceFrame) |
| 105 return; |
| 106 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesView,
this, sourceFrame, selection); |
| 107 this._historyManager.push(entry); |
| 108 } |
| 109 |
| 110 /** |
| 111 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 112 */ |
| 113 removeHistoryForSourceCode(uiSourceCode) { |
| 114 function filterOut(entry) { |
| 115 return entry._projectId === uiSourceCode.project().id() && entry._url ===
uiSourceCode.url(); |
| 116 } |
| 117 |
| 118 this._historyManager.filterOut(filterOut); |
| 119 } |
| 41 }; | 120 }; |
| 42 | 121 |
| 43 WebInspector.EditingLocationHistoryManager.HistoryDepth = 20; | 122 WebInspector.EditingLocationHistoryManager.HistoryDepth = 20; |
| 44 | 123 |
| 45 WebInspector.EditingLocationHistoryManager.prototype = { | |
| 46 /** | |
| 47 * @param {!WebInspector.UISourceCodeFrame} sourceFrame | |
| 48 */ | |
| 49 trackSourceFrameCursorJumps: function(sourceFrame) | |
| 50 { | |
| 51 sourceFrame.textEditor.addEventListener(WebInspector.SourcesTextEditor.E
vents.JumpHappened, this._onJumpHappened.bind(this)); | |
| 52 }, | |
| 53 | |
| 54 /** | |
| 55 * @param {!WebInspector.Event} event | |
| 56 */ | |
| 57 _onJumpHappened: function(event) | |
| 58 { | |
| 59 if (event.data.from) | |
| 60 this._updateActiveState(event.data.from); | |
| 61 if (event.data.to) | |
| 62 this._pushActiveState(event.data.to); | |
| 63 }, | |
| 64 | |
| 65 rollback: function() | |
| 66 { | |
| 67 this._historyManager.rollback(); | |
| 68 }, | |
| 69 | |
| 70 rollover: function() | |
| 71 { | |
| 72 this._historyManager.rollover(); | |
| 73 }, | |
| 74 | |
| 75 updateCurrentState: function() | |
| 76 { | |
| 77 var sourceFrame = this._currentSourceFrameCallback(); | |
| 78 if (!sourceFrame) | |
| 79 return; | |
| 80 this._updateActiveState(sourceFrame.textEditor.selection()); | |
| 81 }, | |
| 82 | |
| 83 pushNewState: function() | |
| 84 { | |
| 85 var sourceFrame = this._currentSourceFrameCallback(); | |
| 86 if (!sourceFrame) | |
| 87 return; | |
| 88 this._pushActiveState(sourceFrame.textEditor.selection()); | |
| 89 }, | |
| 90 | |
| 91 /** | |
| 92 * @param {!WebInspector.TextRange} selection | |
| 93 */ | |
| 94 _updateActiveState: function(selection) | |
| 95 { | |
| 96 var active = this._historyManager.active(); | |
| 97 if (!active) | |
| 98 return; | |
| 99 var sourceFrame = this._currentSourceFrameCallback(); | |
| 100 if (!sourceFrame) | |
| 101 return; | |
| 102 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesVi
ew, this, sourceFrame, selection); | |
| 103 active.merge(entry); | |
| 104 }, | |
| 105 | |
| 106 /** | |
| 107 * @param {!WebInspector.TextRange} selection | |
| 108 */ | |
| 109 _pushActiveState: function(selection) | |
| 110 { | |
| 111 var sourceFrame = this._currentSourceFrameCallback(); | |
| 112 if (!sourceFrame) | |
| 113 return; | |
| 114 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesVi
ew, this, sourceFrame, selection); | |
| 115 this._historyManager.push(entry); | |
| 116 }, | |
| 117 | |
| 118 /** | |
| 119 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 120 */ | |
| 121 removeHistoryForSourceCode: function(uiSourceCode) | |
| 122 { | |
| 123 function filterOut(entry) | |
| 124 { | |
| 125 return entry._projectId === uiSourceCode.project().id() && entry._ur
l === uiSourceCode.url(); | |
| 126 } | |
| 127 | |
| 128 this._historyManager.filterOut(filterOut); | |
| 129 }, | |
| 130 }; | |
| 131 | |
| 132 | |
| 133 /** | 124 /** |
| 134 * @constructor | |
| 135 * @implements {WebInspector.HistoryEntry} | 125 * @implements {WebInspector.HistoryEntry} |
| 136 * @param {!WebInspector.SourcesView} sourcesView | 126 * @unrestricted |
| 137 * @param {!WebInspector.EditingLocationHistoryManager} editingLocationManager | |
| 138 * @param {!WebInspector.SourceFrame} sourceFrame | |
| 139 * @param {!WebInspector.TextRange} selection | |
| 140 */ | 127 */ |
| 141 WebInspector.EditingLocationHistoryEntry = function(sourcesView, editingLocation
Manager, sourceFrame, selection) | 128 WebInspector.EditingLocationHistoryEntry = class { |
| 142 { | 129 /** |
| 130 * @param {!WebInspector.SourcesView} sourcesView |
| 131 * @param {!WebInspector.EditingLocationHistoryManager} editingLocationManager |
| 132 * @param {!WebInspector.SourceFrame} sourceFrame |
| 133 * @param {!WebInspector.TextRange} selection |
| 134 */ |
| 135 constructor(sourcesView, editingLocationManager, sourceFrame, selection) { |
| 143 this._sourcesView = sourcesView; | 136 this._sourcesView = sourcesView; |
| 144 this._editingLocationManager = editingLocationManager; | 137 this._editingLocationManager = editingLocationManager; |
| 145 var uiSourceCode = sourceFrame.uiSourceCode(); | 138 var uiSourceCode = sourceFrame.uiSourceCode(); |
| 146 this._projectId = uiSourceCode.project().id(); | 139 this._projectId = uiSourceCode.project().id(); |
| 147 this._url = uiSourceCode.url(); | 140 this._url = uiSourceCode.url(); |
| 148 | 141 |
| 149 var position = this._positionFromSelection(selection); | 142 var position = this._positionFromSelection(selection); |
| 150 this._positionHandle = sourceFrame.textEditor.textEditorPositionHandle(posit
ion.lineNumber, position.columnNumber); | 143 this._positionHandle = sourceFrame.textEditor.textEditorPositionHandle(posit
ion.lineNumber, position.columnNumber); |
| 144 } |
| 145 |
| 146 /** |
| 147 * @param {!WebInspector.HistoryEntry} entry |
| 148 */ |
| 149 merge(entry) { |
| 150 if (this._projectId !== entry._projectId || this._url !== entry._url) |
| 151 return; |
| 152 this._positionHandle = entry._positionHandle; |
| 153 } |
| 154 |
| 155 /** |
| 156 * @param {!WebInspector.TextRange} selection |
| 157 * @return {!{lineNumber: number, columnNumber: number}} |
| 158 */ |
| 159 _positionFromSelection(selection) { |
| 160 return {lineNumber: selection.endLine, columnNumber: selection.endColumn}; |
| 161 } |
| 162 |
| 163 /** |
| 164 * @override |
| 165 * @return {boolean} |
| 166 */ |
| 167 valid() { |
| 168 var position = this._positionHandle.resolve(); |
| 169 var uiSourceCode = WebInspector.workspace.uiSourceCode(this._projectId, this
._url); |
| 170 return !!(position && uiSourceCode); |
| 171 } |
| 172 |
| 173 /** |
| 174 * @override |
| 175 */ |
| 176 reveal() { |
| 177 var position = this._positionHandle.resolve(); |
| 178 var uiSourceCode = WebInspector.workspace.uiSourceCode(this._projectId, this
._url); |
| 179 if (!position || !uiSourceCode) |
| 180 return; |
| 181 |
| 182 this._editingLocationManager.updateCurrentState(); |
| 183 this._sourcesView.showSourceLocation(uiSourceCode, position.lineNumber, posi
tion.columnNumber); |
| 184 } |
| 151 }; | 185 }; |
| 152 | |
| 153 WebInspector.EditingLocationHistoryEntry.prototype = { | |
| 154 /** | |
| 155 * @param {!WebInspector.HistoryEntry} entry | |
| 156 */ | |
| 157 merge: function(entry) | |
| 158 { | |
| 159 if (this._projectId !== entry._projectId || this._url !== entry._url) | |
| 160 return; | |
| 161 this._positionHandle = entry._positionHandle; | |
| 162 }, | |
| 163 | |
| 164 /** | |
| 165 * @param {!WebInspector.TextRange} selection | |
| 166 * @return {!{lineNumber: number, columnNumber: number}} | |
| 167 */ | |
| 168 _positionFromSelection: function(selection) | |
| 169 { | |
| 170 return { | |
| 171 lineNumber: selection.endLine, | |
| 172 columnNumber: selection.endColumn | |
| 173 }; | |
| 174 }, | |
| 175 | |
| 176 /** | |
| 177 * @override | |
| 178 * @return {boolean} | |
| 179 */ | |
| 180 valid: function() | |
| 181 { | |
| 182 var position = this._positionHandle.resolve(); | |
| 183 var uiSourceCode = WebInspector.workspace.uiSourceCode(this._projectId,
this._url); | |
| 184 return !!(position && uiSourceCode); | |
| 185 }, | |
| 186 | |
| 187 /** | |
| 188 * @override | |
| 189 */ | |
| 190 reveal: function() | |
| 191 { | |
| 192 var position = this._positionHandle.resolve(); | |
| 193 var uiSourceCode = WebInspector.workspace.uiSourceCode(this._projectId,
this._url); | |
| 194 if (!position || !uiSourceCode) | |
| 195 return; | |
| 196 | |
| 197 this._editingLocationManager.updateCurrentState(); | |
| 198 this._sourcesView.showSourceLocation(uiSourceCode, position.lineNumber,
position.columnNumber); | |
| 199 } | |
| 200 }; | |
| OLD | NEW |