kopia lustrzana https://github.com/c9/core
Almost working
rodzic
c78aba36b7
commit
290a9bf71d
|
@ -34,10 +34,10 @@ define(function(require, exports, module) {
|
|||
var msgId = generateMessageId();
|
||||
var done;
|
||||
|
||||
stream.write(JSON.stringify({
|
||||
jstream.write({
|
||||
id: msgId,
|
||||
message: message
|
||||
}));
|
||||
});
|
||||
|
||||
jstream.on("data", function(payload){
|
||||
if (payload.id == msgId && !done) {
|
||||
|
|
|
@ -89,10 +89,10 @@ module.exports = function (vfs, options, register) {
|
|||
sent = true;
|
||||
},
|
||||
onData: function(data){
|
||||
stream.emit("data", data);
|
||||
stream && stream.emit("data", data);
|
||||
},
|
||||
onError: function(err){
|
||||
stream.emit("error", err);
|
||||
stream && stream.emit("error", err);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -42,12 +42,17 @@ define(function(require, exports, module) {
|
|||
});
|
||||
|
||||
stream.on("data", function(payload) {
|
||||
var response = emit("message", { message: payload.message });
|
||||
|
||||
stream.write({
|
||||
id: payload.id,
|
||||
message: response
|
||||
emit("message", {
|
||||
message: payload.message,
|
||||
respond: function(err, message){
|
||||
stream.write({
|
||||
id: payload.id,
|
||||
message: message,
|
||||
error: err
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
stream.on("close", function(){
|
||||
|
@ -63,7 +68,7 @@ define(function(require, exports, module) {
|
|||
|
||||
function write(json){
|
||||
if (!stream) return false;
|
||||
stream.write(JSON.stringify(json));
|
||||
stream.write(json);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,18 +4,20 @@ define(function(require, exports, module) {
|
|||
"Plugin", "bridge", "tabManager", "panels",
|
||||
"tree.favorites", "tree", "fs"
|
||||
];
|
||||
main.provides = ["bridge_commands"];
|
||||
main.provides = ["bridge.commands"];
|
||||
return main;
|
||||
|
||||
function main(options, imports, register) {
|
||||
var Plugin = imports.Plugin;
|
||||
var bridge = imports.bridge;
|
||||
var tabs = imports.tabManager;
|
||||
var tabManager = imports.tabManager;
|
||||
var panels = imports.panels;
|
||||
var tree = imports.tree;
|
||||
var favs = imports["tree.favorites"];
|
||||
var fs = imports.fs;
|
||||
|
||||
var async = require("async");
|
||||
|
||||
/***** Initialization *****/
|
||||
|
||||
var plugin = new Plugin("Ajax.org", main.consumes);
|
||||
|
@ -29,28 +31,36 @@ define(function(require, exports, module) {
|
|||
|
||||
switch (message.type) {
|
||||
case "open":
|
||||
open(message);
|
||||
return true;
|
||||
open(message, e.respond);
|
||||
break;
|
||||
case "ping":
|
||||
return true;
|
||||
e.respond(null, true);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
console.error("Unknown Bridge Command: ", message.type);
|
||||
break;
|
||||
}
|
||||
}, plugin);
|
||||
}
|
||||
|
||||
/***** Methods *****/
|
||||
|
||||
function open(message) {
|
||||
message.paths.forEach(function(info, i) {
|
||||
function open(message, callback) {
|
||||
var i = -1;
|
||||
var tabs = [];
|
||||
|
||||
async.each(message.paths, function(info, next) {
|
||||
var path = info.path;
|
||||
i++;
|
||||
|
||||
// Make sure file is inside workspace
|
||||
if (path.substr(0, BASEPATH.length) !== BASEPATH)
|
||||
return;
|
||||
|
||||
// Remove base path
|
||||
path = path.substr(BASEPATH.length);
|
||||
if (path.charAt(0) !== "~") {
|
||||
if (path.substr(0, BASEPATH.length) !== BASEPATH)
|
||||
return; // Dont' call callback. Perhaps another client will pick this up.
|
||||
|
||||
// Remove base path
|
||||
path = path.substr(BASEPATH.length);
|
||||
}
|
||||
|
||||
if (info.type == "directory") {
|
||||
path = path.replace(/\/$/, "");
|
||||
|
@ -62,23 +72,42 @@ define(function(require, exports, module) {
|
|||
tree.expand(path, function() {
|
||||
tree.select(node); //path || "/");
|
||||
tree.scrollToSelection();
|
||||
next();
|
||||
});
|
||||
tree.focus();
|
||||
}
|
||||
else {
|
||||
tabs.once("ready", function(){
|
||||
tabManager.once("ready", function(){
|
||||
fs.exists(path, function(existing) {
|
||||
tabs.open({
|
||||
var tab = tabManager.open({
|
||||
path: path,
|
||||
active: i === 0,
|
||||
document:
|
||||
existing
|
||||
? undefined
|
||||
: { 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({});
|
||||
|
||||
register(null, {
|
||||
"bridge_commands": plugin
|
||||
"bridge.commands": plugin
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ define(function(require, exports, module) {
|
|||
var EventEmitter = require("events").EventEmitter;
|
||||
|
||||
module.exports = function(stream) {
|
||||
var emit = this.emit;
|
||||
var emit = this.emit.bind(this);
|
||||
|
||||
var buffer = "";
|
||||
stream.on("data", function(chunk) {
|
||||
|
@ -12,14 +12,14 @@ module.exports = function(stream) {
|
|||
var parts = buffer.split("\n");
|
||||
while (parts.length) {
|
||||
try {
|
||||
var message = JSON.parse(buffer[0]);
|
||||
emit("data", { message: message });
|
||||
buffer.shift();
|
||||
var message = JSON.parse(parts[0]);
|
||||
emit("data", message);
|
||||
parts.shift();
|
||||
}
|
||||
catch (e) {
|
||||
if (parts.length !== 1) {
|
||||
emit("error", e);
|
||||
buffer.shift();
|
||||
parts.shift();
|
||||
}
|
||||
else {
|
||||
break;
|
||||
|
@ -30,16 +30,16 @@ module.exports = function(stream) {
|
|||
});
|
||||
|
||||
stream.on("error", function(err){
|
||||
emit("error", err)
|
||||
emit("error", err);
|
||||
});
|
||||
|
||||
stream.on("close", function(data){
|
||||
emit("close", data);
|
||||
});
|
||||
|
||||
this.write = function(data){
|
||||
stream.write(JSON.stringify(data));
|
||||
}
|
||||
this.write = function(data) {
|
||||
stream.write(JSON.stringify(data) + "\n");
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.prototype = new EventEmitter();
|
||||
|
|
|
@ -25,8 +25,13 @@ define(function(require, exports, module) {
|
|||
cmd.addCommand({
|
||||
name: "open",
|
||||
info: " Opens a file or directory.",
|
||||
usage: "<path>",
|
||||
usage: "[--wait] <path>",
|
||||
options: {
|
||||
"wait": {
|
||||
description: "Wait until the file(s) are closed",
|
||||
"default": false,
|
||||
"boolean": true
|
||||
},
|
||||
"path" : {
|
||||
description: "Specify the path that will be opened",
|
||||
default: false
|
||||
|
@ -39,6 +44,7 @@ define(function(require, exports, module) {
|
|||
exec: function(argv) {
|
||||
open(
|
||||
argv._.slice(1), // Remove "open" from the paths
|
||||
argv.wait,
|
||||
function(){});
|
||||
}
|
||||
});
|
||||
|
@ -46,12 +52,16 @@ define(function(require, exports, module) {
|
|||
|
||||
/***** Methods *****/
|
||||
|
||||
function open(paths, callback) {
|
||||
function open(paths, wait, callback) {
|
||||
try {
|
||||
paths = paths.map(function(path) {
|
||||
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 {
|
||||
path: "/" + PATH.resolve(path),
|
||||
path: path,
|
||||
type: isDir ? "directory" : "file"
|
||||
};
|
||||
});
|
||||
|
@ -65,6 +75,7 @@ define(function(require, exports, module) {
|
|||
paths.forEach(function(info) {
|
||||
var path = info.type == "directory"
|
||||
? info.path : PATH.dirname(info.path);
|
||||
|
||||
if (!last) {
|
||||
last = path;
|
||||
}
|
||||
|
@ -86,6 +97,7 @@ define(function(require, exports, module) {
|
|||
var message = {
|
||||
type: "open",
|
||||
workspace: "local",
|
||||
wait: wait,
|
||||
// cwd : cwd,
|
||||
paths: paths
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@ module.exports = function(manifest, installPath) {
|
|||
|
||||
var config = {
|
||||
standalone: true,
|
||||
startBridge: true,
|
||||
manifest: manifest,
|
||||
workspaceDir: workspaceDir,
|
||||
projectName: path.basename(workspaceDir),
|
||||
|
|
Ładowanie…
Reference in New Issue