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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 }, | 243 }, |
228 | 244 |
229 /** | 245 /** |
230 * @param {!WebInspector.Event} event | 246 * @param {!WebInspector.Event} event |
231 */ | 247 */ |
232 _scrollChanged: function(event) | 248 _scrollChanged: function(event) |
233 { | 249 { |
234 if (this._scrollTimer) | 250 if (this._scrollTimer) |
235 clearTimeout(this._scrollTimer); | 251 clearTimeout(this._scrollTimer); |
236 var lineNumber = /** @type {number} */ (event.data); | 252 var lineNumber = /** @type {number} */ (event.data); |
237 this._scrollTimer = setTimeout(updateHistory.bind(this, this._currentFil
e.url(), lineNumber), 100); | 253 this._scrollTimer = setTimeout(saveHistory.bind(this), 100); |
| 254 this._history.updateScrollLineNumber(this._currentFile.url(), lineNumber
); |
238 | 255 |
239 /** | 256 /** |
240 * @param {string} url | |
241 * @param {number} lineNumber | |
242 * @this {WebInspector.TabbedEditorContainer} | 257 * @this {WebInspector.TabbedEditorContainer} |
243 */ | 258 */ |
244 function updateHistory(url, lineNumber) | 259 function saveHistory() |
245 { | 260 { |
246 this._history.updateScrollLineNumber(url, lineNumber); | |
247 this._history.save(this._previouslyViewedFilesSetting); | 261 this._history.save(this._previouslyViewedFilesSetting); |
248 } | 262 } |
249 }, | 263 }, |
250 | 264 |
251 /** | 265 /** |
252 * @param {!WebInspector.Event} event | 266 * @param {!WebInspector.Event} event |
253 */ | 267 */ |
254 _selectionChanged: function(event) | 268 _selectionChanged: function(event) |
255 { | 269 { |
256 var range = /** @type {!WebInspector.TextRange} */ (event.data); | 270 var range = /** @type {!WebInspector.TextRange} */ (event.data); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (nextTabId) | 334 if (nextTabId) |
321 this._tabbedPane.selectTab(nextTabId, true); | 335 this._tabbedPane.selectTab(nextTabId, true); |
322 this._tabbedPane.closeTab(id, true); | 336 this._tabbedPane.closeTab(id, true); |
323 return true; | 337 return true; |
324 } | 338 } |
325 return false; | 339 return false; |
326 }, | 340 }, |
327 | 341 |
328 /** | 342 /** |
329 * @param {!Array.<string>} ids | 343 * @param {!Array.<string>} ids |
| 344 * @param {boolean=} forceCloseDirtyTabs |
330 */ | 345 */ |
331 _closeTabs: function(ids) | 346 _closeTabs: function(ids, forceCloseDirtyTabs) |
332 { | 347 { |
333 var dirtyTabs = []; | 348 var dirtyTabs = []; |
334 var cleanTabs = []; | 349 var cleanTabs = []; |
335 for (var i = 0; i < ids.length; ++i) { | 350 for (var i = 0; i < ids.length; ++i) { |
336 var id = ids[i]; | 351 var id = ids[i]; |
337 var uiSourceCode = this._files[id]; | 352 var uiSourceCode = this._files[id]; |
338 if (uiSourceCode.isDirty()) | 353 if (!forceCloseDirtyTabs && uiSourceCode.isDirty()) |
339 dirtyTabs.push(id); | 354 dirtyTabs.push(id); |
340 else | 355 else |
341 cleanTabs.push(id); | 356 cleanTabs.push(id); |
342 } | 357 } |
343 if (dirtyTabs.length) | 358 if (dirtyTabs.length) |
344 this._tabbedPane.selectTab(dirtyTabs[0], true); | 359 this._tabbedPane.selectTab(dirtyTabs[0], true); |
345 this._tabbedPane.closeTabs(cleanTabs, true); | 360 this._tabbedPane.closeTabs(cleanTabs, true); |
346 for (var i = 0; i < dirtyTabs.length; ++i) { | 361 for (var i = 0; i < dirtyTabs.length; ++i) { |
347 var nextTabId = i + 1 < dirtyTabs.length ? dirtyTabs[i + 1] : null; | 362 var nextTabId = i + 1 < dirtyTabs.length ? dirtyTabs[i + 1] : null; |
348 if (!this._maybeCloseTab(dirtyTabs[i], nextTabId)) | 363 if (!this._maybeCloseTab(dirtyTabs[i], nextTabId)) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 470 |
456 /** | 471 /** |
457 * @param {!WebInspector.UISourceCode} uiSourceCode | 472 * @param {!WebInspector.UISourceCode} uiSourceCode |
458 * @param {boolean=} userGesture | 473 * @param {boolean=} userGesture |
459 * @param {number=} index | 474 * @param {number=} index |
460 * @return {string} | 475 * @return {string} |
461 */ | 476 */ |
462 _appendFileTab: function(uiSourceCode, userGesture, index) | 477 _appendFileTab: function(uiSourceCode, userGesture, index) |
463 { | 478 { |
464 var view = this._delegate.viewForFile(uiSourceCode); | 479 var view = this._delegate.viewForFile(uiSourceCode); |
465 var sourceFrame = view instanceof WebInspector.SourceFrame ? /** @type {
!WebInspector.SourceFrame} */ (view) : null; | |
466 var title = this._titleForFile(uiSourceCode); | 480 var title = this._titleForFile(uiSourceCode); |
467 var tooltip = this._tooltipForFile(uiSourceCode); | 481 var tooltip = this._tooltipForFile(uiSourceCode); |
468 | 482 |
469 var tabId = this._generateTabId(); | 483 var tabId = this._generateTabId(); |
470 this._tabIds.set(uiSourceCode, tabId); | 484 this._tabIds.set(uiSourceCode, tabId); |
471 this._files[tabId] = uiSourceCode; | 485 this._files[tabId] = uiSourceCode; |
472 | 486 |
473 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url(
)); | 487 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url(
)); |
474 if (sourceFrame && savedSelectionRange) | |
475 sourceFrame.setSelection(savedSelectionRange); | |
476 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.
url()); | 488 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.
url()); |
477 if (sourceFrame && savedScrollLineNumber) | 489 this._restoreEditorProperties(view, savedSelectionRange, savedScrollLine
Number); |
478 sourceFrame.scrollToLine(savedScrollLineNumber); | |
479 | 490 |
480 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, und
efined, index); | 491 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, und
efined, index); |
481 | 492 |
482 this._updateFileTitle(uiSourceCode); | 493 this._updateFileTitle(uiSourceCode); |
483 this._addUISourceCodeListeners(uiSourceCode); | 494 this._addUISourceCodeListeners(uiSourceCode); |
484 return tabId; | 495 return tabId; |
485 }, | 496 }, |
486 | 497 |
487 /** | 498 /** |
| 499 * @param {!WebInspector.Widget} editorView |
| 500 * @param {!WebInspector.TextRange=} selection |
| 501 * @param {number=} firstLineNumber |
| 502 */ |
| 503 _restoreEditorProperties: function(editorView, selection, firstLineNumber) |
| 504 { |
| 505 var sourceFrame = editorView instanceof WebInspector.SourceFrame ? /** @
type {!WebInspector.SourceFrame} */ (editorView) : null; |
| 506 if (!sourceFrame) |
| 507 return; |
| 508 if (selection) |
| 509 sourceFrame.setSelection(selection); |
| 510 if (typeof firstLineNumber === "number") |
| 511 sourceFrame.scrollToLine(firstLineNumber); |
| 512 }, |
| 513 |
| 514 /** |
488 * @param {!WebInspector.Event} event | 515 * @param {!WebInspector.Event} event |
489 */ | 516 */ |
490 _tabClosed: function(event) | 517 _tabClosed: function(event) |
491 { | 518 { |
492 var tabId = /** @type {string} */ (event.data.tabId); | 519 var tabId = /** @type {string} */ (event.data.tabId); |
493 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); | 520 var userGesture = /** @type {boolean} */ (event.data.isUserGesture); |
494 | 521 |
495 var uiSourceCode = this._files[tabId]; | 522 var uiSourceCode = this._files[tabId]; |
496 if (this._currentFile === uiSourceCode) { | 523 if (this._currentFile === uiSourceCode) { |
497 this._removeViewListeners(); | 524 this._removeViewListeners(); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 /** | 843 /** |
817 * @override | 844 * @override |
818 * @param {string} tabId | 845 * @param {string} tabId |
819 * @param {!WebInspector.ContextMenu} contextMenu | 846 * @param {!WebInspector.ContextMenu} contextMenu |
820 */ | 847 */ |
821 onContextMenu: function(tabId, contextMenu) | 848 onContextMenu: function(tabId, contextMenu) |
822 { | 849 { |
823 this._editorContainer._onContextMenu(tabId, contextMenu); | 850 this._editorContainer._onContextMenu(tabId, contextMenu); |
824 } | 851 } |
825 }; | 852 }; |
OLD | NEW |