Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1418 from jdiehl/live-development
Browse files Browse the repository at this point in the history
Live development
  • Loading branch information
gruehle committed Aug 28, 2012
2 parents 1c86887 + b5fb39f commit 540b7c4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/LiveDevelopment/Agents/GotoAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ define(function GotoAgent(require, exports, module) {
for (i in node.trace) {
_makeJSTarget(targets, node.trace[i]);
}
for (i in res.matchedCSSRules) {
for (i in node.events) {
var trace = node.events[i];
if (trace.children.length > 0) {
_makeJSTarget(targets, trace.children[0].callFrames[0]);
}
}
for (i in res.matchedCSSRules.reverse()) {
_makeCSSTarget(targets, res.matchedCSSRules[i]);
}
RemoteAgent.call("showGoto", targets);
Expand Down Expand Up @@ -158,7 +164,7 @@ define(function GotoAgent(require, exports, module) {
console.assert(url.substr(0, 7) === "file://", "Cannot open non-file URLs");

var result = new $.Deferred();

url = _urlWithoutQueryString(url);
// Extract the path, also strip the third slash when on Windows
var path = url.slice(brackets.platform === "win" ? 8 : 7);
Expand Down
6 changes: 6 additions & 0 deletions src/LiveDevelopment/Documents/HTMLDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ define(function HTMLDocumentModule(require, exports, module) {
* @param Document the source document from Brackets
*/
var HTMLDocument = function HTMLDocument(doc, editor) {
if (!editor) {
return;
}
this.doc = doc;
this.editor = editor;
this.onHighlight = this.onHighlight.bind(this);
Expand All @@ -66,6 +69,9 @@ define(function HTMLDocumentModule(require, exports, module) {

/** Close the document */
HTMLDocument.prototype.close = function close() {
if (!this.editor) {
return;
}
$(HighlightAgent).off("highlight", this.onHighlight);
$(this.editor).off("change", this.onChange);
$(this.editor).off("cursorActivity", this.onCursorActivity);
Expand Down
16 changes: 13 additions & 3 deletions src/LiveDevelopment/Documents/JSDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ define(function JSDocumentModule(require, exports, module) {
* @param {Document} the source document
*/
var JSDocument = function JSDocument(doc, editor) {
if (!editor) {
return;
}
this.doc = doc;
this.editor = editor;
this.script = ScriptAgent.scriptForURL(this.doc.url);
this.onHighlight = this.onHighlight.bind(this);
this.onChange = this.onChange.bind(this);
this.onCursorActivity = this.onCursorActivity.bind(this);
Expand All @@ -68,12 +70,19 @@ define(function JSDocumentModule(require, exports, module) {

/** Close the document */
JSDocument.prototype.close = function close() {
if (!this.editor) {
return;
}
$(HighlightAgent).off("highlight", this.onHighlight);
$(this.editor).off("change", this.onChange);
$(this.editor).off("cursorActivity", this.onCursorActivity);
this.onHighlight();
};

JSDocument.prototype.script = function script() {
return ScriptAgent.scriptForURL(this.doc.url);
};


/** Event Handlers *******************************************************/

Expand All @@ -84,7 +93,7 @@ define(function JSDocumentModule(require, exports, module) {
/** Triggered on change by the editor */
JSDocument.prototype.onChange = function onChange(event, editor, change) {
var src = this.doc.getText();
Inspector.Debugger.setScriptSource(this.script.scriptId, src, function onSetScriptSource(res) {
Inspector.Debugger.setScriptSource(this.script().scriptId, src, function onSetScriptSource(res) {
Inspector.Runtime.evaluate("if($)$(\"canvas\").each(function(i,e){if(e.rerender)e.rerender()})");
}.bind(this));
};
Expand All @@ -103,10 +112,11 @@ define(function JSDocumentModule(require, exports, module) {
}

// go through the trace and find highlight the lines of this script
var scriptId = this.script().scriptId;
var callFrame, line;
for (i in node.trace) {
callFrame = node.trace[i];
if (callFrame.location && callFrame.location.scriptId === this.script.scriptId) {
if (callFrame.location && callFrame.location.scriptId === scriptId) {
line = callFrame.location.lineNumber;
codeMirror.setLineClass(line, "highlight");
this._highlight.push(line);
Expand Down
30 changes: 20 additions & 10 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,14 @@ define(function LiveDevelopment(require, exports, module) {
switch (doc.extension) {
case "css":
return CSSDocument;
/* FUTURE:
case "js":
return JSDocument;
return exports.config.experimental ? JSDocument : null;
case "html":
case "htm":
return HTMLDocument;
return exports.config.experimental ? HTMLDocument : null;
default:
throw "Invalid document type: " + doc.extension;
*/
return null;
}

return null;
}

/**
Expand Down Expand Up @@ -251,8 +247,16 @@ define(function LiveDevelopment(require, exports, module) {
/** Load the agents */
function loadAgents() {
var name, promises = [];
for (name in _enabledAgentNames) {
if (_enabledAgentNames.hasOwnProperty(name) && agents[name].load) {
var agentsToLoad;
if (exports.config.experimental) {
// load all agents
agentsToLoad = agents;
} else {
// load only enabled agents
agentsToLoad = _enabledAgentNames;
}
for (name in agentsToLoad) {
if (agentsToLoad.hasOwnProperty(name) && agents[name] && agents[name].load) {
promises.push(agents[name].load());
_loadedAgentNames.push(name);
}
Expand Down Expand Up @@ -294,6 +298,11 @@ define(function LiveDevelopment(require, exports, module) {
function _onError(event, error) {
var message = error.message;

// Remove "Uncaught" from the beginning to avoid the inspector popping up
if (message.substr(0, 8) === "Uncaught") {
message = message.substr(9);
}

// Additional information, like exactly which parameter could not be processed.
var data = error.data;
if (Array.isArray(data)) {
Expand Down Expand Up @@ -352,7 +361,8 @@ define(function LiveDevelopment(require, exports, module) {
// For Sprint 6, we only open live development connections for HTML files
// FUTURE: Remove this test when we support opening connections for different
// file types.
if (!doc.extension || doc.extension.indexOf("htm") !== 0) {

if (!exports.config.experimental && (!doc.extension || doc.extension.indexOf('htm') !== 0)) {
showWrongDocError();
return promise;
}
Expand Down
16 changes: 15 additions & 1 deletion src/LiveDevelopment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
/*global define, $, less, window, XMLHttpRequest */
/*global brackets, define, $, less, window, XMLHttpRequest */

/**
* main integrates LiveDevelopment into Brackets
Expand All @@ -40,12 +40,14 @@ define(function main(require, exports, module) {

var DocumentManager = require("document/DocumentManager"),
Commands = require("command/Commands"),
AppInit = require("utils/AppInit"),
LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
Inspector = require("LiveDevelopment/Inspector/Inspector"),
CommandManager = require("command/CommandManager"),
Strings = require("strings");

var config = {
experimental: false, // enable experimental features
debug: true, // enable debug output and helpers
autoconnect: false, // go live automatically after startup?
highlight: false, // enable highlighting?
Expand Down Expand Up @@ -128,6 +130,9 @@ define(function main(require, exports, module) {
// See the comments at the top of LiveDevelopment.js for details on the
// various status codes.
_setLabel(_$btnGoLive, null, _statusStyle[status + 1], _statusTooltip[status + 1]);
if (config.autoconnect) {
window.sessionStorage.setItem("live.enabled", status === 3);
}
});

// Initialize tooltip for 'not connected' state
Expand Down Expand Up @@ -170,6 +175,15 @@ define(function main(require, exports, module) {
if (config.debug) {
_setupDebugHelpers();
}

// trigger autoconnect
if (config.autoconnect && window.sessionStorage.getItem("live.enabled") === "true") {
AppInit.appReady(function () {
if (DocumentManager.getCurrentDocument()) {
_handleGoLiveCommand();
}
});
}
}
window.setTimeout(init);

Expand Down

0 comments on commit 540b7c4

Please sign in to comment.