From 45ffea9c0efa7ce5c5fe49006d29a130113422ee Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Wed, 30 Mar 2022 11:55:45 -0600 Subject: [PATCH 1/3] folder part of ctx --- json/ctx.json | 5 +++++ scripts/contextmenu/createcontext.js | 11 +++++++++++ scripts/startup/changelog.js | 3 --- scripts/startup/initcontext.js | 1 + styles/context.css | 5 +++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/json/ctx.json b/json/ctx.json index ddb462f..5eb3707 100755 --- a/json/ctx.json +++ b/json/ctx.json @@ -10,5 +10,10 @@ {"name": "Reload", "id": "ctx-reload", "onclick": "reload"}, {"name": "Refresh", "id": "ctx-refresh", "onclick": "refresh"}, {"name": "Options", "id": "ctx-options", "onclick": "options"} + ], + [ + {"name": "Rename", "id": "ctx-rename-folder", "onclick": "rename-folder"}, + {"name": "Pin to Favorites", "id": "ctx-pin", "onclick": "pin"}, + {"name": "Delete", "id": "ctx-delete-folder", "onclick": "delete-folder"} ] ] \ No newline at end of file diff --git a/scripts/contextmenu/createcontext.js b/scripts/contextmenu/createcontext.js index 6b3c648..3b546ed 100755 --- a/scripts/contextmenu/createcontext.js +++ b/scripts/contextmenu/createcontext.js @@ -3,6 +3,17 @@ module.exports = (e, target, window) => { window.kade.context = true; let ctx = document.getElementById('ctx'); ctx.style.display = 'block'; + const ctxf = document.getElementById('ctx-folder'); + if (target.classList.contains('file') || (target.parentElement && target.parentElement.classList.contains('file'))) { + ctxf.style.display = 'block'; + ctxf.previousElementSibling.style.display = 'block'; + if (target.classList.contains('file')) {window.kade.currentFolder = window.kade.cpath + '/' + target.children[1].innerHTML;} + else {window.kade.currentFolder = window.kade.cpath + '/' + target.parentElement.children[1].innerHTML;} + console.log(window.kade.currentFolder); + } else { + ctxf.style.display = 'none'; + ctxf.previousElementSibling.style.display = 'none'; + } ctx.style.left = `${Math.min(e.pageX, (window.innerWidth - (ctx.clientWidth + 2)))}px`; ctx.style.top = `${Math.min(e.pageY, ((window.innerHeight + window.scrollY) - (ctx.clientHeight + 2)))}px`; }; \ No newline at end of file diff --git a/scripts/startup/changelog.js b/scripts/startup/changelog.js index 36a80a0..4c33789 100755 --- a/scripts/startup/changelog.js +++ b/scripts/startup/changelog.js @@ -60,9 +60,6 @@ module.exports = () => { }); clww.style = `height: ${modalOut.clientHeight - 6};`; // TODO cry enough tears that they magically make this line work - console.log(clww.style.height); - console.log(modalOut.clientHeight - 6); - console.log(typeof clww.style); let msm = new Mousetrap(modal); msm.bind('esc', () => { diff --git a/scripts/startup/initcontext.js b/scripts/startup/initcontext.js index 1ba1a0a..e66bc97 100755 --- a/scripts/startup/initcontext.js +++ b/scripts/startup/initcontext.js @@ -23,5 +23,6 @@ module.exports = () => { } if (i + 1 < ctxl.length) {ctx.appendChild(document.createElement('hr'));} } + document.getElementById('ctx-pin').parentElement.id = 'ctx-folder'; } catch (e) {console.error(e);} }; \ No newline at end of file diff --git a/styles/context.css b/styles/context.css index c92ac43..80531aa 100755 --- a/styles/context.css +++ b/styles/context.css @@ -33,4 +33,9 @@ align-items: stretch; align-content: stretch; row-gap: 2px; +} + +#ctx-folder { + padding: 0 0; + margin: 0 0; } \ No newline at end of file From 8f9c30b89bbc91494ee4de07fe81fa1013ea96cf Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Wed, 30 Mar 2022 12:10:52 -0600 Subject: [PATCH 2/3] folder renaming --- scripts/contextmenu/rename-folder.js | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 scripts/contextmenu/rename-folder.js diff --git a/scripts/contextmenu/rename-folder.js b/scripts/contextmenu/rename-folder.js new file mode 100644 index 0000000..25913af --- /dev/null +++ b/scripts/contextmenu/rename-folder.js @@ -0,0 +1,93 @@ +const fs = require('fs'); +const path = require('path'); +const Mousetrap = require('../dep/mousetrap'); + +const lightRefresh = require('../fileview/lightrefresh'); +const preModal = require('../modal/pre'); +const postModal = require('../modal/post'); +const showError = require('../modal/common/error'); +const clearModals = require('../modal/clearmodals'); +const newToast = require('../toast/createtoast'); +const refresh = require('../fileview/refresh'); + +module.exports = () => { + if (window.kade.modal) {return;} + preModal('new-folder-modal-container'); + let modalOut = document.createElement('div'); + modalOut.className = 'modal'; + modalOut.id = 'new-folder-modal-container'; + document.body.appendChild(modalOut); + let modal = document.createElement('div'); + modal.className = 'modal-wrapper'; + modalOut.appendChild(modal); + let title = document.createElement('h2'); + title.innerHTML = 'New Folder'; + modal.appendChild(title); + let text = document.createElement('p'); + text.innerHTML = "Please name your new folder."; + modal.appendChild(text); + let cont = document.createElement('div'); + cont.className = 'button-container'; + modal.appendChild(cont); + let input = document.createElement('input'); + input.placeholder = 'New Folder'; + input.id = 'new-folder-input'; + let lastIn = ''; + input.oninput = () => { + if (!input.value.match(/^[a-zA-Z0-9-_() ]*$/gm)) {input.value = lastIn;} + else {lastIn = input.value;} + }; + cont.appendChild(input); + let conf = document.createElement('button'); + conf.innerHTML = 'Create'; + conf.onclick = () => { + try { + input.value.trim(); + if (!input.value.length) {return;} + if (fs.existsSync(path.join(window.kade.cpath, input.value))) { + if (!input.value.match(/^.+\(\d\)$/gm)) {input.value += ' (1)';} + else { + let tempstr = input.value.split(''); + tempstr[input.value.length - 2] = `${Number(input.value.charAt(input.value.length - 2)) + 1}`; + input.value = tempstr.join(''); + } + return; + } + fs.mkdirSync(path.join(window.kade.cpath, input.value)); + lightRefresh(); + modalOut.remove(); + newToast( + "Folder created", [`Folder "${input.value}" created successfully`, `${window.kade.cpath}/${input.value}`], undefined, false, 5, + () => { + refresh(`${window.kade.cpath}/${input.value}`); + require('electron').clipboard.writeText(`${window.kade.cpath}`); + newToast("Copied!", "The folder's path has been copied to your clipboard.", "#19df46"); + } + ); + } catch { + newToast("Folder not Created", "An error caused that folder to not be created.", "#b24355", false, 5, () => {showError("Folder Creation", "There was an unknown error while trying to create that folder. It may be a permissions issue, or the host folder doesn't exist anymore.");}); + clearModals(); + } + postModal(modalOut.id); + }; + cont.appendChild(conf); + input.focus(); + let msm = new Mousetrap(modal); + msm.bind('esc', () => { + lightRefresh(); + modalOut.remove(); + postModal(modalOut.id); + }); + msm.bind('enter', () => {conf.click();}); + let close = document.createElement('a'); + close.className = 'close-button'; + close.onclick = () => { + lightRefresh(); + modalOut.remove(); + postModal(modalOut.id); + }; + let closeWrap = document.createElement('div'); + closeWrap.className = 'close-button-wrapper'; + modal.appendChild(closeWrap); + closeWrap.appendChild(close); +} \ No newline at end of file From b8705723bba3000c74545596f197b790da8638da Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Wed, 30 Mar 2022 12:11:24 -0600 Subject: [PATCH 3/3] folder renaming pt. 2 --- scripts/contextmenu/createcontext.js | 5 ++--- scripts/contextmenu/rename-folder.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/contextmenu/createcontext.js b/scripts/contextmenu/createcontext.js index 3b546ed..bcf2cfb 100755 --- a/scripts/contextmenu/createcontext.js +++ b/scripts/contextmenu/createcontext.js @@ -7,9 +7,8 @@ module.exports = (e, target, window) => { if (target.classList.contains('file') || (target.parentElement && target.parentElement.classList.contains('file'))) { ctxf.style.display = 'block'; ctxf.previousElementSibling.style.display = 'block'; - if (target.classList.contains('file')) {window.kade.currentFolder = window.kade.cpath + '/' + target.children[1].innerHTML;} - else {window.kade.currentFolder = window.kade.cpath + '/' + target.parentElement.children[1].innerHTML;} - console.log(window.kade.currentFolder); + if (target.classList.contains('file')) {window.kade.currentFolder = target.children[1].innerHTML;} + else {window.kade.currentFolder = target.parentElement.children[1].innerHTML;} } else { ctxf.style.display = 'none'; ctxf.previousElementSibling.style.display = 'none'; diff --git a/scripts/contextmenu/rename-folder.js b/scripts/contextmenu/rename-folder.js index 25913af..310ae45 100644 --- a/scripts/contextmenu/rename-folder.js +++ b/scripts/contextmenu/rename-folder.js @@ -12,26 +12,27 @@ const refresh = require('../fileview/refresh'); module.exports = () => { if (window.kade.modal) {return;} - preModal('new-folder-modal-container'); + preModal('rename-folder-modal-container'); let modalOut = document.createElement('div'); modalOut.className = 'modal'; - modalOut.id = 'new-folder-modal-container'; + modalOut.id = 'rename-folder-modal-container'; document.body.appendChild(modalOut); let modal = document.createElement('div'); modal.className = 'modal-wrapper'; modalOut.appendChild(modal); let title = document.createElement('h2'); - title.innerHTML = 'New Folder'; + title.innerHTML = 'Rename Folder'; modal.appendChild(title); let text = document.createElement('p'); - text.innerHTML = "Please name your new folder."; + text.innerHTML = "What would you like to rename this folder to?"; modal.appendChild(text); let cont = document.createElement('div'); cont.className = 'button-container'; modal.appendChild(cont); let input = document.createElement('input'); - input.placeholder = 'New Folder'; - input.id = 'new-folder-input'; + input.placeholder = window.kade.currentFolder; + input.id = 'rename-folder-input'; + input.value = window.kade.currentFolder; let lastIn = ''; input.oninput = () => { if (!input.value.match(/^[a-zA-Z0-9-_() ]*$/gm)) {input.value = lastIn;} @@ -39,7 +40,7 @@ module.exports = () => { }; cont.appendChild(input); let conf = document.createElement('button'); - conf.innerHTML = 'Create'; + conf.innerHTML = 'Rename'; conf.onclick = () => { try { input.value.trim(); @@ -53,11 +54,11 @@ module.exports = () => { } return; } - fs.mkdirSync(path.join(window.kade.cpath, input.value)); + fs.renameSync(path.join(window.kade.cpath, window.kade.currentFolder), path.join(window.kade.cpath, input.value)); lightRefresh(); modalOut.remove(); newToast( - "Folder created", [`Folder "${input.value}" created successfully`, `${window.kade.cpath}/${input.value}`], undefined, false, 5, + "Folder renamed", [`Folder "${window.kade.currentFolder}" was successfully renamed to "${input.value}"`, `${window.kade.cpath}/${input.value}`], undefined, false, 5, () => { refresh(`${window.kade.cpath}/${input.value}`); require('electron').clipboard.writeText(`${window.kade.cpath}`); @@ -65,7 +66,7 @@ module.exports = () => { } ); } catch { - newToast("Folder not Created", "An error caused that folder to not be created.", "#b24355", false, 5, () => {showError("Folder Creation", "There was an unknown error while trying to create that folder. It may be a permissions issue, or the host folder doesn't exist anymore.");}); + newToast("Folder not Renamed", "An error caused that folder to not be renamed.", "#b24355", false, 5, () => {showError("Folder Creation", "There was an unknown error while trying to create that folder. It may be a permissions issue, or the host folder doesn't exist anymore.");}); clearModals(); } postModal(modalOut.id);