pull/85/head
Ruben Daniels 2015-04-30 22:30:29 +00:00
rodzic c78aba36b7
commit 290a9bf71d
7 zmienionych plików z 86 dodań i 39 usunięć

Wyświetl plik

@ -34,10 +34,10 @@ define(function(require, exports, module) {
var msgId = generateMessageId(); var msgId = generateMessageId();
var done; var done;
stream.write(JSON.stringify({ jstream.write({
id: msgId, id: msgId,
message: message message: message
})); });
jstream.on("data", function(payload){ jstream.on("data", function(payload){
if (payload.id == msgId && !done) { if (payload.id == msgId && !done) {

Wyświetl plik

@ -89,10 +89,10 @@ module.exports = function (vfs, options, register) {
sent = true; sent = true;
}, },
onData: function(data){ onData: function(data){
stream.emit("data", data); stream && stream.emit("data", data);
}, },
onError: function(err){ onError: function(err){
stream.emit("error", err); stream && stream.emit("error", err);
} }
}; };

Wyświetl plik

@ -42,12 +42,17 @@ define(function(require, exports, module) {
}); });
stream.on("data", function(payload) { stream.on("data", function(payload) {
var response = emit("message", { message: payload.message }); emit("message", {
message: payload.message,
respond: function(err, message){
stream.write({ stream.write({
id: payload.id, id: payload.id,
message: response message: message,
error: err
}); });
}
});
}); });
stream.on("close", function(){ stream.on("close", function(){
@ -63,7 +68,7 @@ define(function(require, exports, module) {
function write(json){ function write(json){
if (!stream) return false; if (!stream) return false;
stream.write(JSON.stringify(json)); stream.write(json);
return true; return true;
} }

Wyświetl plik

@ -4,18 +4,20 @@ define(function(require, exports, module) {
"Plugin", "bridge", "tabManager", "panels", "Plugin", "bridge", "tabManager", "panels",
"tree.favorites", "tree", "fs" "tree.favorites", "tree", "fs"
]; ];
main.provides = ["bridge_commands"]; main.provides = ["bridge.commands"];
return main; return main;
function main(options, imports, register) { function main(options, imports, register) {
var Plugin = imports.Plugin; var Plugin = imports.Plugin;
var bridge = imports.bridge; var bridge = imports.bridge;
var tabs = imports.tabManager; var tabManager = imports.tabManager;
var panels = imports.panels; var panels = imports.panels;
var tree = imports.tree; var tree = imports.tree;
var favs = imports["tree.favorites"]; var favs = imports["tree.favorites"];
var fs = imports.fs; var fs = imports.fs;
var async = require("async");
/***** Initialization *****/ /***** Initialization *****/
var plugin = new Plugin("Ajax.org", main.consumes); var plugin = new Plugin("Ajax.org", main.consumes);
@ -29,28 +31,36 @@ define(function(require, exports, module) {
switch (message.type) { switch (message.type) {
case "open": case "open":
open(message); open(message, e.respond);
return true; break;
case "ping": case "ping":
return true; e.respond(null, true);
break;
default: default:
return false; console.error("Unknown Bridge Command: ", message.type);
break;
} }
}, plugin); }, plugin);
} }
/***** Methods *****/ /***** Methods *****/
function open(message) { function open(message, callback) {
message.paths.forEach(function(info, i) { var i = -1;
var tabs = [];
async.each(message.paths, function(info, next) {
var path = info.path; var path = info.path;
i++;
// Make sure file is inside workspace // Make sure file is inside workspace
if (path.charAt(0) !== "~") {
if (path.substr(0, BASEPATH.length) !== BASEPATH) if (path.substr(0, BASEPATH.length) !== BASEPATH)
return; return; // Dont' call callback. Perhaps another client will pick this up.
// Remove base path // Remove base path
path = path.substr(BASEPATH.length); path = path.substr(BASEPATH.length);
}
if (info.type == "directory") { if (info.type == "directory") {
path = path.replace(/\/$/, ""); path = path.replace(/\/$/, "");
@ -62,23 +72,42 @@ define(function(require, exports, module) {
tree.expand(path, function() { tree.expand(path, function() {
tree.select(node); //path || "/"); tree.select(node); //path || "/");
tree.scrollToSelection(); tree.scrollToSelection();
next();
}); });
tree.focus(); tree.focus();
} }
else { else {
tabs.once("ready", function(){ tabManager.once("ready", function(){
fs.exists(path, function(existing) { fs.exists(path, function(existing) {
tabs.open({ var tab = tabManager.open({
path: path, path: path,
active: i === 0, active: i === 0,
document: document:
existing existing
? undefined ? undefined
: { meta : { newfile: true } } : { meta : { newfile: true } }
}, function(){}); }, function(){
next();
});
if (message.wait) {
tab.on("close", function(){
tabs.splice(tabs.indexOf(tab), 1);
if (!tabs.length)
callback(null, true);
});
}
tabs.push(tab);
}); });
}); });
} }
}, function(err){
if (err)
return callback(err);
if (!message.wait || !tabs.length)
callback(null, true);
}); });
} }
@ -100,7 +129,7 @@ define(function(require, exports, module) {
plugin.freezePublicAPI({}); plugin.freezePublicAPI({});
register(null, { register(null, {
"bridge_commands": plugin "bridge.commands": plugin
}); });
} }
}); });

Wyświetl plik

@ -3,7 +3,7 @@ define(function(require, exports, module) {
var EventEmitter = require("events").EventEmitter; var EventEmitter = require("events").EventEmitter;
module.exports = function(stream) { module.exports = function(stream) {
var emit = this.emit; var emit = this.emit.bind(this);
var buffer = ""; var buffer = "";
stream.on("data", function(chunk) { stream.on("data", function(chunk) {
@ -12,14 +12,14 @@ module.exports = function(stream) {
var parts = buffer.split("\n"); var parts = buffer.split("\n");
while (parts.length) { while (parts.length) {
try { try {
var message = JSON.parse(buffer[0]); var message = JSON.parse(parts[0]);
emit("data", { message: message }); emit("data", message);
buffer.shift(); parts.shift();
} }
catch (e) { catch (e) {
if (parts.length !== 1) { if (parts.length !== 1) {
emit("error", e); emit("error", e);
buffer.shift(); parts.shift();
} }
else { else {
break; break;
@ -30,16 +30,16 @@ module.exports = function(stream) {
}); });
stream.on("error", function(err){ stream.on("error", function(err){
emit("error", err) emit("error", err);
}); });
stream.on("close", function(data){ stream.on("close", function(data){
emit("close", data); emit("close", data);
}); });
this.write = function(data){ this.write = function(data) {
stream.write(JSON.stringify(data)); stream.write(JSON.stringify(data) + "\n");
} };
}; };
module.exports.prototype = new EventEmitter(); module.exports.prototype = new EventEmitter();

Wyświetl plik

@ -25,8 +25,13 @@ define(function(require, exports, module) {
cmd.addCommand({ cmd.addCommand({
name: "open", name: "open",
info: " Opens a file or directory.", info: " Opens a file or directory.",
usage: "<path>", usage: "[--wait] <path>",
options: { options: {
"wait": {
description: "Wait until the file(s) are closed",
"default": false,
"boolean": true
},
"path" : { "path" : {
description: "Specify the path that will be opened", description: "Specify the path that will be opened",
default: false default: false
@ -39,6 +44,7 @@ define(function(require, exports, module) {
exec: function(argv) { exec: function(argv) {
open( open(
argv._.slice(1), // Remove "open" from the paths argv._.slice(1), // Remove "open" from the paths
argv.wait,
function(){}); function(){});
} }
}); });
@ -46,12 +52,16 @@ define(function(require, exports, module) {
/***** Methods *****/ /***** Methods *****/
function open(paths, callback) { function open(paths, wait, callback) {
try { try {
paths = paths.map(function(path) { paths = paths.map(function(path) {
var isDir = fs.existsSync(path) && fs.statSync(path).isDirectory(); var isDir = fs.existsSync(path) && fs.statSync(path).isDirectory();
path = PATH.resolve(path);
if (path.substr(0, process.env.HOME.length) == process.env.HOME)
path = "~" + path.substr(process.env.HOME.length);
return { return {
path: "/" + PATH.resolve(path), path: path,
type: isDir ? "directory" : "file" type: isDir ? "directory" : "file"
}; };
}); });
@ -65,6 +75,7 @@ define(function(require, exports, module) {
paths.forEach(function(info) { paths.forEach(function(info) {
var path = info.type == "directory" var path = info.type == "directory"
? info.path : PATH.dirname(info.path); ? info.path : PATH.dirname(info.path);
if (!last) { if (!last) {
last = path; last = path;
} }
@ -86,6 +97,7 @@ define(function(require, exports, module) {
var message = { var message = {
type: "open", type: "open",
workspace: "local", workspace: "local",
wait: wait,
// cwd : cwd, // cwd : cwd,
paths: paths paths: paths
}; };

Wyświetl plik

@ -28,6 +28,7 @@ module.exports = function(manifest, installPath) {
var config = { var config = {
standalone: true, standalone: true,
startBridge: true,
manifest: manifest, manifest: manifest,
workspaceDir: workspaceDir, workspaceDir: workspaceDir,
projectName: path.basename(workspaceDir), projectName: path.basename(workspaceDir),