urls now show a menu

pull/223/head
Ruben Daniels 2015-11-12 19:38:38 +00:00
rodzic 96ef199e6c
commit ac1f51af7e
1 zmienionych plików z 97 dodań i 73 usunięć

Wyświetl plik

@ -30,7 +30,7 @@ define(function(require, exports, module) {
var BASEPATH = options.previewUrl; var BASEPATH = options.previewUrl;
var plugin = new Plugin("Ajax.org", main.consumes); var plugin = new Plugin("Ajax.org", main.consumes);
var menu, lastLink; var menuPath, lastLink;
var reHome = new RegExp("^" + util.escapeRegExp(c9.home)); var reHome = new RegExp("^" + util.escapeRegExp(c9.home));
@ -44,8 +44,8 @@ define(function(require, exports, module) {
ace.hoverLink.on("open", showMenu); ace.hoverLink.on("open", showMenu);
}, plugin); }, plugin);
function createMenu(e) { function createMenu() {
if (menu) if (menuPath)
return; return;
var submenu = new Menu({ var submenu = new Menu({
@ -91,7 +91,7 @@ define(function(require, exports, module) {
new MenuItem({ value: "reveal", caption: "Reveal in File Tree" }) new MenuItem({ value: "reveal", caption: "Reveal in File Tree" })
]; ];
menu = new Menu({ menuPath = new Menu({
items: menuItems, items: menuItems,
onitemclick: function(e) { onitemclick: function(e) {
var info = buildPath(lastLink, true); var info = buildPath(lastLink, true);
@ -117,92 +117,116 @@ define(function(require, exports, module) {
} }
}, plugin); }, plugin);
} }
var menuLink;
function createLinkMenu(){
menuLink = new Menu({
items: [
new MenuItem({ value: "open", caption: "Open" }),
new MenuItem({ value: "open-in-preview", caption: "Open In Preview" }),
new MenuItem({ value: "copy", caption: "Copy" }),
],
onitemclick: function(e) {
if (e.value == "open")
openLink(lastLink.value);
if (e.value == "open-in-preview")
openLink(lastLink.value, true);
else if (e.value == "copy")
commands.exec("copy", null, { data: lastLink.value });
}
}, plugin);
}
/***** Methods *****/ /***** Methods *****/
function showMenu(e) { function showMenu(e) {
if (e.type == "link" && (tabManager.focussedTab || 0).editorType)
return open(e);
if (e.action == "open") if (e.action == "open")
return open(e); return open(e);
createMenu(e);
lastLink = e; lastLink = e;
menu.once("show", function(){ var menu;
var isGit = e && e.command === "git"; if (e.type == "link" && (tabManager.focussedTab || 0).editorType) {
var items = menu.items; createLinkMenu();
for (var i = 0; i < 6; i++) { menu = menuLink;
items[i].aml.visible = -1; }
items[i][isGit ? "show" : "hide"](); else {
} createMenu();
}); menuPath.once("show", function(){
var isGit = e && e.command === "git";
var items = menuPath.items;
for (var i = 0; i < 6; i++) {
items[i].aml.visible = -1;
items[i][isGit ? "show" : "hide"]();
}
});
var ace = e.editor;
menuPath.once("hide", function(){
ace.selection.clearSelection();
});
menu = menuPath;
}
menu.show(e.x, e.y); menu.show(e.x, e.y);
var ace = e.editor;
menu.once("hide", function(){
ace.selection.clearSelection();
});
} }
function open(e, cb) { function openLink(href, inPreview){
if (typeof e == "string") if (!/^(https?|ftp|file):/.test(href)) {
e = {type: "path", value: e}; href = "http://" + href;
if (e.type == "link") {
var href = e.value;
if (!/(https?|ftp|file):/.test(href)) {
href = "http://" + href;
}
href = href.replace(/(^https?:\/\/)(0.0.0.0|localhost)(?=:|\/|$)/, function(_, protocol, host) {
host = c9.hostname || window.location.host;
return protocol + host.replace(/:\d+/, "");
});
if (e.metaKey || e.ctrlKey)
window.open(href);
else
commands.exec("preview", null, { path: href });
} }
else if (e.type == "path") { href = href.replace(/(^https?:\/\/)(0.0.0.0|localhost)(?=:|\/|$)/, function(_, protocol, host) {
var info = buildPath(e); host = c9.hostname || window.location.host;
var path = info.path; return protocol + host.replace(/:\d+/, "");
});
if (inPreview)
commands.exec("preview", null, { path: href });
else
window.open(href);
}
function open(e) {
if (e.type == "link")
return openLink(e.value);
var m = /:(\d*)(?::(\d*))?$/.exec(path); var info = buildPath(e);
var jump = {}; var path = info.path;
if (m) {
if (m[1]) var m = /:(\d*)(?::(\d*))?$/.exec(path);
jump.row = parseInt(m[1], 10) - 1; var jump = {};
if (m[2]) if (m) {
jump.column = parseInt(m[2], 10); if (m[1])
path = path.slice(0, m.index); jump.row = parseInt(m[1], 10) - 1;
if (m[2])
jump.column = parseInt(m[2], 10);
path = path.slice(0, m.index);
}
// Make sure home dir is marked correctly
path = path.replace(reHome, "~");
if (path[0] != "/") path = "/" + path;
fs.stat(path, function(err, stat) {
if (err) {
return commands.exec("navigate", null, { keyword: path });
} }
if (stat.linkStat)
// Make sure home dir is marked correctly stat = stat.linkStat;
path = path.replace(reHome, "~"); if (/directory/.test(stat.mime)) {
if (path[0] != "/") path = "/" + path; return tabbehavior.revealtab({path: path});
}
fs.stat(path, function(err, stat) { tabManager.open({
if (err) { path: path,
return commands.exec("navigate", null, { keyword: path }); focus: true,
} document: {
if (stat.linkStat) ace: {
stat = stat.linkStat; jump: jump
if (/directory/.test(stat.mime)) {
return tabbehavior.revealtab({path: path});
}
tabManager.open({
path: path,
focus: true,
document: {
ace: {
jump: jump
}
} }
}, cb); }
}); }, function(){});
} });
} }
function buildPath(e) { function buildPath(e) {