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);
@ -118,54 +118,79 @@ 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;
if (e.type == "link" && (tabManager.focussedTab || 0).editorType) {
createLinkMenu();
menu = menuLink;
}
else {
createMenu();
menuPath.once("show", function(){
var isGit = e && e.command === "git"; var isGit = e && e.command === "git";
var items = menu.items; var items = menuPath.items;
for (var i = 0; i < 6; i++) { for (var i = 0; i < 6; i++) {
items[i].aml.visible = -1; items[i].aml.visible = -1;
items[i][isGit ? "show" : "hide"](); items[i][isGit ? "show" : "hide"]();
} }
}); });
menu.show(e.x, e.y);
var ace = e.editor; var ace = e.editor;
menu.once("hide", function(){ menuPath.once("hide", function(){
ace.selection.clearSelection(); ace.selection.clearSelection();
}); });
menu = menuPath;
} }
function open(e, cb) { menu.show(e.x, e.y);
if (typeof e == "string") }
e = {type: "path", value: e};
if (e.type == "link") { function openLink(href, inPreview){
var href = e.value; if (!/^(https?|ftp|file):/.test(href)) {
if (!/(https?|ftp|file):/.test(href)) {
href = "http://" + href; href = "http://" + href;
} }
href = href.replace(/(^https?:\/\/)(0.0.0.0|localhost)(?=:|\/|$)/, function(_, protocol, host) { href = href.replace(/(^https?:\/\/)(0.0.0.0|localhost)(?=:|\/|$)/, function(_, protocol, host) {
host = c9.hostname || window.location.host; host = c9.hostname || window.location.host;
return protocol + host.replace(/:\d+/, ""); return protocol + host.replace(/:\d+/, "");
}); });
if (e.metaKey || e.ctrlKey)
window.open(href); if (inPreview)
else
commands.exec("preview", null, { path: href }); commands.exec("preview", null, { path: href });
else
window.open(href);
} }
else if (e.type == "path") {
function open(e) {
if (e.type == "link")
return openLink(e.value);
var info = buildPath(e); var info = buildPath(e);
var path = info.path; var path = info.path;
@ -200,10 +225,9 @@ define(function(require, exports, module) {
jump: jump jump: jump
} }
} }
}, cb); }, function(){});
}); });
} }
}
function buildPath(e) { function buildPath(e) {
var path = e.path || e.value; var path = e.path || e.value;