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

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

Issue 2349343002: DevTools: introduce persistence/ module (Closed)
Patch Set: reupload 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 if (this._tabIds.has(binding.network))
99 return;
dgozman 2016/09/23 23:03:21 select if isSelected
lushnikov 2016/09/24 00:30:50 Done.
100 var tabId = this._appendFileTab(binding.network, false, tabIndex);
101 if (isSelected)
102 this._tabbedPane.selectTab(tabId, false);
103 },
104
105 /**
106 * @param {!WebInspector.Event} event
107 */
108 _onBindingRemoved: function(event)
109 {
110 var binding = /** @type {!WebInspector.PersistenceBinding} */(event.data );
111 var networkTabId = this._tabIds.get(binding.network);
112 if (!networkTabId)
113 return;
114 this._appendFileTab(binding.fileSystem, false);
115 },
116
117 /**
83 * @return {!WebInspector.Widget} 118 * @return {!WebInspector.Widget}
84 */ 119 */
85 get view() 120 get view()
86 { 121 {
87 return this._tabbedPane; 122 return this._tabbedPane;
88 }, 123 },
89 124
90 /** 125 /**
91 * @type {!WebInspector.Widget} 126 * @type {!WebInspector.Widget}
92 */ 127 */
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 this._history.updateSelectionRange(this._currentFile.url(), range); 243 this._history.updateSelectionRange(this._currentFile.url(), range);
209 this._history.save(this._previouslyViewedFilesSetting); 244 this._history.save(this._previouslyViewedFilesSetting);
210 }, 245 },
211 246
212 /** 247 /**
213 * @param {!WebInspector.UISourceCode} uiSourceCode 248 * @param {!WebInspector.UISourceCode} uiSourceCode
214 * @param {boolean=} userGesture 249 * @param {boolean=} userGesture
215 */ 250 */
216 _innerShowFile: function(uiSourceCode, userGesture) 251 _innerShowFile: function(uiSourceCode, userGesture)
217 { 252 {
253 var binding = WebInspector.persistence.binding(uiSourceCode);
254 uiSourceCode = binding ? binding.network : uiSourceCode;
dgozman 2016/09/23 23:03:21 Let's add a test for this line.
lushnikov 2016/09/24 00:30:50 Done.
218 if (this._currentFile === uiSourceCode) 255 if (this._currentFile === uiSourceCode)
219 return; 256 return;
220 257
221 this._removeViewListeners(); 258 this._removeViewListeners();
222 this._currentFile = uiSourceCode; 259 this._currentFile = uiSourceCode;
223 260
224 var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSour ceCode, userGesture); 261 var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSour ceCode, userGesture);
225 262
226 this._tabbedPane.selectTab(tabId, userGesture); 263 this._tabbedPane.selectTab(tabId, userGesture);
227 if (userGesture) 264 if (userGesture)
(...skipping 13 matching lines...) Expand all
241 }, 278 },
242 279
243 /** 280 /**
244 * @param {!WebInspector.UISourceCode} uiSourceCode 281 * @param {!WebInspector.UISourceCode} uiSourceCode
245 * @return {string} 282 * @return {string}
246 */ 283 */
247 _titleForFile: function(uiSourceCode) 284 _titleForFile: function(uiSourceCode)
248 { 285 {
249 var maxDisplayNameLength = 30; 286 var maxDisplayNameLength = 30;
250 var title = uiSourceCode.displayName(true).trimMiddle(maxDisplayNameLeng th); 287 var title = uiSourceCode.displayName(true).trimMiddle(maxDisplayNameLeng th);
251 if (uiSourceCode.isDirty() || uiSourceCode.hasUnsavedCommittedChanges()) 288 if (uiSourceCode.isDirty() || WebInspector.persistence.hasUnsavedCommitt edChanges(uiSourceCode))
252 title += "*"; 289 title += "*";
253 return title; 290 return title;
254 }, 291 },
255 292
256 /** 293 /**
257 * @param {string} id 294 * @param {string} id
258 * @param {string} nextTabId 295 * @param {string} nextTabId
259 */ 296 */
260 _maybeCloseTab: function(id, nextTabId) 297 _maybeCloseTab: function(id, nextTabId)
261 { 298 {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 * @return {string} 433 * @return {string}
397 */ 434 */
398 _tooltipForFile: function(uiSourceCode) 435 _tooltipForFile: function(uiSourceCode)
399 { 436 {
400 return uiSourceCode.url(); 437 return uiSourceCode.url();
401 }, 438 },
402 439
403 /** 440 /**
404 * @param {!WebInspector.UISourceCode} uiSourceCode 441 * @param {!WebInspector.UISourceCode} uiSourceCode
405 * @param {boolean=} userGesture 442 * @param {boolean=} userGesture
443 * @param {number=} index
406 * @return {string} 444 * @return {string}
407 */ 445 */
408 _appendFileTab: function(uiSourceCode, userGesture) 446 _appendFileTab: function(uiSourceCode, userGesture, index)
409 { 447 {
410 var view = this._delegate.viewForFile(uiSourceCode); 448 var view = this._delegate.viewForFile(uiSourceCode);
411 var sourceFrame = view instanceof WebInspector.SourceFrame ? /** @type { !WebInspector.SourceFrame} */ (view) : null; 449 var sourceFrame = view instanceof WebInspector.SourceFrame ? /** @type { !WebInspector.SourceFrame} */ (view) : null;
412 var title = this._titleForFile(uiSourceCode); 450 var title = this._titleForFile(uiSourceCode);
413 var tooltip = this._tooltipForFile(uiSourceCode); 451 var tooltip = this._tooltipForFile(uiSourceCode);
414 452
415 var tabId = this._generateTabId(); 453 var tabId = this._generateTabId();
416 this._tabIds.set(uiSourceCode, tabId); 454 this._tabIds.set(uiSourceCode, tabId);
417 this._files[tabId] = uiSourceCode; 455 this._files[tabId] = uiSourceCode;
418 456
419 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url( )); 457 var savedSelectionRange = this._history.selectionRange(uiSourceCode.url( ));
420 if (sourceFrame && savedSelectionRange) 458 if (sourceFrame && savedSelectionRange)
421 sourceFrame.setSelection(savedSelectionRange); 459 sourceFrame.setSelection(savedSelectionRange);
422 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode. url()); 460 var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode. url());
423 if (sourceFrame && savedScrollLineNumber) 461 if (sourceFrame && savedScrollLineNumber)
424 sourceFrame.scrollToLine(savedScrollLineNumber); 462 sourceFrame.scrollToLine(savedScrollLineNumber);
425 463
426 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture); 464 this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, und efined, index);
427 465
428 this._updateFileTitle(uiSourceCode); 466 this._updateFileTitle(uiSourceCode);
429 this._addUISourceCodeListeners(uiSourceCode); 467 this._addUISourceCodeListeners(uiSourceCode);
430 return tabId; 468 return tabId;
431 }, 469 },
432 470
433 /** 471 /**
434 * @param {!WebInspector.Event} event 472 * @param {!WebInspector.Event} event
435 */ 473 */
436 _tabClosed: function(event) 474 _tabClosed: function(event)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 527
490 /** 528 /**
491 * @param {!WebInspector.UISourceCode} uiSourceCode 529 * @param {!WebInspector.UISourceCode} uiSourceCode
492 */ 530 */
493 _updateFileTitle: function(uiSourceCode) 531 _updateFileTitle: function(uiSourceCode)
494 { 532 {
495 var tabId = this._tabIds.get(uiSourceCode); 533 var tabId = this._tabIds.get(uiSourceCode);
496 if (tabId) { 534 if (tabId) {
497 var title = this._titleForFile(uiSourceCode); 535 var title = this._titleForFile(uiSourceCode);
498 this._tabbedPane.changeTabTitle(tabId, title); 536 this._tabbedPane.changeTabTitle(tabId, title);
499 if (uiSourceCode.hasUnsavedCommittedChanges()) 537 if (WebInspector.persistence.hasUnsavedCommittedChanges(uiSourceCode ))
500 this._tabbedPane.setTabIcon(tabId, "warning-icon", WebInspector. UIString("Changes to this file were not saved to file system.")); 538 this._tabbedPane.setTabIcon(tabId, "warning-icon", WebInspector. UIString("Changes to this file were not saved to file system."));
501 else 539 else
502 this._tabbedPane.setTabIcon(tabId, ""); 540 this._tabbedPane.setTabIcon(tabId, "");
503 } 541 }
504 }, 542 },
505 543
506 _uiSourceCodeTitleChanged: function(event) 544 _uiSourceCodeTitleChanged: function(event)
507 { 545 {
508 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ et); 546 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ et);
509 this._updateFileTitle(uiSourceCode); 547 this._updateFileTitle(uiSourceCode);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 /** 800 /**
763 * @override 801 * @override
764 * @param {string} tabId 802 * @param {string} tabId
765 * @param {!WebInspector.ContextMenu} contextMenu 803 * @param {!WebInspector.ContextMenu} contextMenu
766 */ 804 */
767 onContextMenu: function(tabId, contextMenu) 805 onContextMenu: function(tabId, contextMenu)
768 { 806 {
769 this._editorContainer._onContextMenu(tabId, contextMenu); 807 this._editorContainer._onContextMenu(tabId, contextMenu);
770 } 808 }
771 } 809 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698