From 21939df44de1705786c545cd1bf519d47250322d Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Tue, 11 May 2010 18:35:50 +0100 Subject: Merge Webkit at r58956: Initial merge by Git. Change-Id: I1d9fb60ea2c3f2ddc04c17a871acdb39353be228 --- WebCore/inspector/front-end/SourceView.js | 55 ++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 12 deletions(-) (limited to 'WebCore/inspector/front-end/SourceView.js') diff --git a/WebCore/inspector/front-end/SourceView.js b/WebCore/inspector/front-end/SourceView.js index 9fbd161..3621187 100644 --- a/WebCore/inspector/front-end/SourceView.js +++ b/WebCore/inspector/front-end/SourceView.js @@ -32,7 +32,8 @@ WebInspector.SourceView = function(resource) this.element.addStyleClass("source"); - this.sourceFrame = new WebInspector.SourceFrame(this.contentElement, this._addBreakpoint.bind(this), this._removeBreakpoint.bind(this)); + var canEditScripts = WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script; + this.sourceFrame = new WebInspector.SourceFrame(this.contentElement, this._addBreakpoint.bind(this), this._removeBreakpoint.bind(this), canEditScripts ? this._editLine.bind(this) : null); resource.addEventListener("finished", this._resourceLoadingFinished, this); this._frameNeedsSetup = true; } @@ -77,6 +78,11 @@ WebInspector.SourceView.prototype = { WebInspector.getResourceContent(this.resource.identifier, this._contentLoaded.bind(this)); }, + hasContentTab: function() + { + return true; + }, + contentTabSelected: function() { this.setupSourceFrameIfNeeded(); @@ -105,17 +111,7 @@ WebInspector.SourceView.prototype = { _addBreakpoint: function(line) { - var sourceID = null; - var closestStartingLine = 0; - var scripts = this.resource.scripts; - for (var i = 0; i < scripts.length; ++i) { - var script = scripts[i]; - if (script.startingLine <= line && script.startingLine >= closestStartingLine) { - closestStartingLine = script.startingLine; - sourceID = script.sourceID; - } - } - + var sourceID = this._sourceIDForLine(line); if (WebInspector.panels.scripts) { var breakpoint = new WebInspector.Breakpoint(this.resource.url, line, sourceID); WebInspector.panels.scripts.addBreakpoint(breakpoint); @@ -128,6 +124,41 @@ WebInspector.SourceView.prototype = { WebInspector.panels.scripts.removeBreakpoint(breakpoint); }, + _editLine: function(line, newContent) + { + var lines = []; + var textModel = this.sourceFrame.textModel; + for (var i = 0; i < textModel.linesCount; ++i) { + if (i === line) + lines.push(newContent); + else + lines.push(textModel.line(i)); + } + + var linesCountToShift = newContent.split("\n").length - 1; + WebInspector.panels.scripts.editScriptSource(this._sourceIDForLine(line), lines.join("\n"), line, linesCountToShift, this._editLineComplete.bind(this)); + }, + + _editLineComplete: function(newBody) + { + this.sourceFrame.updateContent(newBody); + }, + + _sourceIDForLine: function(line) + { + var sourceID = null; + var closestStartingLine = 0; + var scripts = this.resource.scripts; + for (var i = 0; i < scripts.length; ++i) { + var script = scripts[i]; + if (script.startingLine <= line && script.startingLine >= closestStartingLine) { + closestStartingLine = script.startingLine; + sourceID = script.sourceID; + } + } + return sourceID; + }, + // The rest of the methods in this prototype need to be generic enough to work with a ScriptView. // The ScriptView prototype pulls these methods into it's prototype to avoid duplicate code. -- cgit v1.1