2015-02-10 19:41:24 +00:00
|
|
|
define(function(require, exports, module) {
|
|
|
|
main.consumes = [
|
|
|
|
"Editor", "editors", "ui", "commands", "menus", "layout",
|
2015-09-15 05:22:43 +00:00
|
|
|
"tabManager", "util", "settings", "api", "c9",
|
|
|
|
"preferences.experimental"
|
2015-02-10 19:41:24 +00:00
|
|
|
];
|
2015-04-23 18:07:28 +00:00
|
|
|
main.provides = ["plugin.packages"];
|
2015-02-10 19:41:24 +00:00
|
|
|
return main;
|
|
|
|
|
|
|
|
function main(options, imports, register) {
|
|
|
|
var Editor = imports.Editor;
|
|
|
|
var editors = imports.editors;
|
|
|
|
var tabs = imports.tabManager;
|
|
|
|
var commands = imports.commands;
|
|
|
|
var settings = imports.settings;
|
|
|
|
var api = imports.api;
|
|
|
|
var c9 = imports.c9;
|
|
|
|
var menus = imports.menus;
|
|
|
|
var util = imports.util;
|
|
|
|
var layout = imports.layout;
|
|
|
|
var ui = imports.ui;
|
2015-09-15 05:22:43 +00:00
|
|
|
var experimental = imports["preferences.experimental"];
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
/***** Initialization *****/
|
|
|
|
|
|
|
|
var extensions = [];
|
|
|
|
var packages = {};
|
|
|
|
|
2015-04-23 22:26:16 +00:00
|
|
|
var handle = editors.register("plugin.packages", "Package Browser",
|
|
|
|
PackageBrowser, extensions);
|
2015-02-10 19:41:24 +00:00
|
|
|
var emit = handle.getEmitter();
|
|
|
|
emit.setMaxListeners(1000);
|
|
|
|
|
2016-01-06 12:19:16 +00:00
|
|
|
var DEBUG_MODE = c9.location.indexOf("debug=2") > -1;
|
|
|
|
var HASSDK = DEBUG_MODE || experimental.addExperiment("sdk", false, "SDK/Load Custom Plugins");
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-04-23 18:07:28 +00:00
|
|
|
function focusOpenPackages(){
|
2015-02-10 19:41:24 +00:00
|
|
|
var pages = tabs.getTabs();
|
|
|
|
for (var i = 0, tab = pages[i]; tab; tab = pages[i++]) {
|
2015-04-23 18:07:28 +00:00
|
|
|
if (tab.editorType == "plugin.packages") {
|
2015-02-10 19:41:24 +00:00
|
|
|
tabs.focusTab(tab);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handle.on("load", function(){
|
|
|
|
if (!HASSDK) return;
|
|
|
|
|
|
|
|
settings.on("read", function(){
|
|
|
|
settings.setDefaults("user/general", [["animateui", true]]);
|
|
|
|
});
|
|
|
|
|
|
|
|
commands.addCommand({
|
2015-04-23 22:26:16 +00:00
|
|
|
name: "openpackagebrowser",
|
|
|
|
hint: "open the package browser",
|
2015-02-10 19:41:24 +00:00
|
|
|
group: "General",
|
|
|
|
// bindKey: { mac: "Command-,", win: "Ctrl-," },
|
|
|
|
exec: function () {
|
|
|
|
var tab = tabs.focussedTab;
|
2015-04-23 18:07:28 +00:00
|
|
|
if (tab && tab.editor.type == "plugin.packages") {
|
2015-02-10 19:41:24 +00:00
|
|
|
tab.close();
|
|
|
|
return;
|
|
|
|
}
|
2015-04-23 18:07:28 +00:00
|
|
|
if (focusOpenPackages())
|
2015-02-10 19:41:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
tabs.open({
|
2015-04-23 18:07:28 +00:00
|
|
|
editorType: "plugin.packages",
|
2015-02-10 19:41:24 +00:00
|
|
|
active: true
|
|
|
|
}, function(){});
|
|
|
|
}
|
|
|
|
}, handle);
|
|
|
|
|
2015-05-07 14:14:01 +00:00
|
|
|
// menus.addItemByPath("Cloud9/~", new ui.divider(), 1000, handle);
|
|
|
|
// menus.addItemByPath("Cloud9/Package Browser", new ui.item({
|
|
|
|
// command: "openpackagebrowser"
|
|
|
|
// }), 1100, handle);
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/***** Methods *****/
|
|
|
|
|
|
|
|
function installPlugin(name, target, callback){
|
|
|
|
var config = packages[name];
|
|
|
|
if (!config)
|
|
|
|
return callback(new Error("Could not find plugin: " + name));
|
|
|
|
|
|
|
|
if (target != "project" && target != "user")
|
|
|
|
return callback(new Error("Invalid installation target: " + target));
|
|
|
|
|
|
|
|
api[target].put("install/" + name, function(err, state){
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function uninstallPlugin(name, target, callback){
|
|
|
|
var config = packages[name];
|
|
|
|
if (!config)
|
|
|
|
return callback(new Error("Could not find plugin: " + name));
|
|
|
|
|
|
|
|
if (target != "project" && target != "user")
|
|
|
|
return callback(new Error("Invalid installation target: " + target));
|
|
|
|
|
|
|
|
api[target].put("uninstall/" + name, function(err, state){
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/***** Register and define API *****/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @extends Plugin
|
|
|
|
* @singleton
|
|
|
|
*/
|
|
|
|
handle.freezePublicAPI({
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
installPlugin: installPlugin,
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
uninstallPlugin: uninstallPlugin
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Editor *****/
|
|
|
|
|
2015-04-23 22:26:16 +00:00
|
|
|
function PackageBrowser(){
|
2015-02-10 19:41:24 +00:00
|
|
|
var plugin = new Editor("Ajax.org", main.consumes, extensions);
|
|
|
|
//var emit = plugin.getEmitter();
|
2015-04-23 22:26:16 +00:00
|
|
|
var tab, iframe;
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
plugin.on("resize", function(e) {
|
|
|
|
emit("resize", e);
|
|
|
|
});
|
|
|
|
|
|
|
|
plugin.on("draw", function(e) {
|
|
|
|
tab = e.tab;
|
|
|
|
var htmlNode = e.htmlNode;
|
|
|
|
|
2015-04-24 00:34:07 +00:00
|
|
|
htmlNode.style.paddingTop = 0;
|
|
|
|
|
2015-04-23 22:26:16 +00:00
|
|
|
iframe = htmlNode.appendChild(document.createElement("iframe"));
|
|
|
|
iframe.style.width = "100%";
|
|
|
|
iframe.style.height = "100%";
|
|
|
|
iframe.style.border = 0;
|
2015-04-24 00:34:07 +00:00
|
|
|
iframe.style.backgroundColor = "#fbfbfb";
|
2015-04-23 22:26:16 +00:00
|
|
|
|
2015-04-24 00:34:07 +00:00
|
|
|
iframe.src = location.origin.replace("ide.", "") + "/profile/packages?nobar=1&pid=" + c9.projectId;
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
plugin.on("getState", function(e) {
|
|
|
|
});
|
|
|
|
plugin.on("setState", function(e) {
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Lifecycle *****/
|
|
|
|
|
|
|
|
plugin.on("documentLoad", function(e) {
|
|
|
|
var doc = e.doc;
|
2015-04-23 22:27:36 +00:00
|
|
|
doc.title = "Package Browser";
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
function setTheme(){
|
2015-04-24 00:34:07 +00:00
|
|
|
var bg = "#fbfbfb";
|
2015-04-23 22:28:43 +00:00
|
|
|
doc.tab.backgroundColor = bg;
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
if (util.shadeColor(bg, 1).isLight)
|
|
|
|
doc.tab.classList.remove("dark");
|
|
|
|
else
|
|
|
|
doc.tab.classList.add("dark");
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.on("themeChange", setTheme, e.doc);
|
|
|
|
setTheme();
|
|
|
|
});
|
|
|
|
|
|
|
|
plugin.on("documentActivate", function(e) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/***** Register and define API *****/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @extends Editor
|
|
|
|
*/
|
|
|
|
plugin.freezePublicAPI({
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-23 18:07:28 +00:00
|
|
|
plugin.load(null, "plugin.packages");
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
register(null, {
|
2015-04-23 18:07:28 +00:00
|
|
|
"plugin.packages": handle
|
2015-02-10 19:41:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|