Commit da6a56e7 authored by vsevik@chromium.org's avatar vsevik@chromium.org

DevTools: Extract SourcesEditor from SourcesPanel.

This extracts everything related to our tabbed editor from the sources panel to the separate SourcesEditor class.
This class could be later refactored into the view that could be embedded in other places (e.g. Drawer).

R=pfeldman, lushnikov

Review URL: https://codereview.chromium.org/206063003

git-svn-id: svn://svn.chromium.org/blink/trunk@169653 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6c9aff08
......@@ -256,7 +256,7 @@ InspectorTest.waitForScriptSource = function(scriptName, callback)
}
}
InspectorTest.addSniffer(WebInspector.SourcesPanel.prototype, "_addUISourceCode", InspectorTest.waitForScriptSource.bind(InspectorTest, scriptName, callback));
InspectorTest.addSniffer(WebInspector.SourcesEditor.prototype, "_addUISourceCode", InspectorTest.waitForScriptSource.bind(InspectorTest, scriptName, callback));
};
InspectorTest.dumpNavigatorView = function(navigatorView, id, prefix)
......@@ -393,7 +393,7 @@ InspectorTest.checkUILocation = function(uiSourceCode, lineNumber, columnNumber,
InspectorTest.scriptFormatter = function()
{
var editorActions = WebInspector.moduleManager.instances(WebInspector.SourcesPanel.EditorAction);
var editorActions = WebInspector.moduleManager.instances(WebInspector.SourcesEditor.EditorAction);
for (var i = 0; i < editorActions.length; ++i) {
if (editorActions[i] instanceof WebInspector.ScriptFormatterEditorAction)
return editorActions[i];
......
......@@ -10,15 +10,18 @@ function test()
{
WebInspector.inspectorView.showPanel("sources");
var panel = WebInspector.panels.sources;
var sourcesEditor = panel._sourcesEditor;
var historyManager = sourcesEditor._historyManager;
var editorContainer = sourcesEditor._editorContainer;
function rollback()
{
panel._historyManager.rollback();
historyManager.rollback();
}
function rollover()
{
panel._historyManager.rollover();
historyManager.rollover();
}
function dumpSelection(editor, label)
......@@ -158,8 +161,8 @@ function test()
function testCloseCrossFile(next)
{
var selectedTab = panel._editorContainer._tabbedPane.selectedTabId;
panel._editorContainer._tabbedPane.closeTab(selectedTab);
var selectedTab = editorContainer._tabbedPane.selectedTabId;
editorContainer._tabbedPane.closeTab(selectedTab);
dumpSelection(panel.visibleView.textEditor, "Close active tab");
for (var i = 0; i < 1; ++i) {
rollback();
......
......@@ -14,7 +14,6 @@ function test()
function testSourceFramesCount(next)
{
var panel = WebInspector.panels.sources;
var select = panel._navigator._filesSelectElement;
var sourceFrameCount = 0;
InspectorTest.showScriptSource("source-frame-count.html", step2);
......@@ -49,7 +48,7 @@ function test()
function didShowScriptSourceAgain()
{
InspectorTest.assertTrue(panel._editorContainer.visibleView._uiSourceCode.originURL().indexOf("script3.js") !== -1);
InspectorTest.assertTrue(panel.visibleView._uiSourceCode.originURL().indexOf("script3.js") !== -1);
// There should be maximum 3 source frames shown:
// - first one is the first shown (first tab added)
// - second one is the last viewed ("script2.js")
......
......@@ -157,6 +157,7 @@
'front_end/SourceFrame.js',
'front_end/SourceMap.js',
'front_end/SourceMapping.js',
'front_end/SourcesEditor.js',
'front_end/Spectrum.js',
'front_end/SplitView.js',
'front_end/StackView.js',
......
......@@ -30,12 +30,12 @@
/**
* @constructor
* @param {!WebInspector.SourcesPanel} sourcesPanel
* @param {!WebInspector.SourcesEditor} sourcesEditor
* @param {!function():?WebInspector.SourceFrame} currentSourceFrameCallback
*/
WebInspector.EditingLocationHistoryManager = function(sourcesPanel, currentSourceFrameCallback)
WebInspector.EditingLocationHistoryManager = function(sourcesEditor, currentSourceFrameCallback)
{
this._sourcesPanel = sourcesPanel;
this._sourcesEditor = sourcesEditor;
this._historyManager = new WebInspector.SimpleHistoryManager(WebInspector.EditingLocationHistoryManager.HistoryDepth);
this._currentSourceFrameCallback = currentSourceFrameCallback;
}
......@@ -99,7 +99,7 @@ WebInspector.EditingLocationHistoryManager.prototype = {
var sourceFrame = this._currentSourceFrameCallback();
if (!sourceFrame)
return;
var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesPanel, this, sourceFrame, selection);
var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesEditor, this, sourceFrame, selection);
active.merge(entry);
},
......@@ -111,7 +111,7 @@ WebInspector.EditingLocationHistoryManager.prototype = {
var sourceFrame = this._currentSourceFrameCallback();
if (!sourceFrame)
return;
var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesPanel, this, sourceFrame, selection);
var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesEditor, this, sourceFrame, selection);
this._historyManager.push(entry);
},
......@@ -133,14 +133,14 @@ WebInspector.EditingLocationHistoryManager.prototype = {
/**
* @constructor
* @implements {WebInspector.HistoryEntry}
* @param {!WebInspector.SourcesPanel} sourcesPanel
* @param {!WebInspector.SourcesEditor} sourcesEditor
* @param {!WebInspector.EditingLocationHistoryManager} editingLocationManager
* @param {!WebInspector.SourceFrame} sourceFrame
* @param {!WebInspector.TextRange} selection
*/
WebInspector.EditingLocationHistoryEntry = function(sourcesPanel, editingLocationManager, sourceFrame, selection)
WebInspector.EditingLocationHistoryEntry = function(sourcesEditor, editingLocationManager, sourceFrame, selection)
{
this._sourcesPanel = sourcesPanel;
this._sourcesEditor = sourcesEditor;
this._editingLocationManager = editingLocationManager;
var uiSourceCode = sourceFrame.uiSourceCode();
this._projectId = uiSourceCode.project().id();
......@@ -191,6 +191,6 @@ WebInspector.EditingLocationHistoryEntry.prototype = {
return;
this._editingLocationManager.updateCurrentState();
this._sourcesPanel.showUISourceCode(uiSourceCode, position.lineNumber, position.columnNumber);
this._sourcesEditor.showSourceLocation(uiSourceCode, position.lineNumber, position.columnNumber);
}
};
......@@ -716,7 +716,7 @@ WebInspector.ExtensionServer.prototype = {
startColumn: textRange.startColumn,
endLine: textRange.endLine,
endColumn: textRange.endColumn,
url: sourcesPanel.tabbedEditorContainer.currentFile().uri()
url: sourcesPanel.sourcesEditor().currentUISourceCode().uri()
};
return selection;
......
......@@ -492,16 +492,14 @@ WebInspector.SelectionDialogContentProvider.prototype = {
/**
* @constructor
* @extends {WebInspector.SelectionDialogContentProvider}
* @param {!WebInspector.View} view
* @param {!WebInspector.UISourceCode} uiSourceCode
* @param {function(number, number)} selectItemCallback
*/
WebInspector.JavaScriptOutlineDialog = function(view, uiSourceCode, selectItemCallback)
WebInspector.JavaScriptOutlineDialog = function(uiSourceCode, selectItemCallback)
{
WebInspector.SelectionDialogContentProvider.call(this);
this._functionItems = [];
this._view = view;
this._selectItemCallback = selectItemCallback;
this._outlineWorker = new Worker("ScriptFormatterWorker.js");
this._outlineWorker.onmessage = this._didBuildOutlineChunk.bind(this);
......@@ -517,7 +515,7 @@ WebInspector.JavaScriptOutlineDialog.show = function(view, uiSourceCode, selectI
{
if (WebInspector.Dialog.currentInstance())
return null;
var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(new WebInspector.JavaScriptOutlineDialog(view, uiSourceCode, selectItemCallback));
var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(new WebInspector.JavaScriptOutlineDialog(uiSourceCode, selectItemCallback));
WebInspector.Dialog.show(view.element, filteredItemSelectionDialog);
}
......@@ -768,13 +766,13 @@ WebInspector.SelectUISourceCodeDialog.prototype = {
/**
* @constructor
* @extends {WebInspector.SelectUISourceCodeDialog}
* @param {!WebInspector.SourcesPanel} panel
* @param {!WebInspector.SourcesEditor} sourcesEditor
* @param {!Map.<!WebInspector.UISourceCode, number>=} defaultScores
*/
WebInspector.OpenResourceDialog = function(panel, defaultScores)
WebInspector.OpenResourceDialog = function(sourcesEditor, defaultScores)
{
WebInspector.SelectUISourceCodeDialog.call(this, defaultScores);
this._panel = panel;
this._sourcesEditor = sourcesEditor;
}
WebInspector.OpenResourceDialog.prototype = {
......@@ -787,10 +785,10 @@ WebInspector.OpenResourceDialog.prototype = {
uiSourceCodeSelected: function(uiSourceCode, lineNumber, columnNumber)
{
if (!uiSourceCode)
uiSourceCode = this._panel.currentUISourceCode();
uiSourceCode = this._sourcesEditor.currentUISourceCode();
if (!uiSourceCode)
return;
this._panel.showUISourceCode(uiSourceCode, lineNumber, columnNumber);
this._sourcesEditor.showSourceLocation(uiSourceCode, lineNumber, columnNumber);
},
/**
......@@ -815,17 +813,17 @@ WebInspector.OpenResourceDialog.prototype = {
}
/**
* @param {!WebInspector.SourcesPanel} panel
* @param {!WebInspector.SourcesEditor} sourcesEditor
* @param {!Element} relativeToElement
* @param {string=} query
* @param {!Map.<!WebInspector.UISourceCode, number>=} defaultScores
*/
WebInspector.OpenResourceDialog.show = function(panel, relativeToElement, query, defaultScores)
WebInspector.OpenResourceDialog.show = function(sourcesEditor, relativeToElement, query, defaultScores)
{
if (WebInspector.Dialog.currentInstance())
return;
var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(new WebInspector.OpenResourceDialog(panel, defaultScores));
var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(new WebInspector.OpenResourceDialog(sourcesEditor, defaultScores));
filteredItemSelectionDialog.renderAsTwoRows();
if (query)
filteredItemSelectionDialog.setQuery(query);
......
......@@ -5,7 +5,7 @@
/**
* @constructor
* @implements {WebInspector.SourcesPanel.EditorAction}
* @implements {WebInspector.SourcesEditor.EditorAction}
*/
WebInspector.InplaceFormatterEditorAction = function()
{
......@@ -40,17 +40,17 @@ WebInspector.InplaceFormatterEditorAction.prototype = {
},
/**
* @param {!WebInspector.SourcesPanel} panel
* @param {!WebInspector.SourcesEditor} sourcesEditor
* @return {!Element}
*/
button: function(panel)
button: function(sourcesEditor)
{
if (this._button)
return this._button.element;
this._panel = panel;
this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorSelected, this._editorSelected.bind(this));
this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorClosed, this._editorClosed.bind(this));
this._sourcesEditor = sourcesEditor;
this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.EditorSelected, this._editorSelected.bind(this));
this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.EditorClosed, this._editorClosed.bind(this));
this._button = new WebInspector.StatusBarButton(WebInspector.UIString("Format"), "sources-toggle-pretty-print-status-bar-item");
this._button.toggled = false;
......@@ -74,7 +74,7 @@ WebInspector.InplaceFormatterEditorAction.prototype = {
_formatSourceInPlace: function()
{
var uiSourceCode = this._panel.selectedUISourceCode();
var uiSourceCode = this._sourcesEditor.currentUISourceCode();
if (!this._isFormattable(uiSourceCode))
return;
......@@ -102,14 +102,14 @@ WebInspector.InplaceFormatterEditorAction.prototype = {
{
if (uiSourceCode.workingCopy() === formattedContent)
return;
var sourceFrame = this._panel.viewForFile(uiSourceCode);
var sourceFrame = this._sourcesEditor.viewForFile(uiSourceCode);
var start = [0, 0];
if (sourceFrame) {
var selection = sourceFrame.selection();
start = formatterMapping.originalToFormatted(selection.startLine, selection.startColumn);
}
uiSourceCode.setWorkingCopy(formattedContent);
this._panel.showUISourceCode(uiSourceCode, start[0], start[1]);
this._sourcesEditor.showSourceLocation(uiSourceCode, start[0], start[1]);
}
},
}
......@@ -262,7 +262,7 @@ WebInspector.FormatterProjectDelegate.prototype = {
/**
* @constructor
* @implements {WebInspector.SourcesPanel.EditorAction}
* @implements {WebInspector.SourcesEditor.EditorAction}
*/
WebInspector.ScriptFormatterEditorAction = function()
{
......@@ -301,17 +301,17 @@ WebInspector.ScriptFormatterEditorAction.prototype = {
},
/**
* @param {!WebInspector.SourcesPanel} panel
* @param {!WebInspector.SourcesEditor} sourcesEditor
* @return {!Element}
*/
button: function(panel)
button: function(sourcesEditor)
{
if (this._button)
return this._button.element;
this._panel = panel;
this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorSelected, this._editorSelected.bind(this));
this._panel.addEventListener(WebInspector.SourcesPanel.Events.EditorClosed, this._editorClosed.bind(this));
this._sourcesEditor = sourcesEditor;
this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.EditorSelected, this._editorSelected.bind(this));
this._sourcesEditor.addEventListener(WebInspector.SourcesEditor.Events.EditorClosed, this._editorClosed.bind(this));
this._button = new WebInspector.StatusBarButton(WebInspector.UIString("Pretty print"), "sources-toggle-pretty-print-status-bar-item");
this._button.toggled = false;
......@@ -338,7 +338,7 @@ WebInspector.ScriptFormatterEditorAction.prototype = {
_toggleFormatScriptSource: function()
{
var uiSourceCode = this._panel.selectedUISourceCode();
var uiSourceCode = this._sourcesEditor.currentUISourceCode();
if (!this._isFormatableScript(uiSourceCode))
return;
this._formatUISourceCodeScript(uiSourceCode);
......@@ -366,15 +366,15 @@ WebInspector.ScriptFormatterEditorAction.prototype = {
{
if (!formattedUISourceCode)
return;
if (uiSourceCode !== this._panel.selectedUISourceCode())
if (uiSourceCode !== this._sourcesEditor.currentUISourceCode())
return;
var sourceFrame = this._panel.viewForFile(uiSourceCode);
var sourceFrame = this._sourcesEditor.viewForFile(uiSourceCode);
var start = [0, 0];
if (sourceFrame) {
var selection = sourceFrame.selection();
start = mapping.originalToFormatted(selection.startLine, selection.startColumn);
}
this._panel.showUISourceCode(formattedUISourceCode, start[0], start[1]);
this._sourcesEditor.showSourceLocation(formattedUISourceCode, start[0], start[1]);
this._updateButton(formattedUISourceCode);
}
},
......
This diff is collapsed.
......@@ -147,11 +147,11 @@ var allDescriptors = [
className: "WebInspector.SourcesPanel.UILocationRevealer"
},
{
type: "@WebInspector.SourcesPanel.EditorAction",
type: "@WebInspector.SourcesEditor.EditorAction",
className: "WebInspector.InplaceFormatterEditorAction"
},
{
type: "@WebInspector.SourcesPanel.EditorAction",
type: "@WebInspector.SourcesEditor.EditorAction",
className: "WebInspector.ScriptFormatterEditorAction"
},
{
......
......@@ -273,6 +273,7 @@
"ScopeChainSidebarPane.js",
"ScriptFormatter.js",
"SimpleHistoryManager.js",
"SourcesEditor.js",
"SourcesNavigator.js",
"SourcesPanel.js",
"SourcesSearchScope.js",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment