| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * | 10 * |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 /** | 28 /** |
| 29 * @interface | 29 * @interface |
| 30 */ | 30 */ |
| 31 WebInspector.TabbedEditorContainerDelegate = function() {}; | 31 Sources.TabbedEditorContainerDelegate = function() {}; |
| 32 | 32 |
| 33 WebInspector.TabbedEditorContainerDelegate.prototype = { | 33 Sources.TabbedEditorContainerDelegate.prototype = { |
| 34 /** | 34 /** |
| 35 * @param {!WebInspector.UISourceCode} uiSourceCode | 35 * @param {!Workspace.UISourceCode} uiSourceCode |
| 36 * @return {!WebInspector.Widget} | 36 * @return {!UI.Widget} |
| 37 */ | 37 */ |
| 38 viewForFile: function(uiSourceCode) {}, | 38 viewForFile: function(uiSourceCode) {}, |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * @unrestricted | 42 * @unrestricted |
| 43 */ | 43 */ |
| 44 WebInspector.TabbedEditorContainer = class extends WebInspector.Object { | 44 Sources.TabbedEditorContainer = class extends Common.Object { |
| 45 /** | 45 /** |
| 46 * @param {!WebInspector.TabbedEditorContainerDelegate} delegate | 46 * @param {!Sources.TabbedEditorContainerDelegate} delegate |
| 47 * @param {!WebInspector.Setting} setting | 47 * @param {!Common.Setting} setting |
| 48 * @param {string} placeholderText | 48 * @param {string} placeholderText |
| 49 */ | 49 */ |
| 50 constructor(delegate, setting, placeholderText) { | 50 constructor(delegate, setting, placeholderText) { |
| 51 super(); | 51 super(); |
| 52 this._delegate = delegate; | 52 this._delegate = delegate; |
| 53 | 53 |
| 54 this._tabbedPane = new WebInspector.TabbedPane(); | 54 this._tabbedPane = new UI.TabbedPane(); |
| 55 this._tabbedPane.setPlaceholderText(placeholderText); | 55 this._tabbedPane.setPlaceholderText(placeholderText); |
| 56 this._tabbedPane.setTabDelegate(new WebInspector.EditorContainerTabDelegate(
this)); | 56 this._tabbedPane.setTabDelegate(new Sources.EditorContainerTabDelegate(this)
); |
| 57 | 57 |
| 58 this._tabbedPane.setCloseableTabs(true); | 58 this._tabbedPane.setCloseableTabs(true); |
| 59 this._tabbedPane.setAllowTabReorder(true, true); | 59 this._tabbedPane.setAllowTabReorder(true, true); |
| 60 | 60 |
| 61 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed,
this._tabClosed, this); | 61 this._tabbedPane.addEventListener(UI.TabbedPane.Events.TabClosed, this._tabC
losed, this); |
| 62 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected
, this._tabSelected, this); | 62 this._tabbedPane.addEventListener(UI.TabbedPane.Events.TabSelected, this._ta
bSelected, this); |
| 63 | 63 |
| 64 WebInspector.persistence.addEventListener( | 64 Persistence.persistence.addEventListener( |
| 65 WebInspector.Persistence.Events.BindingCreated, this._onBindingCreated,
this); | 65 Persistence.Persistence.Events.BindingCreated, this._onBindingCreated, t
his); |
| 66 WebInspector.persistence.addEventListener( | 66 Persistence.persistence.addEventListener( |
| 67 WebInspector.Persistence.Events.BindingRemoved, this._onBindingRemoved,
this); | 67 Persistence.Persistence.Events.BindingRemoved, this._onBindingRemoved, t
his); |
| 68 | 68 |
| 69 this._tabIds = new Map(); | 69 this._tabIds = new Map(); |
| 70 this._files = {}; | 70 this._files = {}; |
| 71 | 71 |
| 72 this._previouslyViewedFilesSetting = setting; | 72 this._previouslyViewedFilesSetting = setting; |
| 73 this._history = WebInspector.TabbedEditorContainer.History.fromObject(this._
previouslyViewedFilesSetting.get()); | 73 this._history = Sources.TabbedEditorContainer.History.fromObject(this._previ
ouslyViewedFilesSetting.get()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * @param {!WebInspector.Event} event | 77 * @param {!Common.Event} event |
| 78 */ | 78 */ |
| 79 _onBindingCreated(event) { | 79 _onBindingCreated(event) { |
| 80 var binding = /** @type {!WebInspector.PersistenceBinding} */ (event.data); | 80 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); |
| 81 this._updateFileTitle(binding.network); | 81 this._updateFileTitle(binding.network); |
| 82 | 82 |
| 83 var networkTabId = this._tabIds.get(binding.network); | 83 var networkTabId = this._tabIds.get(binding.network); |
| 84 var fileSystemTabId = this._tabIds.get(binding.fileSystem); | 84 var fileSystemTabId = this._tabIds.get(binding.fileSystem); |
| 85 if (!fileSystemTabId) | 85 if (!fileSystemTabId) |
| 86 return; | 86 return; |
| 87 | 87 |
| 88 var wasSelectedInFileSystem = this._currentFile === binding.fileSystem; | 88 var wasSelectedInFileSystem = this._currentFile === binding.fileSystem; |
| 89 var currentSelectionRange = this._history.selectionRange(binding.fileSystem.
url()); | 89 var currentSelectionRange = this._history.selectionRange(binding.fileSystem.
url()); |
| 90 var currentScrollLineNumber = this._history.scrollLineNumber(binding.fileSys
tem.url()); | 90 var currentScrollLineNumber = this._history.scrollLineNumber(binding.fileSys
tem.url()); |
| 91 | 91 |
| 92 var tabIndex = this._tabbedPane.tabIndex(fileSystemTabId); | 92 var tabIndex = this._tabbedPane.tabIndex(fileSystemTabId); |
| 93 var tabsToClose = [fileSystemTabId]; | 93 var tabsToClose = [fileSystemTabId]; |
| 94 if (networkTabId) | 94 if (networkTabId) |
| 95 tabsToClose.push(networkTabId); | 95 tabsToClose.push(networkTabId); |
| 96 this._closeTabs(tabsToClose, true); | 96 this._closeTabs(tabsToClose, true); |
| 97 networkTabId = this._appendFileTab(binding.network, false, tabIndex); | 97 networkTabId = this._appendFileTab(binding.network, false, tabIndex); |
| 98 this._updateHistory(); | 98 this._updateHistory(); |
| 99 | 99 |
| 100 if (wasSelectedInFileSystem) | 100 if (wasSelectedInFileSystem) |
| 101 this._tabbedPane.selectTab(networkTabId, false); | 101 this._tabbedPane.selectTab(networkTabId, false); |
| 102 | 102 |
| 103 var networkTabView = /** @type {!WebInspector.Widget} */ (this._tabbedPane.t
abView(networkTabId)); | 103 var networkTabView = /** @type {!UI.Widget} */ (this._tabbedPane.tabView(net
workTabId)); |
| 104 this._restoreEditorProperties(networkTabView, currentSelectionRange, current
ScrollLineNumber); | 104 this._restoreEditorProperties(networkTabView, currentSelectionRange, current
ScrollLineNumber); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * @param {!WebInspector.Event} event | 108 * @param {!Common.Event} event |
| 109 */ | 109 */ |
| 110 _onBindingRemoved(event) { | 110 _onBindingRemoved(event) { |
| 111 var binding = /** @type {!WebInspector.PersistenceBinding} */ (event.data); | 111 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); |
| 112 this._updateFileTitle(binding.network); | 112 this._updateFileTitle(binding.network); |
| 113 | 113 |
| 114 var networkTabId = this._tabIds.get(binding.network); | 114 var networkTabId = this._tabIds.get(binding.network); |
| 115 if (!networkTabId) | 115 if (!networkTabId) |
| 116 return; | 116 return; |
| 117 | 117 |
| 118 var tabIndex = this._tabbedPane.tabIndex(networkTabId); | 118 var tabIndex = this._tabbedPane.tabIndex(networkTabId); |
| 119 var wasSelected = this._currentFile === binding.network; | 119 var wasSelected = this._currentFile === binding.network; |
| 120 var fileSystemTabId = this._appendFileTab(binding.fileSystem, false, tabInde
x); | 120 var fileSystemTabId = this._appendFileTab(binding.fileSystem, false, tabInde
x); |
| 121 this._updateHistory(); | 121 this._updateHistory(); |
| 122 | 122 |
| 123 if (wasSelected) | 123 if (wasSelected) |
| 124 this._tabbedPane.selectTab(fileSystemTabId, false); | 124 this._tabbedPane.selectTab(fileSystemTabId, false); |
| 125 | 125 |
| 126 var fileSystemTabView = /** @type {!WebInspector.Widget} */ (this._tabbedPan
e.tabView(fileSystemTabId)); | 126 var fileSystemTabView = /** @type {!UI.Widget} */ (this._tabbedPane.tabView(
fileSystemTabId)); |
| 127 var savedSelectionRange = this._history.selectionRange(binding.network.url()
); | 127 var savedSelectionRange = this._history.selectionRange(binding.network.url()
); |
| 128 var savedScrollLineNumber = this._history.scrollLineNumber(binding.network.u
rl()); | 128 var savedScrollLineNumber = this._history.scrollLineNumber(binding.network.u
rl()); |
| 129 this._restoreEditorProperties(fileSystemTabView, savedSelectionRange, savedS
crollLineNumber); | 129 this._restoreEditorProperties(fileSystemTabView, savedSelectionRange, savedS
crollLineNumber); |
| 130 } | 130 } |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * @return {!WebInspector.Widget} | 133 * @return {!UI.Widget} |
| 134 */ | 134 */ |
| 135 get view() { | 135 get view() { |
| 136 return this._tabbedPane; | 136 return this._tabbedPane; |
| 137 } | 137 } |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * @return {?WebInspector.Widget} | 140 * @return {?UI.Widget} |
| 141 */ | 141 */ |
| 142 get visibleView() { | 142 get visibleView() { |
| 143 return this._tabbedPane.visibleView; | 143 return this._tabbedPane.visibleView; |
| 144 } | 144 } |
| 145 | 145 |
| 146 /** | 146 /** |
| 147 * @return {!Array.<!WebInspector.Widget>} | 147 * @return {!Array.<!UI.Widget>} |
| 148 */ | 148 */ |
| 149 fileViews() { | 149 fileViews() { |
| 150 return /** @type {!Array.<!WebInspector.Widget>} */ (this._tabbedPane.tabVie
ws()); | 150 return /** @type {!Array.<!UI.Widget>} */ (this._tabbedPane.tabViews()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @return {!WebInspector.Toolbar} | 154 * @return {!UI.Toolbar} |
| 155 */ | 155 */ |
| 156 leftToolbar() { | 156 leftToolbar() { |
| 157 return this._tabbedPane.leftToolbar(); | 157 return this._tabbedPane.leftToolbar(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 /** | 160 /** |
| 161 * @return {!WebInspector.Toolbar} | 161 * @return {!UI.Toolbar} |
| 162 */ | 162 */ |
| 163 rightToolbar() { | 163 rightToolbar() { |
| 164 return this._tabbedPane.rightToolbar(); | 164 return this._tabbedPane.rightToolbar(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 /** | 167 /** |
| 168 * @param {!Element} parentElement | 168 * @param {!Element} parentElement |
| 169 */ | 169 */ |
| 170 show(parentElement) { | 170 show(parentElement) { |
| 171 this._tabbedPane.show(parentElement); | 171 this._tabbedPane.show(parentElement); |
| 172 } | 172 } |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * @param {!WebInspector.UISourceCode} uiSourceCode | 175 * @param {!Workspace.UISourceCode} uiSourceCode |
| 176 */ | 176 */ |
| 177 showFile(uiSourceCode) { | 177 showFile(uiSourceCode) { |
| 178 this._innerShowFile(uiSourceCode, true); | 178 this._innerShowFile(uiSourceCode, true); |
| 179 } | 179 } |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * @param {!WebInspector.UISourceCode} uiSourceCode | 182 * @param {!Workspace.UISourceCode} uiSourceCode |
| 183 */ | 183 */ |
| 184 closeFile(uiSourceCode) { | 184 closeFile(uiSourceCode) { |
| 185 var tabId = this._tabIds.get(uiSourceCode); | 185 var tabId = this._tabIds.get(uiSourceCode); |
| 186 if (!tabId) | 186 if (!tabId) |
| 187 return; | 187 return; |
| 188 this._closeTabs([tabId]); | 188 this._closeTabs([tabId]); |
| 189 } | 189 } |
| 190 | 190 |
| 191 closeAllFiles() { | 191 closeAllFiles() { |
| 192 this._closeTabs(this._tabbedPane.allTabs()); | 192 this._closeTabs(this._tabbedPane.allTabs()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 /** | 195 /** |
| 196 * @return {!Array.<!WebInspector.UISourceCode>} | 196 * @return {!Array.<!Workspace.UISourceCode>} |
| 197 */ | 197 */ |
| 198 historyUISourceCodes() { | 198 historyUISourceCodes() { |
| 199 // FIXME: there should be a way to fetch UISourceCode for its uri. | 199 // FIXME: there should be a way to fetch UISourceCode for its uri. |
| 200 var uriToUISourceCode = {}; | 200 var uriToUISourceCode = {}; |
| 201 for (var id in this._files) { | 201 for (var id in this._files) { |
| 202 var uiSourceCode = this._files[id]; | 202 var uiSourceCode = this._files[id]; |
| 203 uriToUISourceCode[uiSourceCode.url()] = uiSourceCode; | 203 uriToUISourceCode[uiSourceCode.url()] = uiSourceCode; |
| 204 } | 204 } |
| 205 | 205 |
| 206 var result = []; | 206 var result = []; |
| 207 var uris = this._history._urls(); | 207 var uris = this._history._urls(); |
| 208 for (var i = 0; i < uris.length; ++i) { | 208 for (var i = 0; i < uris.length; ++i) { |
| 209 var uiSourceCode = uriToUISourceCode[uris[i]]; | 209 var uiSourceCode = uriToUISourceCode[uris[i]]; |
| 210 if (uiSourceCode) | 210 if (uiSourceCode) |
| 211 result.push(uiSourceCode); | 211 result.push(uiSourceCode); |
| 212 } | 212 } |
| 213 return result; | 213 return result; |
| 214 } | 214 } |
| 215 | 215 |
| 216 _addViewListeners() { | 216 _addViewListeners() { |
| 217 if (!this._currentView || !this._currentView.textEditor) | 217 if (!this._currentView || !this._currentView.textEditor) |
| 218 return; | 218 return; |
| 219 this._currentView.textEditor.addEventListener( | 219 this._currentView.textEditor.addEventListener( |
| 220 WebInspector.SourcesTextEditor.Events.ScrollChanged, this._scrollChanged
, this); | 220 SourceFrame.SourcesTextEditor.Events.ScrollChanged, this._scrollChanged,
this); |
| 221 this._currentView.textEditor.addEventListener( | 221 this._currentView.textEditor.addEventListener( |
| 222 WebInspector.SourcesTextEditor.Events.SelectionChanged, this._selectionC
hanged, this); | 222 SourceFrame.SourcesTextEditor.Events.SelectionChanged, this._selectionCh
anged, this); |
| 223 } | 223 } |
| 224 | 224 |
| 225 _removeViewListeners() { | 225 _removeViewListeners() { |
| 226 if (!this._currentView || !this._currentView.textEditor) | 226 if (!this._currentView || !this._currentView.textEditor) |
| 227 return; | 227 return; |
| 228 this._currentView.textEditor.removeEventListener( | 228 this._currentView.textEditor.removeEventListener( |
| 229 WebInspector.SourcesTextEditor.Events.ScrollChanged, this._scrollChanged
, this); | 229 SourceFrame.SourcesTextEditor.Events.ScrollChanged, this._scrollChanged,
this); |
| 230 this._currentView.textEditor.removeEventListener( | 230 this._currentView.textEditor.removeEventListener( |
| 231 WebInspector.SourcesTextEditor.Events.SelectionChanged, this._selectionC
hanged, this); | 231 SourceFrame.SourcesTextEditor.Events.SelectionChanged, this._selectionCh
anged, this); |
| 232 } | 232 } |
| 233 | 233 |
| 234 /** | 234 /** |
| 235 * @param {!WebInspector.Event} event | 235 * @param {!Common.Event} event |
| 236 */ | 236 */ |
| 237 _scrollChanged(event) { | 237 _scrollChanged(event) { |
| 238 if (this._scrollTimer) | 238 if (this._scrollTimer) |
| 239 clearTimeout(this._scrollTimer); | 239 clearTimeout(this._scrollTimer); |
| 240 var lineNumber = /** @type {number} */ (event.data); | 240 var lineNumber = /** @type {number} */ (event.data); |
| 241 this._scrollTimer = setTimeout(saveHistory.bind(this), 100); | 241 this._scrollTimer = setTimeout(saveHistory.bind(this), 100); |
| 242 this._history.updateScrollLineNumber(this._currentFile.url(), lineNumber); | 242 this._history.updateScrollLineNumber(this._currentFile.url(), lineNumber); |
| 243 | 243 |
| 244 /** | 244 /** |
| 245 * @this {WebInspector.TabbedEditorContainer} | 245 * @this {Sources.TabbedEditorContainer} |
| 246 */ | 246 */ |
| 247 function saveHistory() { | 247 function saveHistory() { |
| 248 this._history.save(this._previouslyViewedFilesSetting); | 248 this._history.save(this._previouslyViewedFilesSetting); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * @param {!WebInspector.Event} event | 253 * @param {!Common.Event} event |
| 254 */ | 254 */ |
| 255 _selectionChanged(event) { | 255 _selectionChanged(event) { |
| 256 var range = /** @type {!WebInspector.TextRange} */ (event.data); | 256 var range = /** @type {!Common.TextRange} */ (event.data); |
| 257 this._history.updateSelectionRange(this._currentFile.url(), range); | 257 this._history.updateSelectionRange(this._currentFile.url(), range); |
| 258 this._history.save(this._previouslyViewedFilesSetting); | 258 this._history.save(this._previouslyViewedFilesSetting); |
| 259 } | 259 } |
| 260 | 260 |
| 261 /** | 261 /** |
| 262 * @param {!WebInspector.UISourceCode} uiSourceCode | 262 * @param {!Workspace.UISourceCode} uiSourceCode |
| 263 * @param {boolean=} userGesture | 263 * @param {boolean=} userGesture |
| 264 */ | 264 */ |
| 265 _innerShowFile(uiSourceCode, userGesture) { | 265 _innerShowFile(uiSourceCode, userGesture) { |
| 266 var binding = WebInspector.persistence.binding(uiSourceCode); | 266 var binding = Persistence.persistence.binding(uiSourceCode); |
| 267 uiSourceCode = binding ? binding.network : uiSourceCode; | 267 uiSourceCode = binding ? binding.network : uiSourceCode; |
| 268 if (this._currentFile === uiSourceCode) | 268 if (this._currentFile === uiSourceCode) |
| 269 return; | 269 return; |
| 270 | 270 |
| 271 this._removeViewListeners(); | 271 this._removeViewListeners(); |
| 272 this._currentFile = uiSourceCode; | 272 this._currentFile = uiSourceCode; |
| 273 | 273 |
| 274 var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCo
de, userGesture); | 274 var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCo
de, userGesture); |
| 275 | 275 |
| 276 this._tabbedPane.selectTab(tabId, userGesture); | 276 this._tabbedPane.selectTab(tabId, userGesture); |
| 277 if (userGesture) | 277 if (userGesture) |
| 278 this._editorSelectedByUserAction(); | 278 this._editorSelectedByUserAction(); |
| 279 | 279 |
| 280 var previousView = this._currentView; | 280 var previousView = this._currentView; |
| 281 this._currentView = this.visibleView; | 281 this._currentView = this.visibleView; |
| 282 this._addViewListeners(); | 282 this._addViewListeners(); |
| 283 | 283 |
| 284 var eventData = { | 284 var eventData = { |
| 285 currentFile: this._currentFile, | 285 currentFile: this._currentFile, |
| 286 currentView: this._currentView, | 286 currentView: this._currentView, |
| 287 previousView: previousView, | 287 previousView: previousView, |
| 288 userGesture: userGesture | 288 userGesture: userGesture |
| 289 }; | 289 }; |
| 290 this.dispatchEventToListeners(WebInspector.TabbedEditorContainer.Events.Edit
orSelected, eventData); | 290 this.dispatchEventToListeners(Sources.TabbedEditorContainer.Events.EditorSel
ected, eventData); |
| 291 } | 291 } |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * @param {!WebInspector.UISourceCode} uiSourceCode | 294 * @param {!Workspace.UISourceCode} uiSourceCode |
| 295 * @return {string} | 295 * @return {string} |
| 296 */ | 296 */ |
| 297 _titleForFile(uiSourceCode) { | 297 _titleForFile(uiSourceCode) { |
| 298 var binding = WebInspector.persistence.binding(uiSourceCode); | 298 var binding = Persistence.persistence.binding(uiSourceCode); |
| 299 var titleUISourceCode = binding ? binding.fileSystem : uiSourceCode; | 299 var titleUISourceCode = binding ? binding.fileSystem : uiSourceCode; |
| 300 var maxDisplayNameLength = 30; | 300 var maxDisplayNameLength = 30; |
| 301 var title = titleUISourceCode.displayName(true).trimMiddle(maxDisplayNameLen
gth); | 301 var title = titleUISourceCode.displayName(true).trimMiddle(maxDisplayNameLen
gth); |
| 302 if (uiSourceCode.isDirty() || WebInspector.persistence.hasUnsavedCommittedCh
anges(uiSourceCode)) | 302 if (uiSourceCode.isDirty() || Persistence.persistence.hasUnsavedCommittedCha
nges(uiSourceCode)) |
| 303 title += '*'; | 303 title += '*'; |
| 304 return title; | 304 return title; |
| 305 } | 305 } |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * @param {string} id | 308 * @param {string} id |
| 309 * @param {string} nextTabId | 309 * @param {string} nextTabId |
| 310 */ | 310 */ |
| 311 _maybeCloseTab(id, nextTabId) { | 311 _maybeCloseTab(id, nextTabId) { |
| 312 var uiSourceCode = this._files[id]; | 312 var uiSourceCode = this._files[id]; |
| 313 var shouldPrompt = uiSourceCode.isDirty() && uiSourceCode.project().canSetFi
leContent(); | 313 var shouldPrompt = uiSourceCode.isDirty() && uiSourceCode.project().canSetFi
leContent(); |
| 314 // FIXME: this should be replaced with common Save/Discard/Cancel dialog. | 314 // FIXME: this should be replaced with common Save/Discard/Cancel dialog. |
| 315 if (!shouldPrompt || | 315 if (!shouldPrompt || |
| 316 confirm(WebInspector.UIString('Are you sure you want to close unsaved fi
le: %s?', uiSourceCode.name()))) { | 316 confirm(Common.UIString('Are you sure you want to close unsaved file: %s
?', uiSourceCode.name()))) { |
| 317 uiSourceCode.resetWorkingCopy(); | 317 uiSourceCode.resetWorkingCopy(); |
| 318 var previousView = this._currentView; | 318 var previousView = this._currentView; |
| 319 if (nextTabId) | 319 if (nextTabId) |
| 320 this._tabbedPane.selectTab(nextTabId, true); | 320 this._tabbedPane.selectTab(nextTabId, true); |
| 321 this._tabbedPane.closeTab(id, true); | 321 this._tabbedPane.closeTab(id, true); |
| 322 return true; | 322 return true; |
| 323 } | 323 } |
| 324 return false; | 324 return false; |
| 325 } | 325 } |
| 326 | 326 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 344 this._tabbedPane.closeTabs(cleanTabs, true); | 344 this._tabbedPane.closeTabs(cleanTabs, true); |
| 345 for (var i = 0; i < dirtyTabs.length; ++i) { | 345 for (var i = 0; i < dirtyTabs.length; ++i) { |
| 346 var nextTabId = i + 1 < dirtyTabs.length ? dirtyTabs[i + 1] : null; | 346 var nextTabId = i + 1 < dirtyTabs.length ? dirtyTabs[i + 1] : null; |
| 347 if (!this._maybeCloseTab(dirtyTabs[i], nextTabId)) | 347 if (!this._maybeCloseTab(dirtyTabs[i], nextTabId)) |
| 348 break; | 348 break; |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 | 351 |
| 352 /** | 352 /** |
| 353 * @param {string} tabId | 353 * @param {string} tabId |
| 354 * @param {!WebInspector.ContextMenu} contextMenu | 354 * @param {!UI.ContextMenu} contextMenu |
| 355 */ | 355 */ |
| 356 _onContextMenu(tabId, contextMenu) { | 356 _onContextMenu(tabId, contextMenu) { |
| 357 var uiSourceCode = this._files[tabId]; | 357 var uiSourceCode = this._files[tabId]; |
| 358 if (uiSourceCode) | 358 if (uiSourceCode) |
| 359 contextMenu.appendApplicableItems(uiSourceCode); | 359 contextMenu.appendApplicableItems(uiSourceCode); |
| 360 } | 360 } |
| 361 | 361 |
| 362 /** | 362 /** |
| 363 * @param {!WebInspector.UISourceCode} uiSourceCode | 363 * @param {!Workspace.UISourceCode} uiSourceCode |
| 364 */ | 364 */ |
| 365 addUISourceCode(uiSourceCode) { | 365 addUISourceCode(uiSourceCode) { |
| 366 var uri = uiSourceCode.url(); | 366 var uri = uiSourceCode.url(); |
| 367 var index = this._history.index(uri); | 367 var index = this._history.index(uri); |
| 368 if (index === -1) | 368 if (index === -1) |
| 369 return; | 369 return; |
| 370 | 370 |
| 371 if (!this._tabIds.has(uiSourceCode)) | 371 if (!this._tabIds.has(uiSourceCode)) |
| 372 this._appendFileTab(uiSourceCode, false); | 372 this._appendFileTab(uiSourceCode, false); |
| 373 | 373 |
| 374 // Select tab if this file was the last to be shown. | 374 // Select tab if this file was the last to be shown. |
| 375 if (!index) { | 375 if (!index) { |
| 376 this._innerShowFile(uiSourceCode, false); | 376 this._innerShowFile(uiSourceCode, false); |
| 377 return; | 377 return; |
| 378 } | 378 } |
| 379 | 379 |
| 380 if (!this._currentFile) | 380 if (!this._currentFile) |
| 381 return; | 381 return; |
| 382 var currentProjectType = this._currentFile.project().type(); | 382 var currentProjectType = this._currentFile.project().type(); |
| 383 var addedProjectType = uiSourceCode.project().type(); | 383 var addedProjectType = uiSourceCode.project().type(); |
| 384 var snippetsProjectType = WebInspector.projectTypes.Snippets; | 384 var snippetsProjectType = Workspace.projectTypes.Snippets; |
| 385 if (this._history.index(this._currentFile.url()) && currentProjectType === s
nippetsProjectType && | 385 if (this._history.index(this._currentFile.url()) && currentProjectType === s
nippetsProjectType && |
| 386 addedProjectType !== snippetsProjectType) | 386 addedProjectType !== snippetsProjectType) |
| 387 this._innerShowFile(uiSourceCode, false); | 387 this._innerShowFile(uiSourceCode, false); |
| 388 } | 388 } |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * @param {!WebInspector.UISourceCode} uiSourceCode | 391 * @param {!Workspace.UISourceCode} uiSourceCode |
| 392 */ | 392 */ |
| 393 removeUISourceCode(uiSourceCode) { | 393 removeUISourceCode(uiSourceCode) { |
| 394 this.removeUISourceCodes([uiSourceCode]); | 394 this.removeUISourceCodes([uiSourceCode]); |
| 395 } | 395 } |
| 396 | 396 |
| 397 /** | 397 /** |
| 398 * @param {!Array.<!WebInspector.UISourceCode>} uiSourceCodes | 398 * @param {!Array.<!Workspace.UISourceCode>} uiSourceCodes |
| 399 */ | 399 */ |
| 400 removeUISourceCodes(uiSourceCodes) { | 400 removeUISourceCodes(uiSourceCodes) { |
| 401 var tabIds = []; | 401 var tabIds = []; |
| 402 for (var i = 0; i < uiSourceCodes.length; ++i) { | 402 for (var i = 0; i < uiSourceCodes.length; ++i) { |
| 403 var uiSourceCode = uiSourceCodes[i]; | 403 var uiSourceCode = uiSourceCodes[i]; |
| 404 var tabId = this._tabIds.get(uiSourceCode); | 404 var tabId = this._tabIds.get(uiSourceCode); |
| 405 if (tabId) | 405 if (tabId) |
| 406 tabIds.push(tabId); | 406 tabIds.push(tabId); |
| 407 } | 407 } |
| 408 this._tabbedPane.closeTabs(tabIds); | 408 this._tabbedPane.closeTabs(tabIds); |
| 409 } | 409 } |
| 410 | 410 |
| 411 /** | 411 /** |
| 412 * @param {!WebInspector.UISourceCode} uiSourceCode | 412 * @param {!Workspace.UISourceCode} uiSourceCode |
| 413 */ | 413 */ |
| 414 _editorClosedByUserAction(uiSourceCode) { | 414 _editorClosedByUserAction(uiSourceCode) { |
| 415 this._history.remove(uiSourceCode.url()); | 415 this._history.remove(uiSourceCode.url()); |
| 416 this._updateHistory(); | 416 this._updateHistory(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 _editorSelectedByUserAction() { | 419 _editorSelectedByUserAction() { |
| 420 this._updateHistory(); | 420 this._updateHistory(); |
| 421 } | 421 } |
| 422 | 422 |
| 423 _updateHistory() { | 423 _updateHistory() { |
| 424 var tabIds = | 424 var tabIds = |
| 425 this._tabbedPane.lastOpenedTabIds(WebInspector.TabbedEditorContainer.max
imalPreviouslyViewedFilesCount); | 425 this._tabbedPane.lastOpenedTabIds(Sources.TabbedEditorContainer.maximalP
reviouslyViewedFilesCount); |
| 426 | 426 |
| 427 /** | 427 /** |
| 428 * @param {string} tabId | 428 * @param {string} tabId |
| 429 * @this {WebInspector.TabbedEditorContainer} | 429 * @this {Sources.TabbedEditorContainer} |
| 430 */ | 430 */ |
| 431 function tabIdToURI(tabId) { | 431 function tabIdToURI(tabId) { |
| 432 return this._files[tabId].url(); | 432 return this._files[tabId].url(); |
| 433 } | 433 } |
| 434 | 434 |
| 435 this._history.update(tabIds.map(tabIdToURI.bind(this))); | 435 this._history.update(tabIds.map(tabIdToURI.bind(this))); |
| 436 this._history.save(this._previouslyViewedFilesSetting); | 436 this._history.save(this._previouslyViewedFilesSetting); |
| 437 } | 437 } |
| 438 | 438 |
| 439 /** | 439 /** |
| 440 * @param {!WebInspector.UISourceCode} uiSourceCode | 440 * @param {!Workspace.UISourceCode} uiSourceCode |
| 441 * @return {string} | 441 * @return {string} |
| 442 */ | 442 */ |
| 443 _tooltipForFile(uiSourceCode) { | 443 _tooltipForFile(uiSourceCode) { |
| 444 uiSourceCode = WebInspector.persistence.fileSystem(uiSourceCode) || uiSource
Code; | 444 uiSourceCode = Persistence.persistence.fileSystem(uiSourceCode) || uiSourceC
ode; |
| 445 return uiSourceCode.url(); | 445 return uiSourceCode.url(); |
| 446 } | 446 } |
| 447 | 447 |
| 448 /** | 448 /** |
| 449 * @param {!WebInspector.UISourceCode} uiSourceCode | 449 * @param {!Workspace.UISourceCode} uiSourceCode |
| 450 * @param {boolean=} userGesture | 450 * @param {boolean=} userGesture |
| 451 * @param {number=} index | 451 * @param {number=} index |
| 452 * @return {string} | 452 * @return {string} |
| 453 */ | 453 */ |
| 454 _appendFileTab(uiSourceCode, userGesture, index) { | 454 _appendFileTab(uiSourceCode, userGesture, index) { |
| 455 var view = this._delegate.viewForFile(uiSourceCode); | 455 var view = this._delegate.viewForFile(uiSourceCode); |
| 456 var title = this._titleForFile(uiSourceCode); | 456 var title = this._titleForFile(uiSourceCode); |
| 457 var tooltip = this._tooltipForFile(uiSourceCode); | 457 var tooltip = this._tooltipForFile(uiSourceCode); |
| 458 | 458 |
| 459 var tabId = this._generateTabId(); | 459 var tabId = this._generateTabId(); |
| 460 this._tabIds.set(uiSourceCode, tabId); | 460 this._tabIds.set(uiSourceCode, tabId); |
| 461 this._files[tabId] = uiSourceCode; | 461 this._files[tabId] = uiSourceCode; |
| 462 | 462 |
| 463 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url()); | 463 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url()); |
| 464 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.url(
)); | 464 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.url(
)); |
| 465 this._restoreEditorProperties(view, savedSelectionRange, savedScrollLineNumb
er); | 465 this._restoreEditorProperties(view, savedSelectionRange, savedScrollLineNumb
er); |
| 466 | 466 |
| 467 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, undefin
ed, index); | 467 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, undefin
ed, index); |
| 468 | 468 |
| 469 this._updateFileTitle(uiSourceCode); | 469 this._updateFileTitle(uiSourceCode); |
| 470 this._addUISourceCodeListeners(uiSourceCode); | 470 this._addUISourceCodeListeners(uiSourceCode); |
| 471 return tabId; | 471 return tabId; |
| 472 } | 472 } |
| 473 | 473 |
| 474 /** | 474 /** |
| 475 * @param {!WebInspector.Widget} editorView | 475 * @param {!UI.Widget} editorView |
| 476 * @param {!WebInspector.TextRange=} selection | 476 * @param {!Common.TextRange=} selection |
| 477 * @param {number=} firstLineNumber | 477 * @param {number=} firstLineNumber |
| 478 */ | 478 */ |
| 479 _restoreEditorProperties(editorView, selection, firstLineNumber) { | 479 _restoreEditorProperties(editorView, selection, firstLineNumber) { |
| 480 var sourceFrame = | 480 var sourceFrame = |
| 481 editorView instanceof WebInspector.SourceFrame ? /** @type {!WebInspecto
r.SourceFrame} */ (editorView) : null; | 481 editorView instanceof SourceFrame.SourceFrame ? /** @type {!SourceFrame.
SourceFrame} */ (editorView) : null; |
| 482 if (!sourceFrame) | 482 if (!sourceFrame) |
| 483 return; | 483 return; |
| 484 if (selection) | 484 if (selection) |
| 485 sourceFrame.setSelection(selection); | 485 sourceFrame.setSelection(selection); |
| 486 if (typeof firstLineNumber === 'number') | 486 if (typeof firstLineNumber === 'number') |
| 487 sourceFrame.scrollToLine(firstLineNumber); | 487 sourceFrame.scrollToLine(firstLineNumber); |
| 488 } | 488 } |
| 489 | 489 |
| 490 /** | 490 /** |
| 491 * @param {!WebInspector.Event} event | 491 * @param {!Common.Event} event |
| 492 */ | 492 */ |
| 493 _tabClosed(event) { | 493 _tabClosed(event) { |
| 494 var tabId = /** @type {string} */ (event.data.tabId); | 494 var tabId = /** @type {string} */ (event.data.tabId); |
| 495 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); | 495 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); |
| 496 | 496 |
| 497 var uiSourceCode = this._files[tabId]; | 497 var uiSourceCode = this._files[tabId]; |
| 498 if (this._currentFile === uiSourceCode) { | 498 if (this._currentFile === uiSourceCode) { |
| 499 this._removeViewListeners(); | 499 this._removeViewListeners(); |
| 500 delete this._currentView; | 500 delete this._currentView; |
| 501 delete this._currentFile; | 501 delete this._currentFile; |
| 502 } | 502 } |
| 503 this._tabIds.remove(uiSourceCode); | 503 this._tabIds.remove(uiSourceCode); |
| 504 delete this._files[tabId]; | 504 delete this._files[tabId]; |
| 505 | 505 |
| 506 this._removeUISourceCodeListeners(uiSourceCode); | 506 this._removeUISourceCodeListeners(uiSourceCode); |
| 507 | 507 |
| 508 this.dispatchEventToListeners(WebInspector.TabbedEditorContainer.Events.Edit
orClosed, uiSourceCode); | 508 this.dispatchEventToListeners(Sources.TabbedEditorContainer.Events.EditorClo
sed, uiSourceCode); |
| 509 | 509 |
| 510 if (userGesture) | 510 if (userGesture) |
| 511 this._editorClosedByUserAction(uiSourceCode); | 511 this._editorClosedByUserAction(uiSourceCode); |
| 512 } | 512 } |
| 513 | 513 |
| 514 /** | 514 /** |
| 515 * @param {!WebInspector.Event} event | 515 * @param {!Common.Event} event |
| 516 */ | 516 */ |
| 517 _tabSelected(event) { | 517 _tabSelected(event) { |
| 518 var tabId = /** @type {string} */ (event.data.tabId); | 518 var tabId = /** @type {string} */ (event.data.tabId); |
| 519 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); | 519 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); |
| 520 | 520 |
| 521 var uiSourceCode = this._files[tabId]; | 521 var uiSourceCode = this._files[tabId]; |
| 522 this._innerShowFile(uiSourceCode, userGesture); | 522 this._innerShowFile(uiSourceCode, userGesture); |
| 523 } | 523 } |
| 524 | 524 |
| 525 /** | 525 /** |
| 526 * @param {!WebInspector.UISourceCode} uiSourceCode | 526 * @param {!Workspace.UISourceCode} uiSourceCode |
| 527 */ | 527 */ |
| 528 _addUISourceCodeListeners(uiSourceCode) { | 528 _addUISourceCodeListeners(uiSourceCode) { |
| 529 uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.TitleChanged,
this._uiSourceCodeTitleChanged, this); | 529 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged, th
is._uiSourceCodeTitleChanged, this); |
| 530 uiSourceCode.addEventListener( | 530 uiSourceCode.addEventListener( |
| 531 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeW
orkingCopyChanged, this); | 531 Workspace.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWork
ingCopyChanged, this); |
| 532 uiSourceCode.addEventListener( | 532 uiSourceCode.addEventListener( |
| 533 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCod
eWorkingCopyCommitted, this); | 533 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWo
rkingCopyCommitted, this); |
| 534 } | 534 } |
| 535 | 535 |
| 536 /** | 536 /** |
| 537 * @param {!WebInspector.UISourceCode} uiSourceCode | 537 * @param {!Workspace.UISourceCode} uiSourceCode |
| 538 */ | 538 */ |
| 539 _removeUISourceCodeListeners(uiSourceCode) { | 539 _removeUISourceCodeListeners(uiSourceCode) { |
| 540 uiSourceCode.removeEventListener( | 540 uiSourceCode.removeEventListener( |
| 541 WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleCh
anged, this); | 541 Workspace.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChang
ed, this); |
| 542 uiSourceCode.removeEventListener( | 542 uiSourceCode.removeEventListener( |
| 543 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeW
orkingCopyChanged, this); | 543 Workspace.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWork
ingCopyChanged, this); |
| 544 uiSourceCode.removeEventListener( | 544 uiSourceCode.removeEventListener( |
| 545 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCod
eWorkingCopyCommitted, this); | 545 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWo
rkingCopyCommitted, this); |
| 546 } | 546 } |
| 547 | 547 |
| 548 /** | 548 /** |
| 549 * @param {!WebInspector.UISourceCode} uiSourceCode | 549 * @param {!Workspace.UISourceCode} uiSourceCode |
| 550 */ | 550 */ |
| 551 _updateFileTitle(uiSourceCode) { | 551 _updateFileTitle(uiSourceCode) { |
| 552 var tabId = this._tabIds.get(uiSourceCode); | 552 var tabId = this._tabIds.get(uiSourceCode); |
| 553 if (tabId) { | 553 if (tabId) { |
| 554 var title = this._titleForFile(uiSourceCode); | 554 var title = this._titleForFile(uiSourceCode); |
| 555 this._tabbedPane.changeTabTitle(tabId, title); | 555 this._tabbedPane.changeTabTitle(tabId, title); |
| 556 if (WebInspector.persistence.hasUnsavedCommittedChanges(uiSourceCode)) { | 556 if (Persistence.persistence.hasUnsavedCommittedChanges(uiSourceCode)) { |
| 557 this._tabbedPane.setTabIcon( | 557 this._tabbedPane.setTabIcon( |
| 558 tabId, 'smallicon-warning', WebInspector.UIString('Changes to this f
ile were not saved to file system.')); | 558 tabId, 'smallicon-warning', Common.UIString('Changes to this file we
re not saved to file system.')); |
| 559 } else if (Runtime.experiments.isEnabled('persistence2') && WebInspector.p
ersistence.binding(uiSourceCode)) { | 559 } else if (Runtime.experiments.isEnabled('persistence2') && Persistence.pe
rsistence.binding(uiSourceCode)) { |
| 560 var binding = WebInspector.persistence.binding(uiSourceCode); | 560 var binding = Persistence.persistence.binding(uiSourceCode); |
| 561 this._tabbedPane.setTabIcon(tabId, 'smallicon-green-checkmark', WebInspe
ctor.PersistenceUtils.tooltipForUISourceCode(binding.fileSystem)); | 561 this._tabbedPane.setTabIcon(tabId, 'smallicon-green-checkmark', Persiste
nce.PersistenceUtils.tooltipForUISourceCode(binding.fileSystem)); |
| 562 } else { | 562 } else { |
| 563 this._tabbedPane.setTabIcon(tabId, ''); | 563 this._tabbedPane.setTabIcon(tabId, ''); |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 | 567 |
| 568 _uiSourceCodeTitleChanged(event) { | 568 _uiSourceCodeTitleChanged(event) { |
| 569 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.target); | 569 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); |
| 570 this._updateFileTitle(uiSourceCode); | 570 this._updateFileTitle(uiSourceCode); |
| 571 this._updateHistory(); | 571 this._updateHistory(); |
| 572 } | 572 } |
| 573 | 573 |
| 574 _uiSourceCodeWorkingCopyChanged(event) { | 574 _uiSourceCodeWorkingCopyChanged(event) { |
| 575 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.target); | 575 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); |
| 576 this._updateFileTitle(uiSourceCode); | 576 this._updateFileTitle(uiSourceCode); |
| 577 } | 577 } |
| 578 | 578 |
| 579 _uiSourceCodeWorkingCopyCommitted(event) { | 579 _uiSourceCodeWorkingCopyCommitted(event) { |
| 580 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.target); | 580 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target); |
| 581 this._updateFileTitle(uiSourceCode); | 581 this._updateFileTitle(uiSourceCode); |
| 582 } | 582 } |
| 583 | 583 |
| 584 /** | 584 /** |
| 585 * @return {string} | 585 * @return {string} |
| 586 */ | 586 */ |
| 587 _generateTabId() { | 587 _generateTabId() { |
| 588 return 'tab_' + (WebInspector.TabbedEditorContainer._tabId++); | 588 return 'tab_' + (Sources.TabbedEditorContainer._tabId++); |
| 589 } | 589 } |
| 590 | 590 |
| 591 /** | 591 /** |
| 592 * @return {?WebInspector.UISourceCode} uiSourceCode | 592 * @return {?Workspace.UISourceCode} uiSourceCode |
| 593 */ | 593 */ |
| 594 currentFile() { | 594 currentFile() { |
| 595 return this._currentFile || null; | 595 return this._currentFile || null; |
| 596 } | 596 } |
| 597 }; | 597 }; |
| 598 | 598 |
| 599 /** @enum {symbol} */ | 599 /** @enum {symbol} */ |
| 600 WebInspector.TabbedEditorContainer.Events = { | 600 Sources.TabbedEditorContainer.Events = { |
| 601 EditorSelected: Symbol('EditorSelected'), | 601 EditorSelected: Symbol('EditorSelected'), |
| 602 EditorClosed: Symbol('EditorClosed') | 602 EditorClosed: Symbol('EditorClosed') |
| 603 }; | 603 }; |
| 604 | 604 |
| 605 WebInspector.TabbedEditorContainer._tabId = 0; | 605 Sources.TabbedEditorContainer._tabId = 0; |
| 606 | 606 |
| 607 WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount = 30; | 607 Sources.TabbedEditorContainer.maximalPreviouslyViewedFilesCount = 30; |
| 608 | 608 |
| 609 /** | 609 /** |
| 610 * @unrestricted | 610 * @unrestricted |
| 611 */ | 611 */ |
| 612 WebInspector.TabbedEditorContainer.HistoryItem = class { | 612 Sources.TabbedEditorContainer.HistoryItem = class { |
| 613 /** | 613 /** |
| 614 * @param {string} url | 614 * @param {string} url |
| 615 * @param {!WebInspector.TextRange=} selectionRange | 615 * @param {!Common.TextRange=} selectionRange |
| 616 * @param {number=} scrollLineNumber | 616 * @param {number=} scrollLineNumber |
| 617 */ | 617 */ |
| 618 constructor(url, selectionRange, scrollLineNumber) { | 618 constructor(url, selectionRange, scrollLineNumber) { |
| 619 /** @const */ this.url = url; | 619 /** @const */ this.url = url; |
| 620 /** @const */ this._isSerializable = | 620 /** @const */ this._isSerializable = |
| 621 url.length < WebInspector.TabbedEditorContainer.HistoryItem.serializable
UrlLengthLimit; | 621 url.length < Sources.TabbedEditorContainer.HistoryItem.serializableUrlLe
ngthLimit; |
| 622 this.selectionRange = selectionRange; | 622 this.selectionRange = selectionRange; |
| 623 this.scrollLineNumber = scrollLineNumber; | 623 this.scrollLineNumber = scrollLineNumber; |
| 624 } | 624 } |
| 625 | 625 |
| 626 /** | 626 /** |
| 627 * @param {!Object} serializedHistoryItem | 627 * @param {!Object} serializedHistoryItem |
| 628 * @return {!WebInspector.TabbedEditorContainer.HistoryItem} | 628 * @return {!Sources.TabbedEditorContainer.HistoryItem} |
| 629 */ | 629 */ |
| 630 static fromObject(serializedHistoryItem) { | 630 static fromObject(serializedHistoryItem) { |
| 631 var selectionRange = serializedHistoryItem.selectionRange ? | 631 var selectionRange = serializedHistoryItem.selectionRange ? |
| 632 WebInspector.TextRange.fromObject(serializedHistoryItem.selectionRange)
: | 632 Common.TextRange.fromObject(serializedHistoryItem.selectionRange) : |
| 633 undefined; | 633 undefined; |
| 634 return new WebInspector.TabbedEditorContainer.HistoryItem( | 634 return new Sources.TabbedEditorContainer.HistoryItem( |
| 635 serializedHistoryItem.url, selectionRange, serializedHistoryItem.scrollL
ineNumber); | 635 serializedHistoryItem.url, selectionRange, serializedHistoryItem.scrollL
ineNumber); |
| 636 } | 636 } |
| 637 | 637 |
| 638 /** | 638 /** |
| 639 * @return {?Object} | 639 * @return {?Object} |
| 640 */ | 640 */ |
| 641 serializeToObject() { | 641 serializeToObject() { |
| 642 if (!this._isSerializable) | 642 if (!this._isSerializable) |
| 643 return null; | 643 return null; |
| 644 var serializedHistoryItem = {}; | 644 var serializedHistoryItem = {}; |
| 645 serializedHistoryItem.url = this.url; | 645 serializedHistoryItem.url = this.url; |
| 646 serializedHistoryItem.selectionRange = this.selectionRange; | 646 serializedHistoryItem.selectionRange = this.selectionRange; |
| 647 serializedHistoryItem.scrollLineNumber = this.scrollLineNumber; | 647 serializedHistoryItem.scrollLineNumber = this.scrollLineNumber; |
| 648 return serializedHistoryItem; | 648 return serializedHistoryItem; |
| 649 } | 649 } |
| 650 }; | 650 }; |
| 651 | 651 |
| 652 WebInspector.TabbedEditorContainer.HistoryItem.serializableUrlLengthLimit = 4096
; | 652 Sources.TabbedEditorContainer.HistoryItem.serializableUrlLengthLimit = 4096; |
| 653 | 653 |
| 654 | 654 |
| 655 /** | 655 /** |
| 656 * @unrestricted | 656 * @unrestricted |
| 657 */ | 657 */ |
| 658 WebInspector.TabbedEditorContainer.History = class { | 658 Sources.TabbedEditorContainer.History = class { |
| 659 /** | 659 /** |
| 660 * @param {!Array.<!WebInspector.TabbedEditorContainer.HistoryItem>} items | 660 * @param {!Array.<!Sources.TabbedEditorContainer.HistoryItem>} items |
| 661 */ | 661 */ |
| 662 constructor(items) { | 662 constructor(items) { |
| 663 this._items = items; | 663 this._items = items; |
| 664 this._rebuildItemIndex(); | 664 this._rebuildItemIndex(); |
| 665 } | 665 } |
| 666 | 666 |
| 667 /** | 667 /** |
| 668 * @param {!Array.<!Object>} serializedHistory | 668 * @param {!Array.<!Object>} serializedHistory |
| 669 * @return {!WebInspector.TabbedEditorContainer.History} | 669 * @return {!Sources.TabbedEditorContainer.History} |
| 670 */ | 670 */ |
| 671 static fromObject(serializedHistory) { | 671 static fromObject(serializedHistory) { |
| 672 var items = []; | 672 var items = []; |
| 673 for (var i = 0; i < serializedHistory.length; ++i) | 673 for (var i = 0; i < serializedHistory.length; ++i) |
| 674 items.push(WebInspector.TabbedEditorContainer.HistoryItem.fromObject(seria
lizedHistory[i])); | 674 items.push(Sources.TabbedEditorContainer.HistoryItem.fromObject(serialized
History[i])); |
| 675 return new WebInspector.TabbedEditorContainer.History(items); | 675 return new Sources.TabbedEditorContainer.History(items); |
| 676 } | 676 } |
| 677 | 677 |
| 678 /** | 678 /** |
| 679 * @param {string} url | 679 * @param {string} url |
| 680 * @return {number} | 680 * @return {number} |
| 681 */ | 681 */ |
| 682 index(url) { | 682 index(url) { |
| 683 return this._itemsIndex.has(url) ? /** @type {number} */ (this._itemsIndex.g
et(url)) : -1; | 683 return this._itemsIndex.has(url) ? /** @type {number} */ (this._itemsIndex.g
et(url)) : -1; |
| 684 } | 684 } |
| 685 | 685 |
| 686 _rebuildItemIndex() { | 686 _rebuildItemIndex() { |
| 687 /** @type {!Map<string, number>} */ | 687 /** @type {!Map<string, number>} */ |
| 688 this._itemsIndex = new Map(); | 688 this._itemsIndex = new Map(); |
| 689 for (var i = 0; i < this._items.length; ++i) { | 689 for (var i = 0; i < this._items.length; ++i) { |
| 690 console.assert(!this._itemsIndex.has(this._items[i].url)); | 690 console.assert(!this._itemsIndex.has(this._items[i].url)); |
| 691 this._itemsIndex.set(this._items[i].url, i); | 691 this._itemsIndex.set(this._items[i].url, i); |
| 692 } | 692 } |
| 693 } | 693 } |
| 694 | 694 |
| 695 /** | 695 /** |
| 696 * @param {string} url | 696 * @param {string} url |
| 697 * @return {!WebInspector.TextRange|undefined} | 697 * @return {!Common.TextRange|undefined} |
| 698 */ | 698 */ |
| 699 selectionRange(url) { | 699 selectionRange(url) { |
| 700 var index = this.index(url); | 700 var index = this.index(url); |
| 701 return index !== -1 ? this._items[index].selectionRange : undefined; | 701 return index !== -1 ? this._items[index].selectionRange : undefined; |
| 702 } | 702 } |
| 703 | 703 |
| 704 /** | 704 /** |
| 705 * @param {string} url | 705 * @param {string} url |
| 706 * @param {!WebInspector.TextRange=} selectionRange | 706 * @param {!Common.TextRange=} selectionRange |
| 707 */ | 707 */ |
| 708 updateSelectionRange(url, selectionRange) { | 708 updateSelectionRange(url, selectionRange) { |
| 709 if (!selectionRange) | 709 if (!selectionRange) |
| 710 return; | 710 return; |
| 711 var index = this.index(url); | 711 var index = this.index(url); |
| 712 if (index === -1) | 712 if (index === -1) |
| 713 return; | 713 return; |
| 714 this._items[index].selectionRange = selectionRange; | 714 this._items[index].selectionRange = selectionRange; |
| 715 } | 715 } |
| 716 | 716 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 738 * @param {!Array.<string>} urls | 738 * @param {!Array.<string>} urls |
| 739 */ | 739 */ |
| 740 update(urls) { | 740 update(urls) { |
| 741 for (var i = urls.length - 1; i >= 0; --i) { | 741 for (var i = urls.length - 1; i >= 0; --i) { |
| 742 var index = this.index(urls[i]); | 742 var index = this.index(urls[i]); |
| 743 var item; | 743 var item; |
| 744 if (index !== -1) { | 744 if (index !== -1) { |
| 745 item = this._items[index]; | 745 item = this._items[index]; |
| 746 this._items.splice(index, 1); | 746 this._items.splice(index, 1); |
| 747 } else | 747 } else |
| 748 item = new WebInspector.TabbedEditorContainer.HistoryItem(urls[i]); | 748 item = new Sources.TabbedEditorContainer.HistoryItem(urls[i]); |
| 749 this._items.unshift(item); | 749 this._items.unshift(item); |
| 750 this._rebuildItemIndex(); | 750 this._rebuildItemIndex(); |
| 751 } | 751 } |
| 752 } | 752 } |
| 753 | 753 |
| 754 /** | 754 /** |
| 755 * @param {string} url | 755 * @param {string} url |
| 756 */ | 756 */ |
| 757 remove(url) { | 757 remove(url) { |
| 758 var index = this.index(url); | 758 var index = this.index(url); |
| 759 if (index !== -1) { | 759 if (index !== -1) { |
| 760 this._items.splice(index, 1); | 760 this._items.splice(index, 1); |
| 761 this._rebuildItemIndex(); | 761 this._rebuildItemIndex(); |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 | 764 |
| 765 /** | 765 /** |
| 766 * @param {!WebInspector.Setting} setting | 766 * @param {!Common.Setting} setting |
| 767 */ | 767 */ |
| 768 save(setting) { | 768 save(setting) { |
| 769 setting.set(this._serializeToObject()); | 769 setting.set(this._serializeToObject()); |
| 770 } | 770 } |
| 771 | 771 |
| 772 /** | 772 /** |
| 773 * @return {!Array.<!Object>} | 773 * @return {!Array.<!Object>} |
| 774 */ | 774 */ |
| 775 _serializeToObject() { | 775 _serializeToObject() { |
| 776 var serializedHistory = []; | 776 var serializedHistory = []; |
| 777 for (var i = 0; i < this._items.length; ++i) { | 777 for (var i = 0; i < this._items.length; ++i) { |
| 778 var serializedItem = this._items[i].serializeToObject(); | 778 var serializedItem = this._items[i].serializeToObject(); |
| 779 if (serializedItem) | 779 if (serializedItem) |
| 780 serializedHistory.push(serializedItem); | 780 serializedHistory.push(serializedItem); |
| 781 if (serializedHistory.length === WebInspector.TabbedEditorContainer.maxima
lPreviouslyViewedFilesCount) | 781 if (serializedHistory.length === Sources.TabbedEditorContainer.maximalPrev
iouslyViewedFilesCount) |
| 782 break; | 782 break; |
| 783 } | 783 } |
| 784 return serializedHistory; | 784 return serializedHistory; |
| 785 } | 785 } |
| 786 | 786 |
| 787 /** | 787 /** |
| 788 * @return {!Array.<string>} | 788 * @return {!Array.<string>} |
| 789 */ | 789 */ |
| 790 _urls() { | 790 _urls() { |
| 791 var result = []; | 791 var result = []; |
| 792 for (var i = 0; i < this._items.length; ++i) | 792 for (var i = 0; i < this._items.length; ++i) |
| 793 result.push(this._items[i].url); | 793 result.push(this._items[i].url); |
| 794 return result; | 794 return result; |
| 795 } | 795 } |
| 796 }; | 796 }; |
| 797 | 797 |
| 798 | 798 |
| 799 /** | 799 /** |
| 800 * @implements {WebInspector.TabbedPaneTabDelegate} | 800 * @implements {UI.TabbedPaneTabDelegate} |
| 801 * @unrestricted | 801 * @unrestricted |
| 802 */ | 802 */ |
| 803 WebInspector.EditorContainerTabDelegate = class { | 803 Sources.EditorContainerTabDelegate = class { |
| 804 /** | 804 /** |
| 805 * @param {!WebInspector.TabbedEditorContainer} editorContainer | 805 * @param {!Sources.TabbedEditorContainer} editorContainer |
| 806 */ | 806 */ |
| 807 constructor(editorContainer) { | 807 constructor(editorContainer) { |
| 808 this._editorContainer = editorContainer; | 808 this._editorContainer = editorContainer; |
| 809 } | 809 } |
| 810 | 810 |
| 811 /** | 811 /** |
| 812 * @override | 812 * @override |
| 813 * @param {!WebInspector.TabbedPane} tabbedPane | 813 * @param {!UI.TabbedPane} tabbedPane |
| 814 * @param {!Array.<string>} ids | 814 * @param {!Array.<string>} ids |
| 815 */ | 815 */ |
| 816 closeTabs(tabbedPane, ids) { | 816 closeTabs(tabbedPane, ids) { |
| 817 this._editorContainer._closeTabs(ids); | 817 this._editorContainer._closeTabs(ids); |
| 818 } | 818 } |
| 819 | 819 |
| 820 /** | 820 /** |
| 821 * @override | 821 * @override |
| 822 * @param {string} tabId | 822 * @param {string} tabId |
| 823 * @param {!WebInspector.ContextMenu} contextMenu | 823 * @param {!UI.ContextMenu} contextMenu |
| 824 */ | 824 */ |
| 825 onContextMenu(tabId, contextMenu) { | 825 onContextMenu(tabId, contextMenu) { |
| 826 this._editorContainer._onContextMenu(tabId, contextMenu); | 826 this._editorContainer._onContextMenu(tabId, contextMenu); |
| 827 } | 827 } |
| 828 }; | 828 }; |
| OLD | NEW |