| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 _onBindingCreated: function(event) | 88 _onBindingCreated: function(event) |
| 89 { | 89 { |
| 90 var binding = /** @type {!WebInspector.PersistenceBinding} */(event.data
); | 90 var binding = /** @type {!WebInspector.PersistenceBinding} */(event.data
); |
| 91 var networkTabId = this._tabIds.get(binding.network); | 91 var networkTabId = this._tabIds.get(binding.network); |
| 92 var fileSystemTabId = this._tabIds.get(binding.fileSystem); | 92 var fileSystemTabId = this._tabIds.get(binding.fileSystem); |
| 93 | 93 |
| 94 if (networkTabId) | 94 if (networkTabId) |
| 95 this._tabbedPane.changeTabTitle(networkTabId, this._titleForFile(bin
ding.fileSystem), this._tooltipForFile(binding.fileSystem)); | 95 this._tabbedPane.changeTabTitle(networkTabId, this._titleForFile(bin
ding.fileSystem), this._tooltipForFile(binding.fileSystem)); |
| 96 if (!fileSystemTabId) | 96 if (!fileSystemTabId) |
| 97 return; | 97 return; |
| 98 |
| 98 var wasSelectedInFileSystem = this._currentFile === binding.fileSystem; | 99 var wasSelectedInFileSystem = this._currentFile === binding.fileSystem; |
| 100 var currentSelectionRange = this._history.selectionRange(binding.fileSys
tem.url()); |
| 101 var currentScrollLineNumber = this._history.scrollLineNumber(binding.fil
eSystem.url()); |
| 102 |
| 99 var tabIndex = this._tabbedPane.tabIndex(fileSystemTabId); | 103 var tabIndex = this._tabbedPane.tabIndex(fileSystemTabId); |
| 100 this._closeTabs([fileSystemTabId]); | 104 this._closeTabs([fileSystemTabId], true); |
| 101 if (!networkTabId) | 105 if (!networkTabId) |
| 102 networkTabId = this._appendFileTab(binding.network, false, tabIndex)
; | 106 networkTabId = this._appendFileTab(binding.network, false, tabIndex)
; |
| 107 this._updateHistory(); |
| 108 |
| 103 if (wasSelectedInFileSystem) | 109 if (wasSelectedInFileSystem) |
| 104 this._tabbedPane.selectTab(networkTabId, false); | 110 this._tabbedPane.selectTab(networkTabId, false); |
| 111 |
| 112 var networkTabView = /** @type {!WebInspector.Widget} */(this._tabbedPan
e.tabView(networkTabId)); |
| 113 this._restoreEditorProperties(networkTabView, currentSelectionRange, cur
rentScrollLineNumber); |
| 105 }, | 114 }, |
| 106 | 115 |
| 107 /** | 116 /** |
| 108 * @param {!WebInspector.Event} event | 117 * @param {!WebInspector.Event} event |
| 109 */ | 118 */ |
| 110 _onBindingRemoved: function(event) | 119 _onBindingRemoved: function(event) |
| 111 { | 120 { |
| 112 var binding = /** @type {!WebInspector.PersistenceBinding} */(event.data
); | 121 var binding = /** @type {!WebInspector.PersistenceBinding} */(event.data
); |
| 113 var networkTabId = this._tabIds.get(binding.network); | 122 var networkTabId = this._tabIds.get(binding.network); |
| 114 if (!networkTabId) | 123 if (!networkTabId) |
| 115 return; | 124 return; |
| 116 this._appendFileTab(binding.fileSystem, false); | 125 |
| 126 var fileSystemTabId = this._appendFileTab(binding.fileSystem, false); |
| 127 this._updateHistory(); |
| 128 |
| 129 var fileSystemTabView = /** @type {!WebInspector.Widget} */(this._tabbed
Pane.tabView(fileSystemTabId)); |
| 130 var savedSelectionRange = this._history.selectionRange(binding.network.u
rl()); |
| 131 var savedScrollLineNumber = this._history.scrollLineNumber(binding.netwo
rk.url()); |
| 132 this._restoreEditorProperties(fileSystemTabView, savedSelectionRange, sa
vedScrollLineNumber); |
| 117 }, | 133 }, |
| 118 | 134 |
| 119 /** | 135 /** |
| 120 * @return {!WebInspector.Widget} | 136 * @return {!WebInspector.Widget} |
| 121 */ | 137 */ |
| 122 get view() | 138 get view() |
| 123 { | 139 { |
| 124 return this._tabbedPane; | 140 return this._tabbedPane; |
| 125 }, | 141 }, |
| 126 | 142 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 if (nextTabId) | 324 if (nextTabId) |
| 309 this._tabbedPane.selectTab(nextTabId, true); | 325 this._tabbedPane.selectTab(nextTabId, true); |
| 310 this._tabbedPane.closeTab(id, true); | 326 this._tabbedPane.closeTab(id, true); |
| 311 return true; | 327 return true; |
| 312 } | 328 } |
| 313 return false; | 329 return false; |
| 314 }, | 330 }, |
| 315 | 331 |
| 316 /** | 332 /** |
| 317 * @param {!Array.<string>} ids | 333 * @param {!Array.<string>} ids |
| 334 * @param {boolean=} forceCloseDirtyTabs |
| 318 */ | 335 */ |
| 319 _closeTabs: function(ids) | 336 _closeTabs: function(ids, forceCloseDirtyTabs) |
| 320 { | 337 { |
| 321 var dirtyTabs = []; | 338 var dirtyTabs = []; |
| 322 var cleanTabs = []; | 339 var cleanTabs = []; |
| 323 for (var i = 0; i < ids.length; ++i) { | 340 for (var i = 0; i < ids.length; ++i) { |
| 324 var id = ids[i]; | 341 var id = ids[i]; |
| 325 var uiSourceCode = this._files[id]; | 342 var uiSourceCode = this._files[id]; |
| 326 if (uiSourceCode.isDirty()) | 343 if (!forceCloseDirtyTabs && uiSourceCode.isDirty()) |
| 327 dirtyTabs.push(id); | 344 dirtyTabs.push(id); |
| 328 else | 345 else |
| 329 cleanTabs.push(id); | 346 cleanTabs.push(id); |
| 330 } | 347 } |
| 331 if (dirtyTabs.length) | 348 if (dirtyTabs.length) |
| 332 this._tabbedPane.selectTab(dirtyTabs[0], true); | 349 this._tabbedPane.selectTab(dirtyTabs[0], true); |
| 333 this._tabbedPane.closeTabs(cleanTabs, true); | 350 this._tabbedPane.closeTabs(cleanTabs, true); |
| 334 for (var i = 0; i < dirtyTabs.length; ++i) { | 351 for (var i = 0; i < dirtyTabs.length; ++i) { |
| 335 var nextTabId = i + 1 < dirtyTabs.length ? dirtyTabs[i + 1] : null; | 352 var nextTabId = i + 1 < dirtyTabs.length ? dirtyTabs[i + 1] : null; |
| 336 if (!this._maybeCloseTab(dirtyTabs[i], nextTabId)) | 353 if (!this._maybeCloseTab(dirtyTabs[i], nextTabId)) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 460 |
| 444 /** | 461 /** |
| 445 * @param {!WebInspector.UISourceCode} uiSourceCode | 462 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 446 * @param {boolean=} userGesture | 463 * @param {boolean=} userGesture |
| 447 * @param {number=} index | 464 * @param {number=} index |
| 448 * @return {string} | 465 * @return {string} |
| 449 */ | 466 */ |
| 450 _appendFileTab: function(uiSourceCode, userGesture, index) | 467 _appendFileTab: function(uiSourceCode, userGesture, index) |
| 451 { | 468 { |
| 452 var view = this._delegate.viewForFile(uiSourceCode); | 469 var view = this._delegate.viewForFile(uiSourceCode); |
| 453 var sourceFrame = view instanceof WebInspector.SourceFrame ? /** @type {
!WebInspector.SourceFrame} */ (view) : null; | |
| 454 var title = this._titleForFile(uiSourceCode); | 470 var title = this._titleForFile(uiSourceCode); |
| 455 var tooltip = this._tooltipForFile(uiSourceCode); | 471 var tooltip = this._tooltipForFile(uiSourceCode); |
| 456 | 472 |
| 457 var tabId = this._generateTabId(); | 473 var tabId = this._generateTabId(); |
| 458 this._tabIds.set(uiSourceCode, tabId); | 474 this._tabIds.set(uiSourceCode, tabId); |
| 459 this._files[tabId] = uiSourceCode; | 475 this._files[tabId] = uiSourceCode; |
| 460 | 476 |
| 461 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url(
)); | 477 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url(
)); |
| 462 if (sourceFrame && savedSelectionRange) | |
| 463 sourceFrame.setSelection(savedSelectionRange); | |
| 464 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.
url()); | 478 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.
url()); |
| 465 if (sourceFrame && savedScrollLineNumber) | 479 this._restoreEditorProperties(view, savedSelectionRange, savedScrollLine
Number); |
| 466 sourceFrame.scrollToLine(savedScrollLineNumber); | |
| 467 | 480 |
| 468 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, und
efined, index); | 481 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, und
efined, index); |
| 469 | 482 |
| 470 this._updateFileTitle(uiSourceCode); | 483 this._updateFileTitle(uiSourceCode); |
| 471 this._addUISourceCodeListeners(uiSourceCode); | 484 this._addUISourceCodeListeners(uiSourceCode); |
| 472 return tabId; | 485 return tabId; |
| 473 }, | 486 }, |
| 474 | 487 |
| 475 /** | 488 /** |
| 489 * @param {!WebInspector.Widget} editorView |
| 490 * @param {!WebInspector.TextRange=} selection |
| 491 * @param {number=} firstLineNumber |
| 492 */ |
| 493 _restoreEditorProperties: function(editorView, selection, firstLineNumber) |
| 494 { |
| 495 var sourceFrame = editorView instanceof WebInspector.SourceFrame ? /** @
type {!WebInspector.SourceFrame} */ (editorView) : null; |
| 496 if (!sourceFrame) |
| 497 return; |
| 498 if (selection) |
| 499 sourceFrame.setSelection(selection); |
| 500 if (typeof firstLineNumber === "number") |
| 501 sourceFrame.scrollToLine(firstLineNumber); |
| 502 }, |
| 503 |
| 504 /** |
| 476 * @param {!WebInspector.Event} event | 505 * @param {!WebInspector.Event} event |
| 477 */ | 506 */ |
| 478 _tabClosed: function(event) | 507 _tabClosed: function(event) |
| 479 { | 508 { |
| 480 var tabId = /** @type {string} */ (event.data.tabId); | 509 var tabId = /** @type {string} */ (event.data.tabId); |
| 481 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); | 510 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); |
| 482 | 511 |
| 483 var uiSourceCode = this._files[tabId]; | 512 var uiSourceCode = this._files[tabId]; |
| 484 if (this._currentFile === uiSourceCode) { | 513 if (this._currentFile === uiSourceCode) { |
| 485 this._removeViewListeners(); | 514 this._removeViewListeners(); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 /** | 833 /** |
| 805 * @override | 834 * @override |
| 806 * @param {string} tabId | 835 * @param {string} tabId |
| 807 * @param {!WebInspector.ContextMenu} contextMenu | 836 * @param {!WebInspector.ContextMenu} contextMenu |
| 808 */ | 837 */ |
| 809 onContextMenu: function(tabId, contextMenu) | 838 onContextMenu: function(tabId, contextMenu) |
| 810 { | 839 { |
| 811 this._editorContainer._onContextMenu(tabId, contextMenu); | 840 this._editorContainer._onContextMenu(tabId, contextMenu); |
| 812 } | 841 } |
| 813 } | 842 } |
| OLD | NEW |