From 0876d9fb4bdd4e7b14392aee61166f9a1f9282e2 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 1 Apr 2022 13:14:37 -0600 Subject: [PATCH 1/3] pin folder to sidebar --- json/config/favorites.json | 1 + scripts/contextmenu/createcontext.js | 4 ++-- scripts/contextmenu/pin.js | 36 ++++++++++++++++++++++++++++ scripts/contextmenu/rename-folder.js | 2 +- scripts/startup/changelog.js | 2 +- 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 json/config/favorites.json create mode 100644 scripts/contextmenu/pin.js diff --git a/json/config/favorites.json b/json/config/favorites.json new file mode 100644 index 0000000..c2e739b --- /dev/null +++ b/json/config/favorites.json @@ -0,0 +1 @@ +{"C:/Users/clarkjr1836/Desktop/yb":"yb","C:/Users/clarkjr1836/Desktop/bot":"bot"} \ No newline at end of file diff --git a/scripts/contextmenu/createcontext.js b/scripts/contextmenu/createcontext.js index bcf2cfb..9b8d809 100755 --- a/scripts/contextmenu/createcontext.js +++ b/scripts/contextmenu/createcontext.js @@ -7,8 +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 = target.children[1].innerHTML;} - else {window.kade.currentFolder = target.parentElement.children[1].innerHTML;} + if (target.classList.contains('file')) {window.kade.currentFolder = target.children[1].innerHTML.trim();} + else {window.kade.currentFolder = target.parentElement.children[1].innerHTML.trim();} } else { ctxf.style.display = 'none'; ctxf.previousElementSibling.style.display = 'none'; diff --git a/scripts/contextmenu/pin.js b/scripts/contextmenu/pin.js new file mode 100644 index 0000000..5d6191f --- /dev/null +++ b/scripts/contextmenu/pin.js @@ -0,0 +1,36 @@ +const fs = require('fs'); +const path = require('path'); + +const createToast = require('../toast/createtoast'); +const refresh = require('../fileview/refresh'); +const newToast = require("../toast/createtoast"); + +module.exports = () => { + let pins; + if (fs.existsSync(path.join(__dirname, '../../', '/json/config/favorites.json'))) { + pins = require('../../json/config/favorites.json'); + } else {pins = {};} + let fta = window.kade.currentFolder.trim(); + if (Object.keys(pins).includes(`${window.kade.cpath.replace(/\\+/gm, '/')}/${fta}`)) { + return createToast("Already pinned", "That folder is already pinned!"); + } + let tr = `${window.kade.cpath.replace(/\\+/gm, '/')}/${fta}`; + pins[tr] = fta; + let cfc = document.getElementById('custom-favorites-container'); + let fav = document.createElement('div'); + ['favorites-button', 'folder-pin', 'nosel'].forEach(x => fav.classList.add(x)); + fav.innerHTML = fta; + fav.onclick = () => {refresh(tr);}; + console.log(fta, window.kade.cpath.replace(/\\+/gm, '/')); + cfc.appendChild(fav); + createToast( + "Folder Pinned", [`Folder "${fta}" was successfully pinned! You can now access it permanently in your sidebar!"`, `${window.kade.cpath.replace(/\\+/gm, '/')}/${fta}`], undefined, false, 5, + () => { + refresh(tr); + require('electron').clipboard.writeText(`${window.kade.cpath.replace(/\\+/gm, '/')}`); + newToast("Copied!", "The folder's path has been copied to your clipboard.", "#19df46"); + } + ); + try {fs.writeFileSync(path.join(__dirname, '../../', '/json/config/favorites.json'), JSON.stringify(pins));} + catch {createToast("Error", "Your pin was not saved for some reason. Please restart or reload (ctrl+shift+r) the app and try again.", "#ff557a");} +}; \ No newline at end of file diff --git a/scripts/contextmenu/rename-folder.js b/scripts/contextmenu/rename-folder.js index 310ae45..df9185a 100644 --- a/scripts/contextmenu/rename-folder.js +++ b/scripts/contextmenu/rename-folder.js @@ -43,7 +43,7 @@ module.exports = () => { conf.innerHTML = 'Rename'; conf.onclick = () => { try { - input.value.trim(); + input.value = 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)';} diff --git a/scripts/startup/changelog.js b/scripts/startup/changelog.js index 4c33789..1a46812 100755 --- a/scripts/startup/changelog.js +++ b/scripts/startup/changelog.js @@ -59,7 +59,7 @@ module.exports = () => { }); }); - clww.style = `height: ${modalOut.clientHeight - 6};`; // TODO cry enough tears that they magically make this line work + clww.style = `height: ${modalOut.clientHeight - 6};`; let msm = new Mousetrap(modal); msm.bind('esc', () => { From 28262c8c60643cd82dc22c104d7e17707a39ba49 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 1 Apr 2022 13:21:45 -0600 Subject: [PATCH 2/3] load folder pins on init --- json/config/favorites.json | 2 +- scripts/contextmenu/pin.js | 1 - scripts/startup/initsidebar.js | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/json/config/favorites.json b/json/config/favorites.json index c2e739b..3005c44 100644 --- a/json/config/favorites.json +++ b/json/config/favorites.json @@ -1 +1 @@ -{"C:/Users/clarkjr1836/Desktop/yb":"yb","C:/Users/clarkjr1836/Desktop/bot":"bot"} \ No newline at end of file +{"C:/Users/clarkjr1836/Desktop/yb":"yb","C:/Users/clarkjr1836/Desktop/bot":"bot","C:/Users/clarkjr1836/Desktop/bot/Natsuki":"Natsuki"} \ No newline at end of file diff --git a/scripts/contextmenu/pin.js b/scripts/contextmenu/pin.js index 5d6191f..68116ad 100644 --- a/scripts/contextmenu/pin.js +++ b/scripts/contextmenu/pin.js @@ -21,7 +21,6 @@ module.exports = () => { ['favorites-button', 'folder-pin', 'nosel'].forEach(x => fav.classList.add(x)); fav.innerHTML = fta; fav.onclick = () => {refresh(tr);}; - console.log(fta, window.kade.cpath.replace(/\\+/gm, '/')); cfc.appendChild(fav); createToast( "Folder Pinned", [`Folder "${fta}" was successfully pinned! You can now access it permanently in your sidebar!"`, `${window.kade.cpath.replace(/\\+/gm, '/')}/${fta}`], undefined, false, 5, diff --git a/scripts/startup/initsidebar.js b/scripts/startup/initsidebar.js index 4437c8c..71ede29 100644 --- a/scripts/startup/initsidebar.js +++ b/scripts/startup/initsidebar.js @@ -2,6 +2,8 @@ const refresh = require('../fileview/refresh'); const qa = require('../../json/qa.json'); const os = require("os"); +const fs = require('fs'); +const path = require('path'); module.exports = () => { let root @@ -24,4 +26,16 @@ module.exports = () => { quick.classList.add('nosel'); quickAccess.appendChild(quick); }); + + if (fs.existsSync(path.join(__dirname, '../../', '/json/config/favorites.json'))) { + const pins = require('../../json/config/favorites.json'); + let cfc = document.getElementById('custom-favorites-container'); + Object.keys(pins).forEach(pin => { + let fav = document.createElement('div'); + ['favorites-button', 'folder-pin', 'nosel'].forEach(x => fav.classList.add(x)); + fav.innerHTML = pins[pin]; + fav.onclick = () => {refresh(pin);}; + cfc.appendChild(fav); + }); + } }; \ No newline at end of file From 9bf66e72c00ef2ce2d4058bbe52ef35cdb834712 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 1 Apr 2022 13:27:13 -0600 Subject: [PATCH 3/3] fix header margins --- index.html | 12 ++++++++---- json/config/favorites.json | 1 - styles/sidebar.css | 4 ++++ 3 files changed, 12 insertions(+), 5 deletions(-) delete mode 100644 json/config/favorites.json diff --git a/index.html b/index.html index 299c235..71a4b40 100755 --- a/index.html +++ b/index.html @@ -26,13 +26,17 @@
-

Quick Access

+
+

Quick Access

+
+
-
-

Favorites

+
+

Favorites

+
+
-
diff --git a/json/config/favorites.json b/json/config/favorites.json deleted file mode 100644 index 3005c44..0000000 --- a/json/config/favorites.json +++ /dev/null @@ -1 +0,0 @@ -{"C:/Users/clarkjr1836/Desktop/yb":"yb","C:/Users/clarkjr1836/Desktop/bot":"bot","C:/Users/clarkjr1836/Desktop/bot/Natsuki":"Natsuki"} \ No newline at end of file diff --git a/styles/sidebar.css b/styles/sidebar.css index 061a993..11324e0 100644 --- a/styles/sidebar.css +++ b/styles/sidebar.css @@ -35,4 +35,8 @@ background-color: #a172a65f; padding-left: 10px; color: white; +} + +.favorites-header { + margin-bottom: 7px; } \ No newline at end of file