Added context menu connection options to xterm.

Ylian Saint-Hilaire committed Jan 26, 2020 at 11:27 UTC 195c869ab57768ef9069ea4af176f39ee16e9a58
3 files changed +84 -19
translate/translate.json
+17 -11
@@ -389,7 +389,7 @@
389 "default.handlebars->23->597",
390 "default.handlebars->23->627",
391 "default.handlebars->23->639",
392 - "xterm.handlebars->3->6"
392 + "xterm.handlebars->9->6"
393 ]
394 },
395 {
@@ -1863,7 +1863,8 @@
1863 "nl": "Beheerder PowerShell",
1864 "ru": "Админ PowerShell",
1865 "xloc": [
1866 - "default.handlebars->termShellContextMenu->cxtermps"
1866 + "default.handlebars->termShellContextMenu->cxtermps",
1867 + "xterm.handlebars->termShellContextMenu->cxtermps"
1868 ]
1869 },
1870 {
@@ -1886,7 +1887,8 @@
1887 "nl": "Beheerder Shell",
1888 "ru": "Админ Shell",
1889 "xloc": [
1889 - "default.handlebars->termShellContextMenu->cxtermnorm->0"
1890 + "default.handlebars->termShellContextMenu->cxtermnorm->0",
1891 + "xterm.handlebars->termShellContextMenu->cxtermnorm->0"
1892 ]
1893 },
1894 {
@@ -3998,7 +4000,7 @@
4000 "xloc": [
4001 "default-mobile.handlebars->9->4",
4002 "default.handlebars->23->11",
4001 - "xterm.handlebars->3->4"
4003 + "xterm.handlebars->9->4"
4004 ]
4005 },
4006 {
@@ -4048,7 +4050,7 @@
4050 "default.handlebars->23->220",
4051 "default.handlebars->23->678",
4052 "default.handlebars->23->9",
4051 - "xterm.handlebars->3->2"
4053 + "xterm.handlebars->9->2"
4054 ]
4055 },
4056 {
@@ -5482,7 +5484,7 @@
5484 "default.handlebars->container->column_l->p11->deskarea0->deskarea1->3->deskstatus",
5485 "default.handlebars->container->column_l->p12->termTable->1->1->0->1->3->termstatus",
5486 "default.handlebars->container->column_l->p13->p13toolbar->1->0->1->3->p13Status",
5485 - "xterm.handlebars->3->1"
5487 + "xterm.handlebars->9->1"
5488 ]
5489 },
5490 {
@@ -8154,7 +8156,7 @@
8156 "xloc": [
8157 "default-mobile.handlebars->9->5",
8158 "default.handlebars->23->12",
8157 - "xterm.handlebars->3->5"
8159 + "xterm.handlebars->9->5"
8160 ]
8161 },
8162 {
@@ -13851,7 +13853,8 @@
13853 "nl": "Root Shell",
13854 "ru": "Root Shell",
13855 "xloc": [
13854 - "default.handlebars->termShellContextMenuLinux->cxtermnorm->0"
13856 + "default.handlebars->termShellContextMenuLinux->cxtermnorm->0",
13857 + "xterm.handlebars->termShellContextMenuLinux->cxtermnorm->0"
13858 ]
13859 },
13860 {
@@ -14782,7 +14785,7 @@
14785 "default.handlebars->23->212",
14786 "default.handlebars->23->215",
14787 "default.handlebars->23->221",
14785 - "xterm.handlebars->3->3"
14788 + "xterm.handlebars->9->3"
14789 ]
14790 },
14791 {
@@ -17379,7 +17382,8 @@
17382 "nl": "Gebruiker PowerShell",
17383 "ru": "Пользовательский PowerShell",
17384 "xloc": [
17382 - "default.handlebars->termShellContextMenu->cxtermups"
17385 + "default.handlebars->termShellContextMenu->cxtermups",
17386 + "xterm.handlebars->termShellContextMenu->cxtermups"
17387 ]
17388 },
17389 {
@@ -17404,7 +17408,9 @@
17408 "ru": "Пользовательская оболочка",
17409 "xloc": [
17410 "default.handlebars->termShellContextMenu->cxtermunorm",
17407 - "default.handlebars->termShellContextMenuLinux->cxtermps"
17411 + "default.handlebars->termShellContextMenuLinux->cxtermps",
17412 + "xterm.handlebars->termShellContextMenu->cxtermunorm",
17413 + "xterm.handlebars->termShellContextMenuLinux->cxtermps"
17414 ]
17415 },
17416 {
views/default.handlebars
+1 -1
@@ -5297,7 +5297,7 @@
5297 var url = '/xterm?nodeid=' + encodeURIComponent(nodeid) + '&auto=1';
5298 var node = getNodeFromId(nodeid);
5299 if (node == null) return;
5300 - //if ([1, 2, 3, 4, 21, 22].indexOf(node.agent.id) >= 0) { url += '&fixsize=1'; }
5300 + if ([1, 2, 3, 4, 21, 22].indexOf(node.agent.id) >= 0) { url += '&os=win'; } else { url += '&os=linux'; }
5301 window.open(url, 'xterm:' + nodeid);
5302 return false;
5303 }
views/xterm.handlebars
+66 -7
@@ -16,7 +16,18 @@
16 <script type="text/javascript" src="scripts/xterm-addon-fit.js"></script>
17 <title>{{{name}}}</title>
18 </head>
19 -<body style="overflow:hidden;background-color:black">
19 +<body style="overflow:hidden;background-color:black" oncontextmenu="handleContextMenu(event)">
20 + <!-- right click menu -->
21 + <div id="termShellContextMenu" class="contextMenu noselect" style="display:none;min-width:0px">
22 + <div id="cxtermnorm" class="cmtext" onclick="cmtermaction(1,event)"><b>Admin Shell</b></div>
23 + <div id="cxtermps" class="cmtext" onclick="cmtermaction(6,event)">Admin PowerShell</div>
24 + <div id="cxtermunorm" class="cmtext" onclick="cmtermaction(8,event)">User Shell</div>
25 + <div id="cxtermups" class="cmtext" onclick="cmtermaction(9,event)">User PowerShell</div>
26 + </div>
27 + <div id="termShellContextMenuLinux" class="contextMenu noselect" style="display:none;min-width:0px">
28 + <div id="cxtermnorm" class="cmtext" onclick="cmtermaction(1,event)"><b>Root Shell</b></div>
29 + <div id="cxtermps" class="cmtext" onclick="cmtermaction(8,event)">User Shell</div>
30 + </div>
31 <div id=p11 class="noselect" style="overflow:hidden">
32 <div id=deskarea0 style="position:relative">
33 <div id=deskarea1 class="areaHead">
@@ -89,9 +100,10 @@
100 meshserver.Start();
101
102 // When the user resizes the window, re-fit
92 - window.onresize = function () {
93 - if (termfit != null) { termfit.fit(); }
94 - }
103 + window.onresize = function () { if (termfit != null) { termfit.fit(); } }
104 +
105 + // Hide the context menu
106 + document.onclick = function (e) { hideContextMenu(); }
107
108 // Update the terminal status and buttons
109 QH('termstatus', StatusStrs[0]);
@@ -117,8 +129,9 @@
129 function onMessage(server, message) { }
130
131 // Handles a tunnel to a remote shell
120 - function CreateRemoteTunnel(onTunnelUpdate) {
132 + function CreateRemoteTunnel(onTunnelUpdate, options) {
133 var obj = { protocol: 1 };
134 + if ((options != null) && (typeof options.protocol == 'number')) { obj.protocol = options.protocol; }
135 obj.onTunnelUpdate = onTunnelUpdate;
136 obj.xxStateChange = function (state) { }
137 obj.ProcessBinaryData = function (data) { obj.onTunnelUpdate(data); }
@@ -133,7 +146,7 @@
146 }
147
148 // Called when the connect/disconnect button is pressed
136 - function connectButton() {
149 + function connectButton(options) {
150 if (!tunnel) {
151 // Setup the terminal with auto-fit
152 if (term != null) { term.dispose(); }
@@ -150,7 +163,7 @@
163 });
164
165 // Setup a terminal tunnel to the agent
153 - tunnel = CreateAgentRedirect(meshserver, CreateRemoteTunnel(tunnelUpdate), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
166 + tunnel = CreateAgentRedirect(meshserver, CreateRemoteTunnel(tunnelUpdate, options), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
167 tunnel.options = { cols: term.cols, rows: term.rows };
168 tunnel.Start(args.nodeid);
169 tunnel.onStateChanged = onTunnelStateChange;
@@ -197,6 +210,52 @@
210 function clearConsoleMsg() { QV('TermConsoleMsg', false); if (termConsoleMsgTimer) { clearTimeout(termConsoleMsgTimer); termConsoleMsgTimer = null; } }
211 function setConsoleMsg(msg) { QH('TermConsoleMsg', EscapeHtml(msg).split('\n').join('<br />')); QV('TermConsoleMsg', true); termConsoleMsgTimer = setTimeout(clearConsoleMsg, 8000); }
212
213 + //
214 + // CONTEXT MENU
215 + //
216 +
217 + var contextelement = null;
218 + function handleContextMenu(event) {
219 + hideContextMenu();
220 + var scrollLeft = (window.pageXOffset !== null) ? window.pageXOffset : (document.documentElement || document.body.parentNode || document.body).scrollLeft;
221 + var scrollTop = (window.pageYOffset !== null) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
222 + var elem = document.elementFromPoint(event.pageX - scrollLeft, event.pageY - scrollTop);
223 + if (elem && elem != null && elem.id == 'ConnectButton') {
224 + contextelement = elem;
225 + var contextmenudiv;
226 + if (args.os == 'win') {
227 + contextmenudiv = document.getElementById('termShellContextMenu');
228 + } else {
229 + contextmenudiv = document.getElementById('termShellContextMenuLinux');
230 + }
231 + showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
232 + }
233 + return haltEvent(event);
234 + }
235 +
236 + function showContextMenuDiv(element, x, y) {
237 + var clientRect = document.documentElement.getBoundingClientRect();
238 + var docHeight = clientRect.height;
239 + var docWidth = clientRect.width;
240 + element.style.left = element.style.right = element.style.top = element.style.bottom = null;
241 + if (x > (docWidth / 2)) { element.style.right = (docWidth - event.pageX) + 'px'; } else { element.style.left = event.pageX + 'px'; }
242 + if (y > (docHeight / 2)) { element.style.bottom = (docHeight - event.pageY) + 'px'; } else { element.style.top = event.pageY + 'px'; }
243 + element.style.display = 'block';
244 + }
245 +
246 + function cmtermaction(action) {
247 + //console.log('cmtermaction', action);
248 + connectButton({ protocol: action })
249 + //connectTerminal(null, 1, { protocol: action });
250 + }
251 +
252 + function hideContextMenu() {
253 + QV('contextMenu', false);
254 + QV('termShellContextMenu', false);
255 + QV('termShellContextMenuLinux', false);
256 + contextelement = null;
257 + }
258 +
259 //
260 // POPUP DIALOG
261 //