2015-02-14 22:00:58 +00:00
|
|
|
|
2015-02-10 19:41:24 +00:00
|
|
|
define(function(require, exports, module) {
|
|
|
|
main.consumes = [
|
2015-05-01 01:53:12 +00:00
|
|
|
"Plugin", "bridge", "tabManager", "panels", "tree.favorites", "tree",
|
2015-05-01 08:13:47 +00:00
|
|
|
"fs", "preferences", "settings", "c9"
|
2015-02-10 19:41:24 +00:00
|
|
|
];
|
2015-04-30 22:30:29 +00:00
|
|
|
main.provides = ["bridge.commands"];
|
2015-02-10 19:41:24 +00:00
|
|
|
return main;
|
|
|
|
|
|
|
|
function main(options, imports, register) {
|
|
|
|
var Plugin = imports.Plugin;
|
|
|
|
var bridge = imports.bridge;
|
2015-04-30 22:30:29 +00:00
|
|
|
var tabManager = imports.tabManager;
|
2015-02-10 19:41:24 +00:00
|
|
|
var panels = imports.panels;
|
|
|
|
var tree = imports.tree;
|
2015-05-01 01:53:12 +00:00
|
|
|
var settings = imports.settings;
|
2015-02-10 19:41:24 +00:00
|
|
|
var favs = imports["tree.favorites"];
|
|
|
|
var fs = imports.fs;
|
2015-05-01 08:13:47 +00:00
|
|
|
var c9 = imports.c9;
|
2015-05-01 01:53:12 +00:00
|
|
|
var prefs = imports.preferences;
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-04-30 22:30:29 +00:00
|
|
|
var async = require("async");
|
|
|
|
|
2015-02-10 19:41:24 +00:00
|
|
|
/***** Initialization *****/
|
|
|
|
|
|
|
|
var plugin = new Plugin("Ajax.org", main.consumes);
|
|
|
|
// var emit = plugin.getEmitter();
|
|
|
|
|
|
|
|
var BASEPATH = options.basePath;
|
|
|
|
|
|
|
|
function load(){
|
|
|
|
bridge.on("message", function(e) {
|
|
|
|
var message = e.message;
|
|
|
|
|
|
|
|
switch (message.type) {
|
|
|
|
case "open":
|
2015-04-30 22:30:29 +00:00
|
|
|
open(message, e.respond);
|
|
|
|
break;
|
2016-02-12 19:09:59 +00:00
|
|
|
case "pipe":
|
|
|
|
createPipe(message, e.respond);
|
|
|
|
break;
|
|
|
|
case "pipeData":
|
|
|
|
updatePipe(message, e.respond);
|
|
|
|
break;
|
|
|
|
case "pipeClosed":
|
|
|
|
closePipe(message, e.respond);
|
|
|
|
break;
|
2015-02-10 19:41:24 +00:00
|
|
|
case "ping":
|
2015-04-30 22:30:29 +00:00
|
|
|
e.respond(null, true);
|
|
|
|
break;
|
2015-04-30 04:01:13 +00:00
|
|
|
default:
|
2015-11-25 10:56:50 +00:00
|
|
|
if (message.type)
|
|
|
|
console.error("Unknown Bridge Command: ", message.type);
|
2015-04-30 22:30:29 +00:00
|
|
|
break;
|
2015-02-10 19:41:24 +00:00
|
|
|
}
|
2015-04-30 04:01:13 +00:00
|
|
|
}, plugin);
|
2015-05-01 01:53:12 +00:00
|
|
|
|
|
|
|
settings.on("read", function(e) {
|
|
|
|
settings.setDefaults("user/terminal", [
|
2015-05-11 13:02:09 +00:00
|
|
|
["defaultEnvEditor", "false"]
|
2015-05-01 01:53:12 +00:00
|
|
|
]);
|
|
|
|
}, plugin);
|
|
|
|
|
|
|
|
prefs.add({
|
|
|
|
"Editors" : {
|
|
|
|
"Terminal" : {
|
|
|
|
"Use Cloud9 as the Default Editor" : {
|
|
|
|
type: "checkbox",
|
2015-05-11 13:02:09 +00:00
|
|
|
path: "user/terminal/@defaultEnvEditor",
|
2015-05-01 01:53:12 +00:00
|
|
|
position: 14000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, plugin);
|
2015-02-10 19:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***** Methods *****/
|
2016-02-12 19:09:59 +00:00
|
|
|
var pipeTab;
|
|
|
|
var pipeClosed = true;
|
|
|
|
|
|
|
|
function createPipe(message, callback) {
|
|
|
|
if(pipeClosed)
|
|
|
|
{
|
|
|
|
tabManager.once("ready", function(){
|
|
|
|
tabManager.open({focus:true, editorType: "ace"}, function(err, tab){
|
|
|
|
pipeTab = tab;
|
|
|
|
pipeTab.document.value += "";
|
|
|
|
pipeClosed = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePipe(message, callback){
|
|
|
|
console.log(message.data);
|
|
|
|
pipeTab.document.value += message.data.toString();;
|
|
|
|
}
|
|
|
|
|
|
|
|
function closePipe(message, callback){
|
|
|
|
pipeClosed = true;
|
|
|
|
}
|
|
|
|
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-04-30 22:30:29 +00:00
|
|
|
function open(message, callback) {
|
|
|
|
var i = -1;
|
|
|
|
var tabs = [];
|
2015-05-01 08:13:47 +00:00
|
|
|
BASEPATH = c9.toInternalPath(BASEPATH);
|
|
|
|
|
2015-04-30 22:30:29 +00:00
|
|
|
async.each(message.paths, function(info, next) {
|
2015-02-10 19:41:24 +00:00
|
|
|
var path = info.path;
|
2015-04-30 22:30:29 +00:00
|
|
|
i++;
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-05-01 08:13:47 +00:00
|
|
|
path = c9.toInternalPath(path);
|
2015-02-10 19:41:24 +00:00
|
|
|
// Make sure file is inside workspace
|
2015-04-30 22:30:29 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
if (info.type == "directory") {
|
|
|
|
path = path.replace(/\/$/, "");
|
|
|
|
|
|
|
|
panels.activate("tree");
|
|
|
|
|
|
|
|
var node = favs.addFavorite(path);
|
|
|
|
|
2015-04-30 04:01:13 +00:00
|
|
|
tree.expand(path, function() {
|
2015-02-10 19:41:24 +00:00
|
|
|
tree.select(node); //path || "/");
|
|
|
|
tree.scrollToSelection();
|
2015-04-30 22:30:29 +00:00
|
|
|
next();
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
tree.focus();
|
|
|
|
}
|
|
|
|
else {
|
2015-04-30 22:30:29 +00:00
|
|
|
tabManager.once("ready", function(){
|
2015-02-10 19:41:24 +00:00
|
|
|
fs.exists(path, function(existing) {
|
2015-04-30 22:30:29 +00:00
|
|
|
var tab = tabManager.open({
|
2015-02-10 19:41:24 +00:00
|
|
|
path: path,
|
2015-06-09 12:15:19 +00:00
|
|
|
focus: i === 0,
|
|
|
|
document: existing
|
|
|
|
? undefined
|
|
|
|
: { meta : { newfile: true } }
|
2015-04-30 22:30:29 +00:00
|
|
|
}, function(){
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (message.wait) {
|
|
|
|
tab.on("close", function(){
|
|
|
|
tabs.splice(tabs.indexOf(tab), 1);
|
|
|
|
if (!tabs.length)
|
|
|
|
callback(null, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
tabs.push(tab);
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-04-30 22:30:29 +00:00
|
|
|
}, function(err){
|
|
|
|
if (err)
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
if (!message.wait || !tabs.length)
|
|
|
|
callback(null, true);
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Lifecycle *****/
|
|
|
|
|
|
|
|
plugin.on("load", function(){
|
|
|
|
load();
|
|
|
|
});
|
|
|
|
|
|
|
|
plugin.on("unload", function(){
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Register and define API *****/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bridge To Communicate from CLI to IDE
|
|
|
|
**/
|
|
|
|
plugin.freezePublicAPI({});
|
|
|
|
|
|
|
|
register(null, {
|
2015-04-30 22:30:29 +00:00
|
|
|
"bridge.commands": plugin
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|