From 0bfd17bec5a6f6e055284a9b6dcbdbc6fd725df8 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Mon, 18 Apr 2022 11:18:32 -0600 Subject: [PATCH] folder deletion --- scripts/contextmenu/delete-folder.js | 67 ++++++++++++++++++++++++++++ scripts/contextmenu/rename-folder.js | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 scripts/contextmenu/delete-folder.js diff --git a/scripts/contextmenu/delete-folder.js b/scripts/contextmenu/delete-folder.js new file mode 100644 index 0000000..e0e2f1f --- /dev/null +++ b/scripts/contextmenu/delete-folder.js @@ -0,0 +1,67 @@ +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('delete-folder-modal-container'); + let modalOut = document.createElement('div'); + modalOut.className = 'modal'; + modalOut.id = 'delete-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 = 'Delete Folder'; + modal.appendChild(title); + let text = document.createElement('p'); + text.innerHTML = "Are you sure you'd like to delete this folder? Remember, this cannot be undone."; + modal.appendChild(text); + let cont = document.createElement('div'); + cont.className = 'button-container'; + modal.appendChild(cont); + let conf = document.createElement('button'); + conf.innerHTML = 'Delete it!'; + let cxl = document.createElement('button'); + cxl.innerHTML = "Nevermind"; + modal.appendChild(cxl); + conf.onclick = () => { + try { + fs.rmdirSync(path.join(window.kade.cpath, window.kade.currentFolder)); + refresh(window.kade.cpath); + newToast("Folder Deleted", "Your folder has been deleted successfully."); + } catch { + newToast("Folder not Deleted", "An error caused that folder to not be deleted.", "#b24355", false, 5, () => {showError("Folder Deletion", "There was an unknown error while trying to delete that folder. It may be a permissions issue, or the host folder doesn't exist anymore.");}); + clearModals(); + } + postModal(modalOut.id); + }; + cont.appendChild(conf); + 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 diff --git a/scripts/contextmenu/rename-folder.js b/scripts/contextmenu/rename-folder.js index df9185a..655e6e7 100644 --- a/scripts/contextmenu/rename-folder.js +++ b/scripts/contextmenu/rename-folder.js @@ -66,7 +66,7 @@ module.exports = () => { } ); } catch { - 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.");}); + newToast("Folder not Renamed", "An error caused that folder to not be renamed.", "#b24355", false, 5, () => {showError("Folder Renaming", "There was an unknown error while trying to rename that folder. It may be a permissions issue, or the host folder doesn't exist anymore.");}); clearModals(); } postModal(modalOut.id);