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 plugin = new Plugin("Ajax.org", main.consumes);
var menu, lastLink;
var menuPath, lastLink;
var reHome = new RegExp("^" + util.escapeRegExp(c9.home));
@ -44,8 +44,8 @@ define(function(require, exports, module) {
ace.hoverLink.on("open", showMenu);
}, plugin);
function createMenu(e) {
if (menu)
function createMenu() {
if (menuPath)
return;
var submenu = new Menu({
@ -91,7 +91,7 @@ define(function(require, exports, module) {
new MenuItem({ value: "reveal", caption: "Reveal in File Tree" })
];
menu = new Menu({
menuPath = new Menu({
items: menuItems,
onitemclick: function(e) {
var info = buildPath(lastLink, true);
@ -118,54 +118,79 @@ define(function(require, exports, module) {
}, 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 *****/
function showMenu(e) {
if (e.type == "link" && (tabManager.focussedTab || 0).editorType)
return open(e);
if (e.action == "open")
return open(e);
createMenu(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 items = menu.items;
var items = menuPath.items;
for (var i = 0; i < 6; i++) {
items[i].aml.visible = -1;
items[i][isGit ? "show" : "hide"]();
}
});
menu.show(e.x, e.y);
var ace = e.editor;
menu.once("hide", function(){
menuPath.once("hide", function(){
ace.selection.clearSelection();
});
menu = menuPath;
}
function open(e, cb) {
if (typeof e == "string")
e = {type: "path", value: e};
menu.show(e.x, e.y);
}
if (e.type == "link") {
var href = e.value;
if (!/(https?|ftp|file):/.test(href)) {
function openLink(href, inPreview){
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
if (inPreview)
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 path = info.path;
@ -200,10 +225,9 @@ define(function(require, exports, module) {
jump: jump
}
}
}, cb);
}, function(){});
});
}
}
function buildPath(e) {
var path = e.path || e.value;