From 8188dcb10d02309510dd9cc8343ffaee8abc7364 Mon Sep 17 00:00:00 2001 From: stackxp <170874486+stackxp@users.noreply.github.com> Date: Fri, 9 Jan 2026 19:13:44 +0100 Subject: [PATCH] Fix and improve right-click menu (once again) --- copyparty/web/browser.js | 43 +++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 4f5c4382..263927c4 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -269,6 +269,7 @@ if (1) "cdt_ask": "when scrolling to the bottom,$Ninstead of loading more files,$Nask what to do", "cdt_hsort": "how many sorting rules (<code>,sorthref</code>) to include in media-URLs. Setting this to 0 will also ignore sorting-rules included in media links when clicking them", "cdt_ren": "enable custom right-click menu, you can still access the regular menu by pressing the shift key and right-clicking", + "cdt_rdb": "show the regular right-click menu when the custom one is already open and right-clicking again", "tt_entree": "show navpane (directory tree sidebar)$NHotkey: B", "tt_detree": "show breadcrumbs$NHotkey: B", @@ -649,7 +650,7 @@ if (1) "rc_ply": "play", "rc_pla": "play as audio", "rc_txt": "open in textfile viewer", - "rc_md": "open in text editor", + "rc_md": "open in markdown viewer", "rc_dl": "download", "rc_zip": "download as archive", "rc_cpl": "copy link", @@ -657,6 +658,7 @@ if (1) "rc_cut": "cut", "rc_cpy": "copy", "rc_pst": "paste", + "rc_rnm": "rename", "rc_nfo": "new folder", "rc_nfi": "new file", "rc_sal": "select all", @@ -988,7 +990,7 @@ ebi('op_cfg').innerHTML = ( ' \n' + '\n' + '

' + L.cl_keytype + '

\n' + - (!MOBILE ? '

' + L.cl_rcm + '

enable
' : '') + + (!MOBILE ? '

' + L.cl_rcm + '

enabledouble
' : '') + '

' + L.cl_hiddenc + '  ' + (MOBILE ? '' + L.cl_hidec + ' / ' : '') + '' + L.cl_reset + '

' ); @@ -1032,13 +1034,12 @@ ebi('rcm').innerHTML = ( '' + L.rc_zip + '' : '') + '
' + - (has(perms, "move") ? - '' + L.rc_del + '' + - '' + L.rc_cut + '' - : '') + + (have_del ? '' + L.rc_del + '' : '') + + (have_mv ? '' + L.rc_cut + '' : '') + '' + L.rc_cpy + '' + (has(perms, "write") ? '' + L.rc_pst + '' + + (have_mv ? '' + L.rc_rnm + '' : '') + '
' + '' + L.rc_nfo + '' + '' + L.rc_nfi + '' @@ -9473,9 +9474,11 @@ var rcm = (function () { return {enabled: false} var r = { - enabled: true + enabled: true, + double: false }; bcfg_bind(r, 'enabled', 'ren', true); + bcfg_bind(r, 'double', 'rdb', false); var menu = ebi('rcm'); var selFile = { @@ -9541,13 +9544,13 @@ var rcm = (function () { case 'opn': var a = mknod('a'); a.href = selFile.path; - a.target = selFile.type == "dir" ? '' : '_blank'; + a.target = selFile.type == 'dir' ? '' : '_blank'; a.click(); break; case 'ply': selFile.type == 'gf' ? thegrid.imshow(selFile.relpath) : play('f-' + selFile.id); break; case 'pla': play('f-' + selFile.id); break; case 'txt': location = '?doc=' + selFile.relpath; break; - case 'md': location = selFile.path + '?v'; break; + case 'md': location = selFile.path + (has(selFile.path, '?') ? '&v' : '?v'); break; case 'cpl': cliptxt(location.protocol + '//' + location.host + selFile.path, function() {toast.ok(2, L.clipped)}); break; case 'dl': ebi('seldl').click(); break; case 'zip': ebi('selzip').click(); break; @@ -9558,6 +9561,7 @@ var rcm = (function () { fileman.paste(); fileman.clip = []; break; + case 'rnm': fileman.rename(); break; case 'nfo': mktemp(true); break; case 'nfi': mktemp(); break; case 'sal': @@ -9584,8 +9588,8 @@ var rcm = (function () { clmod(file, "sel", true); selFile.elem = file; - selFile.path = basenames(file.children[1].firstChild.href).split('?')[0]; - selFile.relpath = selFile.path.split('/').slice(-1)[0]; + selFile.path = basenames(file.children[1].firstChild.href).replace(/(&|\?)v/, ''); + selFile.relpath = selFile.path.split('/').slice(-1)[0].split("?")[0]; if (noq_href(file.children[1].firstChild).endsWith("/")) selFile.type = "dir"; else { @@ -9595,6 +9599,7 @@ var rcm = (function () { } } } + console.log(selFile); msel.selui(); var has_sel = msel.getsel().length; @@ -9605,7 +9610,7 @@ var rcm = (function () { clmod(ebi('rpla'), 'hide', selFile.type != 'gf'); clmod(ebi('rtxt'), 'hide', !selFile.id); clmod(ebi('rs1'), 'hide', !selFile.path); - clmod(ebi('rmd'), 'hide', !selFile.id || selFile.path.slice(-3) != '.md'); + clmod(ebi('rmd'), 'hide', !selFile.id || selFile.relpath.slice(-3) != ".md"); clmod(ebi('rcpl'), 'hide', !selFile.path); clmod(ebi('rdl'), 'hide', !has_sel); clmod(ebi('rzip'), 'hide', !has_sel); @@ -9614,7 +9619,9 @@ var rcm = (function () { clmod(ebi('rdel'), 'hide', !has_sel); clmod(ebi('rcpy'), 'hide', !has_sel); clmod(ebi('rpst'), 'hide', !has_clip); - clmod(ebi('rs3'), 'hide', !has_sel || !has_clip); + clmod(ebi('rrnm'), 'hide', !has_sel); + clmod(ebi('rs3'), 'hide', !has_sel); + clmod(ebi('rs4'), 'hide', !has_sel && !has(perms, "write")); menu.style.left = x + 5 + 'px'; menu.style.top = y + 5 + 'px'; @@ -9622,7 +9629,7 @@ var rcm = (function () { menu.focus(); } - r.hide = function (force) { + r.hide = function(force) { if (!menu.style.display || (!force && menu.contains(document.activeElement))) return; if (selFile.elem && !selFile.no_dsel) { @@ -9635,10 +9642,14 @@ var rcm = (function () { } ebi('wrap').oncontextmenu = function(e) { - if (!r.enabled || e.shiftKey || menu.style.display) { - r.hide(true); + r.hide(true); + if (!r.enabled || e.shiftKey || (r.double && menu.style.display)) { return true; } + if (selFile.elem && !selFile.no_dsel) { + clmod(selFile.elem, "sel", false); + msel.selui(); + } ev(e); var gfile = thegrid.en && e.target && e.target.closest('#ggrid > a'); show(xscroll() + e.clientX, yscroll() + e.clientY, gfile || e.target, gfile);