Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/TabbedEditorContainer.js

Issue 2349343002: DevTools: introduce persistence/ module (Closed)
Patch Set: simplify test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 this._tabbedPane = new WebInspector.TabbedPane(); 54 this._tabbedPane = new WebInspector.TabbedPane();
55 this._tabbedPane.setPlaceholderText(placeholderText); 55 this._tabbedPane.setPlaceholderText(placeholderText);
56 this._tabbedPane.setTabDelegate(new WebInspector.EditorContainerTabDelegate( this)); 56 this._tabbedPane.setTabDelegate(new WebInspector.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(WebInspector.TabbedPane.Events.TabClosed, this._tabClosed, this);
62 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected , this._tabSelected, this); 62 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected , this._tabSelected, this);
63 63
64 WebInspector.persistence.addEventListener(WebInspector.Persistence.Events.Bi ndingCreated, this._onBindingCreated, this);
65 WebInspector.persistence.addEventListener(WebInspector.Persistence.Events.Bi ndingRemoved, this._onBindingRemoved, this);
66
64 this._tabIds = new Map(); 67 this._tabIds = new Map();
65 this._files = {}; 68 this._files = {};
66 69
67 this._previouslyViewedFilesSetting = setting; 70 this._previouslyViewedFilesSetting = setting;
68 this._history = WebInspector.TabbedEditorContainer.History.fromObject(this._ previouslyViewedFilesSetting.get()); 71 this._history = WebInspector.TabbedEditorContainer.History.fromObject(this._ previouslyViewedFilesSetting.get());
69 } 72 }
70 73
71 /** @enum {symbol} */ 74 /** @enum {symbol} */
72 WebInspector.TabbedEditorContainer.Events = { 75 WebInspector.TabbedEditorContainer.Events = {
73 EditorSelected: Symbol("EditorSelected"), 76 EditorSelected: Symbol("EditorSelected"),
74 EditorClosed: Symbol("EditorClosed") 77 EditorClosed: Symbol("EditorClosed")
75 } 78 }
76 79
77 WebInspector.TabbedEditorContainer._tabId = 0; 80 WebInspector.TabbedEditorContainer._tabId = 0;
78 81
79 WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount = 30; 82 WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount = 30;
80 83
81 WebInspector.TabbedEditorContainer.prototype = { 84 WebInspector.TabbedEditorContainer.prototype = {
82 /** 85 /**
86 * @param {!WebInspector.Event} event
87 */
88 _onBindingCreated: function(event)
89 {
90 var binding = /** @type {!WebInspector.PersistenceBinding} */(event.data );
91 var fileSystemTabId = this._tabIds.get(binding.fileSystem);
92 if (!fileSystemTabId)
93 return;
94
95 var isSelected = this._currentFile === binding.fileSystem;
96 var tabIndex = this._tabbedPane.tabIndex(fileSystemTabId);
97 this._closeTabs([fileSystemTabId]);
98 var networkTabId = this._tabIds.get(binding.network);
99 if (networkTabId) {
100 if (isSelected)
101 this._tabbedPane.selectTab(networkTabId, false);
102 return;
103 }
104 var tabId = this._appendFileTab(binding.network, false, tabIndex);
105 if (isSelected)
106 this._tabbedPane.selectTab(tabId, false);
107 },
108
109 /**
110 * @param {!WebInspector.Event} event
111 */
112 _onBindingRemoved: function(event)
113 {
114 var binding = /** @type {!WebInspector.PersistenceBinding} */(event.data );
115 var networkTabId = this._tabIds.get(binding.network);
116 if (!networkTabId)
117 return;
118 this._appendFileTab(binding.fileSystem, false);
119 },
120
121 /**
83 * @return {!WebInspector.Widget} 122 * @return {!WebInspector.Widget}
84 */ 123 */
85 get view() 124 get view()
86 { 125 {
87 return this._tabbedPane; 126 return this._tabbedPane;
88 }, 127 },
89 128
90 /** 129 /**
91 * @type {!WebInspector.Widget} 130 * @type {!WebInspector.Widget}
92 */ 131 */
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 this._history.updateSelectionRange(this._currentFile.url(), range); 247 this._history.updateSelectionRange(this._currentFile.url(), range);
209 this._history.save(this._previouslyViewedFilesSetting); 248 this._history.save(this._previouslyViewedFilesSetting);
210 }, 249 },
211 250
212 /** 251 /**
213 * @param {!WebInspector.UISourceCode} uiSourceCode 252 * @param {!WebInspector.UISourceCode} uiSourceCode
214 * @param {boolean=} userGesture 253 * @param {boolean=} userGesture
215 */ 254 */
216 _innerShowFile: function(uiSourceCode, userGesture) 255 _innerShowFile: function(uiSourceCode, userGesture)
217 { 256 {
257 var binding = WebInspector.persistence.binding(uiSourceCode);
258 uiSourceCode = binding ? binding.network : uiSourceCode;
218 if (this._currentFile === uiSourceCode) 259 if (this._currentFile === uiSourceCode)
219 return; 260 return;
220 261
221 this._removeViewListeners(); 262 this._removeViewListeners();
222 this._currentFile = uiSourceCode; 263 this._currentFile = uiSourceCode;
223 264
224 var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSour ceCode, userGesture); 265 var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSour ceCode, userGesture);
225 266
226 this._tabbedPane.selectTab(tabId, userGesture); 267 this._tabbedPane.selectTab(tabId, userGesture);
227 if (userGesture) 268 if (userGesture)
(...skipping 13 matching lines...) Expand all
241 }, 282 },
242 283
243 /** 284 /**
244 * @param {!WebInspector.UISourceCode} uiSourceCode 285 * @param {!WebInspector.UISourceCode} uiSourceCode
245 * @return {string} 286 * @return {string}
246 */ 287 */
247 _titleForFile: function(uiSourceCode) 288 _titleForFile: function(uiSourceCode)
248 { 289 {
249 var maxDisplayNameLength = 30; 290 var maxDisplayNameLength = 30;
250 var title = uiSourceCode.displayName(true).trimMiddle(maxDisplayNameLeng th); 291 var title = uiSourceCode.displayName(true).trimMiddle(maxDisplayNameLeng th);
251 if (uiSourceCode.isDirty() || uiSourceCode.hasUnsavedCommittedChanges()) 292 if (uiSourceCode.isDirty() || WebInspector.persistence.hasUnsavedCommitt edChanges(uiSourceCode))
252 title += "*"; 293 title += "*";
253 return title; 294 return title;
254 }, 295 },
255 296
256 /** 297 /**
257 * @param {string} id 298 * @param {string} id
258 * @param {string} nextTabId 299 * @param {string} nextTabId
259 */ 300 */
260 _maybeCloseTab: function(id, nextTabId) 301 _maybeCloseTab: function(id, nextTabId)
261 { 302 {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 * @return {string} 437 * @return {string}
397 */ 438 */
398 _tooltipForFile: function(uiSourceCode) 439 _tooltipForFile: function(uiSourceCode)
399 { 440 {
400 return uiSourceCode.url(); 441 return uiSourceCode.url();
401 }, 442 },
402 443
403 /** 444 /**
404 * @param {!WebInspector.UISourceCode} uiSourceCode 445 * @param {!WebInspector.UISourceCode} uiSourceCode
405 * @param {boolean=} userGesture 446 * @param {boolean=} userGesture
447 * @param {number=} index
406 * @return {string} 448 * @return {string}
407 */ 449 */
408 _appendFileTab: function(uiSourceCode, userGesture) 450 _appendFileTab: function(uiSourceCode, userGesture, index)
409 { 451 {
410 var view = this._delegate.viewForFile(uiSourceCode); 452 var view = this._delegate.viewForFile(uiSourceCode);
411 var sourceFrame = view instanceof WebInspector.SourceFrame ? /** @type { !WebInspector.SourceFrame} */ (view) : null; 453 var sourceFrame = view instanceof WebInspector.SourceFrame ? /** @type { !WebInspector.SourceFrame} */ (view) : null;
412 var title = this._titleForFile(uiSourceCode); 454 var title = this._titleForFile(uiSourceCode);
413 var tooltip = this._tooltipForFile(uiSourceCode); 455 var tooltip = this._tooltipForFile(uiSourceCode);
414 456
415 var tabId = this._generateTabId(); 457 var tabId = this._generateTabId();
416 this._tabIds.set(uiSourceCode, tabId); 458 this._tabIds.set(uiSourceCode, tabId);
417 this._files[tabId] = uiSourceCode; 459 this._files[tabId] = uiSourceCode;
418 460
419 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url( )); 461 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url( ));
420 if (sourceFrame && savedSelectionRange) 462 if (sourceFrame && savedSelectionRange)
421 sourceFrame.setSelection(savedSelectionRange); 463 sourceFrame.setSelection(savedSelectionRange);
422 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode. url()); 464 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode. url());
423 if (sourceFrame && savedScrollLineNumber) 465 if (sourceFrame && savedScrollLineNumber)
424 sourceFrame.scrollToLine(savedScrollLineNumber); 466 sourceFrame.scrollToLine(savedScrollLineNumber);
425 467
426 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture); 468 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, und efined, index);
427 469
428 this._updateFileTitle(uiSourceCode); 470 this._updateFileTitle(uiSourceCode);
429 this._addUISourceCodeListeners(uiSourceCode); 471 this._addUISourceCodeListeners(uiSourceCode);
430 return tabId; 472 return tabId;
431 }, 473 },
432 474
433 /** 475 /**
434 * @param {!WebInspector.Event} event 476 * @param {!WebInspector.Event} event
435 */ 477 */
436 _tabClosed: function(event) 478 _tabClosed: function(event)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 531
490 /** 532 /**
491 * @param {!WebInspector.UISourceCode} uiSourceCode 533 * @param {!WebInspector.UISourceCode} uiSourceCode
492 */ 534 */
493 _updateFileTitle: function(uiSourceCode) 535 _updateFileTitle: function(uiSourceCode)
494 { 536 {
495 var tabId = this._tabIds.get(uiSourceCode); 537 var tabId = this._tabIds.get(uiSourceCode);
496 if (tabId) { 538 if (tabId) {
497 var title = this._titleForFile(uiSourceCode); 539 var title = this._titleForFile(uiSourceCode);
498 this._tabbedPane.changeTabTitle(tabId, title); 540 this._tabbedPane.changeTabTitle(tabId, title);
499 if (uiSourceCode.hasUnsavedCommittedChanges()) 541 if (WebInspector.persistence.hasUnsavedCommittedChanges(uiSourceCode ))
500 this._tabbedPane.setTabIcon(tabId, "warning-icon", WebInspector. UIString("Changes to this file were not saved to file system.")); 542 this._tabbedPane.setTabIcon(tabId, "warning-icon", WebInspector. UIString("Changes to this file were not saved to file system."));
501 else 543 else
502 this._tabbedPane.setTabIcon(tabId, ""); 544 this._tabbedPane.setTabIcon(tabId, "");
503 } 545 }
504 }, 546 },
505 547
506 _uiSourceCodeTitleChanged: function(event) 548 _uiSourceCodeTitleChanged: function(event)
507 { 549 {
508 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ et); 550 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ et);
509 this._updateFileTitle(uiSourceCode); 551 this._updateFileTitle(uiSourceCode);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 /** 804 /**
763 * @override 805 * @override
764 * @param {string} tabId 806 * @param {string} tabId
765 * @param {!WebInspector.ContextMenu} contextMenu 807 * @param {!WebInspector.ContextMenu} contextMenu
766 */ 808 */
767 onContextMenu: function(tabId, contextMenu) 809 onContextMenu: function(tabId, contextMenu)
768 { 810 {
769 this._editorContainer._onContextMenu(tabId, contextMenu); 811 this._editorContainer._onContextMenu(tabId, contextMenu);
770 } 812 }
771 } 813 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698