Modified: trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js (106010 => 106011)
--- trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js 2012-01-26 18:42:50 UTC (rev 106010)
+++ trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js 2012-01-26 18:45:10 UTC (rev 106011)
@@ -26,6 +26,7 @@
/**
* @constructor
+ * @implements {WebInspector.EditorContainerDelegate}
* @extends {WebInspector.Panel}
*/
WebInspector.ScriptsPanel = function(presentationModel)
@@ -77,20 +78,20 @@
this.editorView.installResizer(this._navigatorResizeWidgetElement);
this.editorView.sidebarElement.appendChild(this._navigatorResizeWidgetElement);
- this._editorContainer = new WebInspector.TabbedEditorContainer();
+ this._editorContainer = new WebInspector.TabbedEditorContainer(this);
this._editorContainer.show(this.editorView.mainElement);
WebInspector.OpenResourceDialog.install(this, this._presentationModel, this.editorView.mainElement);
} else {
this._fileSelector = new WebInspector.ScriptsPanel.ComboBoxFileSelector(this._presentationModel);
this._fileSelector.show(this.splitView.mainElement);
- this._editorContainer = new WebInspector.ScriptsPanel.SingleFileEditorContainer();
+ this._editorContainer = new WebInspector.ScriptsPanel.SingleFileEditorContainer(this);
this._editorContainer.show(this.splitView.mainElement);
WebInspector.OpenResourceDialog.install(this, this._presentationModel, this.splitView.mainElement);
}
this._fileSelector.addEventListener(WebInspector.ScriptsPanel.FileSelector.Events.FileSelected, this._fileSelected, this);
this._fileSelector.addEventListener(WebInspector.ScriptsPanel.FileSelector.Events.ReleasedFocusAfterSelection, this._fileSelectorReleasedFocus, this);
- this._editorContainer.addEventListener(WebInspector.ScriptsPanel.EditorContainer.Events.EditorSelected, this._editorSelected, this);
+ this._editorContainer.addEventListener(WebInspector.EditorContainer.Events.EditorSelected, this._editorSelected, this);
this.splitView.mainElement.appendChild(this.debugSidebarResizeWidgetElement);
@@ -282,9 +283,7 @@
setScriptSourceIsBeingEdited: function(uiSourceCode, inEditMode)
{
this._fileSelector.setScriptSourceIsDirty(uiSourceCode, inEditMode);
- var sourceFrame = this._sourceFramesByUISourceCode.get(uiSourceCode)
- if (sourceFrame)
- this._editorContainer.setSourceFrameIsDirty(sourceFrame, inEditMode);
+ this._editorContainer.setFileIsDirty(uiSourceCode, inEditMode);
},
_consoleMessagesCleared: function()
@@ -429,7 +428,7 @@
get visibleView()
{
- return this._editorContainer.currentSourceFrame;
+ return this._editorContainer.visibleView;
},
_updateScriptViewStatusBarItems: function()
@@ -484,9 +483,9 @@
*/
_showFile: function(uiSourceCode)
{
- var sourceFrame = this._sourceFramesByUISourceCode.get(uiSourceCode) || this._createSourceFrame(uiSourceCode);
+ var sourceFrame = this._getOrCreateSourceFrame(uiSourceCode);
- this._editorContainer.showSourceFrame(uiSourceCode.displayName, sourceFrame, uiSourceCode.url);
+ this._editorContainer.showFile(uiSourceCode);
this._updateScriptViewStatusBarItems();
if (uiSourceCode.url)
@@ -526,6 +525,7 @@
/**
* @param {WebInspector.UISourceCode} uiSourceCode
+ * @return {WebInspector.SourceFrame}
*/
_createSourceFrame: function(uiSourceCode)
{
@@ -536,6 +536,24 @@
this._sourceFramesByUISourceCode.put(uiSourceCode, sourceFrame);
return sourceFrame;
},
+
+ /**
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @return {WebInspector.SourceFrame}
+ */
+ _getOrCreateSourceFrame: function(uiSourceCode)
+ {
+ return this._sourceFramesByUISourceCode.get(uiSourceCode) || this._createSourceFrame(uiSourceCode);
+ },
+
+ /**
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @return {WebInspector.SourceFrame}
+ */
+ viewForFile: function(uiSourceCode)
+ {
+ return this._getOrCreateSourceFrame(uiSourceCode);
+ },
/**
* @param {WebInspector.UISourceCode} uiSourceCode
@@ -558,38 +576,10 @@
var oldUISourceCodeList = /** @type {Array.<WebInspector.UISourceCode>} */ event.data.oldUISourceCodeList;
var uiSourceCodeList = /** @type {Array.<WebInspector.UISourceCode>} */ event.data.uiSourceCodeList;
- var addedToFileSelector = false;
- var sourceFrames = [];
- for (var i = 0; i < oldUISourceCodeList.length; ++i) {
- var uiSourceCode = oldUISourceCodeList[i];
- var oldSourceFrame = this._sourceFramesByUISourceCode.get(uiSourceCode);
-
- if (this._fileSelector.isScriptSourceAdded(uiSourceCode)) {
- addedToFileSelector = true;
-
- if (oldSourceFrame)
- sourceFrames.push(oldSourceFrame);
- this._removeSourceFrame(uiSourceCode);
- }
- }
-
- if (addedToFileSelector) {
- this._fileSelector.replaceUISourceCodes(oldUISourceCodeList, uiSourceCodeList);
-
- var shouldReplace = false;
- for (var i = 0; i < sourceFrames.length; ++i) {
- if (this._editorContainer.isSourceFrameOpen(sourceFrames[i])) {
- shouldReplace = true;
- break;
- }
- }
-
- if (shouldReplace) {
- var newUISourceCode = uiSourceCodeList[0];
- var sourceFrame = this._sourceFramesByUISourceCode.get(newUISourceCode) || this._createSourceFrame(newUISourceCode);
- this._editorContainer.replaceSourceFrames(sourceFrames, newUISourceCode.displayName, sourceFrame, newUISourceCode.url);
- }
- }
+ this._fileSelector.replaceUISourceCodes(oldUISourceCodeList, uiSourceCodeList);
+ this._editorContainer.replaceFiles(oldUISourceCodeList, uiSourceCodeList);
+ for (var i = 0; i < oldUISourceCodeList.length; ++i)
+ this._removeSourceFrame(oldUISourceCodeList[i]);
},
_sourceFrameLoaded: function(event)
@@ -658,8 +648,8 @@
_editorSelected: function(event)
{
- var sourceFrame = /** @type {WebInspector.SourceFrame} */ event.data;
- this._fileSelector.revealUISourceCode(sourceFrame._uiSourceCode);
+ var uiSourceCode = /** @type {WebInspector.UISourceCode} */ event.data;
+ this._fileSelector.revealUISourceCode(uiSourceCode);
},
_fileSelected: function(event)
@@ -1086,17 +1076,17 @@
/**
* @interface
*/
-WebInspector.ScriptsPanel.EditorContainer = function() { }
+WebInspector.EditorContainer = function() { }
-WebInspector.ScriptsPanel.EditorContainer.Events = {
+WebInspector.EditorContainer.Events = {
EditorSelected: "EditorSelected"
}
-WebInspector.ScriptsPanel.EditorContainer.prototype = {
+WebInspector.EditorContainer.prototype = {
/**
* @type {WebInspector.SourceFrame}
*/
- get currentSourceFrame() { },
+ get visibleView() { },
/**
* @param {Element} element
@@ -1104,33 +1094,36 @@
show: function(element) { },
/**
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
+ * @param {WebInspector.UISourceCode} uiSourceCode
*/
- showSourceFrame: function(title, sourceFrame, tooltip) { },
+ showFile: function(uiSourceCode) { },
/**
- * @param {WebInspector.SourceFrame} sourceFrame
- * @return {boolean}
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @param {boolean} isDirty
*/
- isSourceFrameOpen: function(sourceFrame) { return false; },
+ setFileIsDirty: function(uiSourceCode, isDirty) { },
/**
- * @param {Array.<WebInspector.SourceFrame>} oldSourceFrames
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
+ * @param {Array.<WebInspector.UISourceCode>} oldUISourceCodeList
+ * @param {Array.<WebInspector.UISourceCode>} uiSourceCodeList
*/
- replaceSourceFrames: function(oldSourceFrames, title, sourceFrame, tooltip) { },
+ replaceFiles: function(oldUISourceCodeList, uiSourceCodeList) { },
+
+ reset: function() { }
+}
+/**
+ * @interface
+ */
+WebInspector.EditorContainerDelegate = function() { }
+
+WebInspector.EditorContainerDelegate.prototype = {
/**
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {boolean} isDirty
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @return {WebInspector.SourceFrame}
*/
- setSourceFrameIsDirty: function(sourceFrame, isDirty) { },
-
- reset: function() { }
+ viewForFile: function(uiSourceCode) { }
}
/**
@@ -1235,23 +1228,32 @@
*/
replaceUISourceCodes: function(oldUISourceCodeList, uiSourceCodeList)
{
- var visible = false;
+ var selected = false;
+ var added = false;
var selectedOption = this._filesSelectElement[this._filesSelectElement.selectedIndex];
var selectedUISourceCode = selectedOption ? selectedOption._uiSourceCode : null;
for (var i = 0; i < oldUISourceCodeList.length; ++i) {
var uiSourceCode = oldUISourceCodeList[i];
- if (selectedUISourceCode === oldUISourceCodeList[i])
- visible = true;
var option = uiSourceCode._option;
+ if (!option)
+ continue;
+ added = true;
+
// FIXME: find out why we are getting here with option detached.
- if (option && this._filesSelectElement === option.parentElement)
+ if (this._filesSelectElement === option.parentElement)
this._filesSelectElement.removeChild(option);
+
+ if (selectedUISourceCode === oldUISourceCodeList[i])
+ selected = true;
}
+ if (!added)
+ return;
+
for (var i = 0; i < uiSourceCodeList.length; ++i)
this._addOptionToFilesSelect(uiSourceCodeList[i]);
- if (visible)
+ if (selected)
this._filesSelectElement.selectedIndex = uiSourceCodeList[0]._option.index;
},
@@ -1348,7 +1350,6 @@
select.folderOptions = {};
var option = document.createElement("option");
- option._uiSourceCode = uiSourceCode;
var parsedURL = uiSourceCode.url.asParsedURL();
const indent = WebInspector.isMac() ? "" : "\u00a0\u00a0\u00a0\u00a0";
@@ -1482,12 +1483,14 @@
WebInspector.ScriptsPanel.ComboBoxFileSelector.prototype.__proto__ = WebInspector.Object.prototype;
/**
- * @implements {WebInspector.ScriptsPanel.EditorContainer}
+ * @implements {WebInspector.EditorContainer}
* @extends {WebInspector.Object}
* @constructor
+ * @param {WebInspector.EditorContainerDelegate} delegate
*/
-WebInspector.ScriptsPanel.SingleFileEditorContainer = function()
+WebInspector.ScriptsPanel.SingleFileEditorContainer = function(delegate)
{
+ this._delegate = delegate;
this.element = document.createElement("div");
this.element.className = "scripts-views-container";
}
@@ -1496,7 +1499,7 @@
/**
* @type {WebInspector.SourceFrame}
*/
- get currentSourceFrame()
+ get visibleView()
{
return this._currentSourceFrame;
},
@@ -1508,14 +1511,13 @@
{
element.appendChild(this.element);
},
-
+
/**
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
+ * @param {WebInspector.UISourceCode} uiSourceCode
*/
- showSourceFrame: function(title, sourceFrame, tooltip)
+ showFile: function(uiSourceCode)
{
+ var sourceFrame = this._delegate.viewForFile(uiSourceCode);
if (this._currentSourceFrame === sourceFrame)
return;
@@ -1523,48 +1525,37 @@
this._currentSourceFrame.detach();
this._currentSourceFrame = sourceFrame;
+ this._currentFile = uiSourceCode;
if (sourceFrame)
sourceFrame.show(this.element);
},
/**
- * @param {WebInspector.SourceFrame} sourceFrame
- * @return {boolean}
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @param {boolean} isDirty
*/
- isSourceFrameOpen: function(sourceFrame)
+ setFileIsDirty: function(uiSourceCode, isDirty)
{
- return this._currentSourceFrame && this._currentSourceFrame === sourceFrame;
+ // Do nothing.
},
/**
- * @param {Array.<WebInspector.SourceFrame>} oldSourceFrames
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
+ * @param {Array.<WebInspector.UISourceCode>} oldUISourceCodeList
+ * @param {Array.<WebInspector.UISourceCode>} uiSourceCodeList
*/
- replaceSourceFrames: function(oldSourceFrames, title, sourceFrame, tooltip)
+ replaceFiles: function(oldUISourceCodeList, uiSourceCodeList)
{
- this._currentSourceFrame.detach();
- this._currentSourceFrame = null;
- this.showSourceFrame(title, sourceFrame, tooltip);
+ if (oldUISourceCodeList.indexOf(this._currentFile) !== -1)
+ this.showFile(uiSourceCodeList[0]);
},
- /**
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {boolean} isDirty
- */
- setSourceFrameIsDirty: function(sourceFrame, isDirty)
- {
- // Do nothing.
- },
-
reset: function()
{
- if (this._currentSourceFrame) {
+ if (this._currentSourceFrame)
this._currentSourceFrame.detach();
- this._currentSourceFrame = null;
- }
+ this._currentSourceFrame = null;
+ this._currentFile = null;
}
}
Modified: trunk/Source/WebCore/inspector/front-end/TabbedEditorContainer.js (106010 => 106011)
--- trunk/Source/WebCore/inspector/front-end/TabbedEditorContainer.js 2012-01-26 18:42:50 UTC (rev 106010)
+++ trunk/Source/WebCore/inspector/front-end/TabbedEditorContainer.js 2012-01-26 18:45:10 UTC (rev 106011)
@@ -27,12 +27,15 @@
*/
/**
- * @implements {WebInspector.ScriptsPanel.EditorContainer}
+ * @implements {WebInspector.EditorContainer}
* @extends {WebInspector.Object}
* @constructor
+ * @param {WebInspector.EditorContainerDelegate} delegate
*/
-WebInspector.TabbedEditorContainer = function()
+WebInspector.TabbedEditorContainer = function(delegate)
{
+ this._delegate = delegate;
+
this._tabbedPane = new WebInspector.TabbedPane();
this._tabbedPane.closeableTabs = true;
this._tabbedPane.element.id = "scripts-editor-container-tabbed-pane";
@@ -40,9 +43,8 @@
this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClosed, this._tabClosed, this);
this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
- this._titles = new Map();
- this._tooltips = new Map();
this._tabIds = new Map();
+ this._files = {};
}
WebInspector.TabbedEditorContainer._tabId = 0;
@@ -51,7 +53,7 @@
/**
* @type {WebInspector.SourceFrame}
*/
- get currentSourceFrame()
+ get visibleView()
{
return this._tabbedPane.visibleView;
},
@@ -65,38 +67,55 @@
},
/**
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
+ * @param {WebInspector.UISourceCode} uiSourceCode
*/
- showSourceFrame: function(title, sourceFrame, tooltip)
+ showFile: function(uiSourceCode)
{
- var tabId = this._tabIds.get(sourceFrame) || this._appendSourceFrameTab(title, sourceFrame, tooltip);
+ var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode);
this._tabbedPane.selectTab(tabId);
},
/**
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @return {string}
*/
- _appendSourceFrameTab: function(title, sourceFrame, tooltip)
+ _titleForFile: function(uiSourceCode)
{
+ return uiSourceCode.displayName;
+ },
+
+ /**
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ * @return {string}
+ */
+ _tooltipForFile: function(uiSourceCode)
+ {
+ return uiSourceCode.url;
+ },
+
+ /**
+ * @param {WebInspector.UISourceCode} uiSourceCode
+ */
+ _appendFileTab: function(uiSourceCode)
+ {
+ var view = this._delegate.viewForFile(uiSourceCode);
+ var title = this._titleForFile(uiSourceCode);
+ var tooltip = this._tooltipForFile(uiSourceCode);
+
var tabId = this._generateTabId();
- this._tabIds.put(sourceFrame, tabId)
- this._titles.put(sourceFrame, title)
- this._tooltips.put(sourceFrame, tooltip)
+ this._tabIds.put(uiSourceCode, tabId);
+ this._files[tabId] = uiSourceCode;
- this._tabbedPane.appendTab(tabId, title, sourceFrame, tooltip);
+ this._tabbedPane.appendTab(tabId, title, view, tooltip);
return tabId;
},
/**
- * @param {WebInspector.SourceFrame} sourceFrame
+ * @param {WebInspector.UISourceCode} uiSourceCode
*/
- _removeSourceFrameTab: function(sourceFrame)
+ _removeFileTab: function(uiSourceCode)
{
- var tabId = this._tabIds.get(sourceFrame);
+ var tabId = this._tabIds.get(uiSourceCode);
if (tabId)
this._tabbedPane.closeTab(tabId);
@@ -107,10 +126,9 @@
*/
_tabClosed: function(event)
{
- var sourceFrame = /** @type {WebInspector.UISourceCode} */ event.data.view;
- this._tabIds.remove(sourceFrame);
- this._titles.remove(sourceFrame);
- this._tooltips.remove(sourceFrame);
+ var tabId = /** @type {string} */ event.data.tabId;
+ this._tabIds.remove(this._files[tabId]);
+ delete this._files[tabId];
},
/**
@@ -118,77 +136,63 @@
*/
_tabSelected: function(event)
{
- var sourceFrame = /** @type {WebInspector.UISourceCode} */ event.data.view;
- this.dispatchEventToListeners(WebInspector.ScriptsPanel.EditorContainer.Events.EditorSelected, sourceFrame);
+ var tabId = /** @type {string} */ event.data.tabId;
+ this.dispatchEventToListeners(WebInspector.EditorContainer.Events.EditorSelected, this._files[tabId]);
},
/**
- * @param {WebInspector.SourceFrame} oldSourceFrame
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
+ * @param {WebInspector.UISourceCode} oldUISourceCode
+ * @param {WebInspector.UISourceCode} newUISourceCode
*/
- _replaceSourceFrameTab: function(oldSourceFrame, title, sourceFrame, tooltip)
+ _replaceFileTab: function(oldUISourceCode, newUISourceCode)
{
- var tabId = this._tabIds.get(oldSourceFrame);
+ var tabId = this._tabIds.get(oldUISourceCode);
- if (tabId) {
- this._tabIds.remove(oldSourceFrame);
- this._titles.remove(oldSourceFrame);
- this._tooltips.remove(oldSourceFrame);
+ if (!tabId)
+ return;
+
+ delete this._files[this._tabIds.get(oldUISourceCode)]
+ this._tabIds.remove(oldUISourceCode);
+ this._tabIds.put(newUISourceCode, tabId);
+ this._files[tabId] = newUISourceCode;
- this._tabIds.put(sourceFrame, tabId);
- this._titles.put(sourceFrame, title);
- this._tooltips.put(sourceFrame, tooltip);
-
- this._tabbedPane.changeTabTitle(tabId, title);
- this._tabbedPane.changeTabView(tabId, sourceFrame);
- this._tabbedPane.changeTabTooltip(tabId, tooltip);
- }
+ this._tabbedPane.changeTabTitle(tabId, this._titleForFile(newUISourceCode));
+ this._tabbedPane.changeTabView(tabId, this._delegate.viewForFile(newUISourceCode));
+ this._tabbedPane.changeTabTooltip(tabId, this._tooltipForFile(newUISourceCode));
},
/**
- * @param {WebInspector.SourceFrame} sourceFrame
- * @return {boolean}
+ * @param {Array.<WebInspector.UISourceCode>} oldUISourceCodeList
+ * @param {Array.<WebInspector.UISourceCode>} uiSourceCodeList
*/
- isSourceFrameOpen: function(sourceFrame)
+ replaceFiles: function(oldUISourceCodeList, uiSourceCodeList)
{
- return !!this._tabIds.get(sourceFrame);
- },
-
- /**
- * @param {Array.<WebInspector.SourceFrame>} oldSourceFrames
- * @param {string} title
- * @param {WebInspector.SourceFrame} sourceFrame
- * @param {string} tooltip
- */
- replaceSourceFrames: function(oldSourceFrames, title, sourceFrame, tooltip)
- {
- var mainSourceFrame;
- for (var i = 0; i < oldSourceFrames.length; ++i) {
- var tabId = this._tabIds.get(oldSourceFrames[i]);
- if (tabId && (!mainSourceFrame || this._tabbedPane.selectedTabId === tabId)) {
- mainSourceFrame = oldSourceFrames[i];
+ var mainFile;
+ for (var i = 0; i < oldUISourceCodeList.length; ++i) {
+ var tabId = this._tabIds.get(oldUISourceCodeList[i]);
+ if (tabId && (!mainFile || this._tabbedPane.selectedTabId === tabId)) {
+ mainFile = oldUISourceCodeList[i];
break;
}
}
- if (mainSourceFrame)
- this._replaceSourceFrameTab(mainSourceFrame, title, sourceFrame, tooltip);
+ if (!mainFile)
+ return;
- for (var i = 0; i < oldSourceFrames.length; ++i)
- this._removeSourceFrameTab(oldSourceFrames[i]);
+ this._replaceFileTab(mainFile, uiSourceCodeList[0]);
+ for (var i = 0; i < oldUISourceCodeList.length; ++i)
+ this._removeFileTab(oldUISourceCodeList[i]);
},
-
+
/**
- * @param {WebInspector.SourceFrame} sourceFrame
+ * @param {WebInspector.UISourceCode} uiSourceCode
* @param {boolean} isDirty
*/
- setSourceFrameIsDirty: function(sourceFrame, isDirty)
+ setFileIsDirty: function(uiSourceCode, isDirty)
{
- var tabId = this._tabIds.get(sourceFrame);
+ var tabId = this._tabIds.get(uiSourceCode);
if (tabId) {
- var title = this._titles.get(sourceFrame);
+ var title = this._titleForFile(uiSourceCode);
if (isDirty)
title += "*";
this._tabbedPane.changeTabTitle(tabId, title);
@@ -198,9 +202,9 @@
reset: function()
{
this._tabbedPane.closeAllTabs();
- this._titles = new Map();
- this._tooltips = new Map();
- this._tabIds = new Map();
+ this._tabIds = new Map();
+ this._files = {};
+
},
/**