From 195c869ab57768ef9069ea4af176f39ee16e9a58 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 26 Jan 2020 11:27:13 -0800 Subject: [PATCH] Added context menu connection options to xterm. --- translate/translate.json | 28 +++++++++------ views/default.handlebars | 2 +- views/xterm.handlebars | 73 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 84 insertions(+), 19 deletions(-) diff --git a/translate/translate.json b/translate/translate.json index 96e4f880..4096e3f7 100644 --- a/translate/translate.json +++ b/translate/translate.json @@ -389,7 +389,7 @@ "default.handlebars->23->597", "default.handlebars->23->627", "default.handlebars->23->639", - "xterm.handlebars->3->6" + "xterm.handlebars->9->6" ] }, { @@ -1863,7 +1863,8 @@ "nl": "Beheerder PowerShell", "ru": "Админ PowerShell", "xloc": [ - "default.handlebars->termShellContextMenu->cxtermps" + "default.handlebars->termShellContextMenu->cxtermps", + "xterm.handlebars->termShellContextMenu->cxtermps" ] }, { @@ -1886,7 +1887,8 @@ "nl": "Beheerder Shell", "ru": "Админ Shell", "xloc": [ - "default.handlebars->termShellContextMenu->cxtermnorm->0" + "default.handlebars->termShellContextMenu->cxtermnorm->0", + "xterm.handlebars->termShellContextMenu->cxtermnorm->0" ] }, { @@ -3998,7 +4000,7 @@ "xloc": [ "default-mobile.handlebars->9->4", "default.handlebars->23->11", - "xterm.handlebars->3->4" + "xterm.handlebars->9->4" ] }, { @@ -4048,7 +4050,7 @@ "default.handlebars->23->220", "default.handlebars->23->678", "default.handlebars->23->9", - "xterm.handlebars->3->2" + "xterm.handlebars->9->2" ] }, { @@ -5482,7 +5484,7 @@ "default.handlebars->container->column_l->p11->deskarea0->deskarea1->3->deskstatus", "default.handlebars->container->column_l->p12->termTable->1->1->0->1->3->termstatus", "default.handlebars->container->column_l->p13->p13toolbar->1->0->1->3->p13Status", - "xterm.handlebars->3->1" + "xterm.handlebars->9->1" ] }, { @@ -8154,7 +8156,7 @@ "xloc": [ "default-mobile.handlebars->9->5", "default.handlebars->23->12", - "xterm.handlebars->3->5" + "xterm.handlebars->9->5" ] }, { @@ -13851,7 +13853,8 @@ "nl": "Root Shell", "ru": "Root Shell", "xloc": [ - "default.handlebars->termShellContextMenuLinux->cxtermnorm->0" + "default.handlebars->termShellContextMenuLinux->cxtermnorm->0", + "xterm.handlebars->termShellContextMenuLinux->cxtermnorm->0" ] }, { @@ -14782,7 +14785,7 @@ "default.handlebars->23->212", "default.handlebars->23->215", "default.handlebars->23->221", - "xterm.handlebars->3->3" + "xterm.handlebars->9->3" ] }, { @@ -17379,7 +17382,8 @@ "nl": "Gebruiker PowerShell", "ru": "Пользовательский PowerShell", "xloc": [ - "default.handlebars->termShellContextMenu->cxtermups" + "default.handlebars->termShellContextMenu->cxtermups", + "xterm.handlebars->termShellContextMenu->cxtermups" ] }, { @@ -17404,7 +17408,9 @@ "ru": "Пользовательская оболочка", "xloc": [ "default.handlebars->termShellContextMenu->cxtermunorm", - "default.handlebars->termShellContextMenuLinux->cxtermps" + "default.handlebars->termShellContextMenuLinux->cxtermps", + "xterm.handlebars->termShellContextMenu->cxtermunorm", + "xterm.handlebars->termShellContextMenuLinux->cxtermps" ] }, { diff --git a/views/default.handlebars b/views/default.handlebars index f15860c3..f3d8d74f 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -5297,7 +5297,7 @@ var url = '/xterm?nodeid=' + encodeURIComponent(nodeid) + '&auto=1'; var node = getNodeFromId(nodeid); if (node == null) return; - //if ([1, 2, 3, 4, 21, 22].indexOf(node.agent.id) >= 0) { url += '&fixsize=1'; } + if ([1, 2, 3, 4, 21, 22].indexOf(node.agent.id) >= 0) { url += '&os=win'; } else { url += '&os=linux'; } window.open(url, 'xterm:' + nodeid); return false; } diff --git a/views/xterm.handlebars b/views/xterm.handlebars index bdc7cd73..50a2a7c8 100644 --- a/views/xterm.handlebars +++ b/views/xterm.handlebars @@ -16,7 +16,18 @@ {{{name}}} - + + + +
@@ -89,9 +100,10 @@ meshserver.Start(); // When the user resizes the window, re-fit - window.onresize = function () { - if (termfit != null) { termfit.fit(); } - } + window.onresize = function () { if (termfit != null) { termfit.fit(); } } + + // Hide the context menu + document.onclick = function (e) { hideContextMenu(); } // Update the terminal status and buttons QH('termstatus', StatusStrs[0]); @@ -117,8 +129,9 @@ function onMessage(server, message) { } // Handles a tunnel to a remote shell - function CreateRemoteTunnel(onTunnelUpdate) { + function CreateRemoteTunnel(onTunnelUpdate, options) { var obj = { protocol: 1 }; + if ((options != null) && (typeof options.protocol == 'number')) { obj.protocol = options.protocol; } obj.onTunnelUpdate = onTunnelUpdate; obj.xxStateChange = function (state) { } obj.ProcessBinaryData = function (data) { obj.onTunnelUpdate(data); } @@ -133,7 +146,7 @@ } // Called when the connect/disconnect button is pressed - function connectButton() { + function connectButton(options) { if (!tunnel) { // Setup the terminal with auto-fit if (term != null) { term.dispose(); } @@ -150,7 +163,7 @@ }); // Setup a terminal tunnel to the agent - tunnel = CreateAgentRedirect(meshserver, CreateRemoteTunnel(tunnelUpdate), serverPublicNamePort, authCookie, authRelayCookie, domainUrl); + tunnel = CreateAgentRedirect(meshserver, CreateRemoteTunnel(tunnelUpdate, options), serverPublicNamePort, authCookie, authRelayCookie, domainUrl); tunnel.options = { cols: term.cols, rows: term.rows }; tunnel.Start(args.nodeid); tunnel.onStateChanged = onTunnelStateChange; @@ -197,6 +210,52 @@ function clearConsoleMsg() { QV('TermConsoleMsg', false); if (termConsoleMsgTimer) { clearTimeout(termConsoleMsgTimer); termConsoleMsgTimer = null; } } function setConsoleMsg(msg) { QH('TermConsoleMsg', EscapeHtml(msg).split('\n').join('
')); QV('TermConsoleMsg', true); termConsoleMsgTimer = setTimeout(clearConsoleMsg, 8000); } + // + // CONTEXT MENU + // + + var contextelement = null; + function handleContextMenu(event) { + hideContextMenu(); + var scrollLeft = (window.pageXOffset !== null) ? window.pageXOffset : (document.documentElement || document.body.parentNode || document.body).scrollLeft; + var scrollTop = (window.pageYOffset !== null) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop; + var elem = document.elementFromPoint(event.pageX - scrollLeft, event.pageY - scrollTop); + if (elem && elem != null && elem.id == 'ConnectButton') { + contextelement = elem; + var contextmenudiv; + if (args.os == 'win') { + contextmenudiv = document.getElementById('termShellContextMenu'); + } else { + contextmenudiv = document.getElementById('termShellContextMenuLinux'); + } + showContextMenuDiv(contextmenudiv, event.pageX, event.pageY); + } + return haltEvent(event); + } + + function showContextMenuDiv(element, x, y) { + var clientRect = document.documentElement.getBoundingClientRect(); + var docHeight = clientRect.height; + var docWidth = clientRect.width; + element.style.left = element.style.right = element.style.top = element.style.bottom = null; + if (x > (docWidth / 2)) { element.style.right = (docWidth - event.pageX) + 'px'; } else { element.style.left = event.pageX + 'px'; } + if (y > (docHeight / 2)) { element.style.bottom = (docHeight - event.pageY) + 'px'; } else { element.style.top = event.pageY + 'px'; } + element.style.display = 'block'; + } + + function cmtermaction(action) { + //console.log('cmtermaction', action); + connectButton({ protocol: action }) + //connectTerminal(null, 1, { protocol: action }); + } + + function hideContextMenu() { + QV('contextMenu', false); + QV('termShellContextMenu', false); + QV('termShellContextMenuLinux', false); + contextelement = null; + } + // // POPUP DIALOG //