OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 29 */ |
| 30 |
| 31 /** |
| 32 * @constructor |
| 33 * @param {!WebInspector.SourcesPanel} sourcesPanel |
| 34 * @param {!function():!WebInspector.SourceFrame} currentSourceFrameCallback |
| 35 */ |
| 36 WebInspector.EditingLocationHistoryManager = function(sourcesPanel, currentSourc
eFrameCallback) |
| 37 { |
| 38 this._sourcesPanel = sourcesPanel; |
| 39 this._historyManager = new WebInspector.SimpleHistoryManager(WebInspector.Ed
itingLocationHistoryManager.HistoryDepth); |
| 40 this._currentSourceFrameCallback = currentSourceFrameCallback; |
| 41 } |
| 42 |
| 43 WebInspector.EditingLocationHistoryManager.HistoryDepth = 20; |
| 44 |
| 45 WebInspector.EditingLocationHistoryManager.prototype = { |
| 46 /** |
| 47 * @param {!WebInspector.UISourceCodeFrame} sourceFrame |
| 48 */ |
| 49 trackSourceFrameCursorJumps: function(sourceFrame) |
| 50 { |
| 51 sourceFrame.addEventListener(WebInspector.SourceFrame.Events.JumpHappene
d, 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 readOnlyLock: function() |
| 76 { |
| 77 this._historyManager.readOnlyLock(); |
| 78 }, |
| 79 |
| 80 releaseReadOnlyLock: function() |
| 81 { |
| 82 this._historyManager.releaseReadOnlyLock(); |
| 83 }, |
| 84 |
| 85 updateCurrentState: function() |
| 86 { |
| 87 var sourceFrame = this._currentSourceFrameCallback(); |
| 88 if (!sourceFrame) |
| 89 return; |
| 90 this._updateActiveState(sourceFrame.textEditor.selection()); |
| 91 }, |
| 92 |
| 93 pushNewState: function() |
| 94 { |
| 95 var sourceFrame = this._currentSourceFrameCallback(); |
| 96 if (!sourceFrame) |
| 97 return; |
| 98 this._pushActiveState(sourceFrame.textEditor.selection()); |
| 99 }, |
| 100 |
| 101 /** |
| 102 * @param {!WebInspector.TextRange} selection |
| 103 */ |
| 104 _updateActiveState: function(selection) |
| 105 { |
| 106 var active = this._historyManager.active(); |
| 107 if (!active) |
| 108 return; |
| 109 var sourceFrame = this._currentSourceFrameCallback(); |
| 110 if (!sourceFrame) |
| 111 return; |
| 112 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesPa
nel, this, sourceFrame, selection); |
| 113 active.merge(entry); |
| 114 }, |
| 115 |
| 116 /** |
| 117 * @param {!WebInspector.TextRange} selection |
| 118 */ |
| 119 _pushActiveState: function(selection) |
| 120 { |
| 121 var sourceFrame = this._currentSourceFrameCallback(); |
| 122 if (!sourceFrame) |
| 123 return; |
| 124 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesPa
nel, this, sourceFrame, selection); |
| 125 this._historyManager.push(entry); |
| 126 }, |
| 127 |
| 128 /** |
| 129 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 130 */ |
| 131 removeHistoryForSourceCode: function(uiSourceCode) |
| 132 { |
| 133 function filterOut(entry) |
| 134 { |
| 135 return entry._projectId === uiSourceCode.project().id() && entry._pa
th === uiSourceCode.path(); |
| 136 } |
| 137 |
| 138 this._historyManager.filterOut(filterOut); |
| 139 }, |
| 140 } |
| 141 |
| 142 |
| 143 /** |
| 144 * @constructor |
| 145 * @implements {WebInspector.HistoryEntry} |
| 146 * @param {!WebInspector.SourcesPanel} sourcesPanel |
| 147 * @param {!WebInspector.EditingLocationHistoryManager} editingLocationManager |
| 148 * @param {!WebInspector.SourceFrame} sourceFrame |
| 149 * @param {!WebInspector.TextRange} selection |
| 150 */ |
| 151 WebInspector.EditingLocationHistoryEntry = function(sourcesPanel, editingLocatio
nManager, sourceFrame, selection) |
| 152 { |
| 153 this._sourcesPanel = sourcesPanel; |
| 154 this._editingLocationManager = editingLocationManager; |
| 155 var uiSourceCode = sourceFrame.sourceCode(); |
| 156 this._projectId = uiSourceCode.project().id(); |
| 157 this._path = uiSourceCode.path(); |
| 158 |
| 159 var position = this._positionFromSelection(selection); |
| 160 this._positionHandle = sourceFrame.textEditor.textEditorPositionHandle(posit
ion.lineNumber, position.columnNumber); |
| 161 } |
| 162 |
| 163 WebInspector.EditingLocationHistoryEntry.prototype = { |
| 164 /** |
| 165 * @param {!WebInspector.HistoryEntry} entry |
| 166 */ |
| 167 merge: function(entry) |
| 168 { |
| 169 if (this._projectId !== entry._projectId || this._path !== entry._path) |
| 170 return; |
| 171 this._positionHandle = entry._positionHandle; |
| 172 }, |
| 173 |
| 174 /** |
| 175 * @param {!WebInspector.TextRange} selection |
| 176 * @return {!{lineNumber: number, columnNumber: number}} |
| 177 */ |
| 178 _positionFromSelection: function(selection) |
| 179 { |
| 180 return { |
| 181 lineNumber: selection.endLine, |
| 182 columnNumber: selection.endColumn |
| 183 }; |
| 184 }, |
| 185 |
| 186 /** |
| 187 * @return {boolean} |
| 188 */ |
| 189 valid: function() |
| 190 { |
| 191 var position = this._positionHandle.resolve(); |
| 192 var uiSourceCode = WebInspector.workspace.project(this._projectId).uiSou
rceCode(this._path); |
| 193 return !!(position && uiSourceCode); |
| 194 }, |
| 195 |
| 196 reveal: function() |
| 197 { |
| 198 var position = this._positionHandle.resolve(); |
| 199 var uiSourceCode = WebInspector.workspace.project(this._projectId).uiSou
rceCode(this._path); |
| 200 if (!position || !uiSourceCode) |
| 201 return; |
| 202 |
| 203 this._editingLocationManager.updateCurrentState(); |
| 204 this._sourcesPanel.showUISourceCode(uiSourceCode); |
| 205 this._sourcesPanel.focus(); |
| 206 this._sourcesPanel.highlightPosition(position.lineNumber, position.colum
nNumber); |
| 207 } |
| 208 }; |
OLD | NEW |