compress selected; bugfix for name checking

master
Kit Kasune 2 years ago
parent 5b6b9c1947
commit 3634033ee6
  1. 1
      json/ctx.json
  2. 5
      scripts/contextmenu/compress-selected.js
  3. 14
      scripts/contextmenu/compress.js
  4. 6
      scripts/contextmenu/createcontext.js

@ -2,6 +2,7 @@
[
{"name": "New Folder", "id": "ctx-new-folder", "onclick": "newfolder"},
{"name": "Compress", "id": "ctx-compress", "onclick": "compress"},
{"name": "Compress Selected", "id": "ctx-compress-selected", "onclick": "compress-selected"},
{"name": "Decompress", "id": "ctx-decompress", "onclick": "decompress"}
],
[

@ -0,0 +1,5 @@
const path = require('path');
module.exports = () => {
return require('./compress')(undefined, path.join(window.kade.cpath, window.kade.currentFolder));
};

@ -11,8 +11,9 @@ const clearModals = require('../modal/clearmodals');
const newToast = require('../toast/createtoast');
const refresh = require('../fileview/refresh');
module.exports = () => {
module.exports = (event, pathToCompress) => {
let zip = new az();
if (!pathToCompress) {pathToCompress = window.kade.cpath;}
if (window.kade.modal) {return;}
preModal('compress-folder-modal-container');
let modalOut = document.createElement('div');
@ -32,7 +33,7 @@ module.exports = () => {
cont.className = 'button-container';
modal.appendChild(cont);
let input = document.createElement('input');
input.placeholder = window.kade.cpath.split(/\\+|\/+/gm).reverse()[0];
input.placeholder = pathToCompress.split(/\\+|\/+/gm).reverse()[0];
input.value = input.placeholder;
input.id = 'compress-folder-input';
let lastIn = '';
@ -46,8 +47,9 @@ module.exports = () => {
conf.onclick = () => {
try {
input.value = input.value.trim();
if (input.value.endsWith('.zip')) {input.value = input.value.slice(0, input.value.length - 4);}
if (!input.value.length) {return;}
if (fs.existsSync(path.join(window.kade.cpath, input.value))) {
if (fs.existsSync(path.join(window.kade.cpath, `${input.value}.zip`))) {
if (!input.value.match(/^.+\(\d\)$/gm)) {input.value += ' (1)';}
else {
let tempstr = input.value.split('');
@ -60,10 +62,10 @@ module.exports = () => {
conf.style.display = 'none';
cont.style.display = 'none';
text.innerHTML = "Please wait a moment...";
zip.addLocalFolderPromise(window.kade.cpath).then(() => {
closeWrap.style.display = 'none';
zip.addLocalFolderPromise(pathToCompress).then(() => {
title.innerHTML += " - In Progress..."
text.innerHTML = "Your folder is being compressed. Please wait a moment.<br><br>This may take some time...";
closeWrap.style.display = 'none';
let bar = document.createElement('div');
bar.className = "loading-bar";
modal.appendChild(bar);
@ -71,7 +73,7 @@ module.exports = () => {
newToast("Folder compressed", [`The current folder was compressed into "${input.value}" successfully`, `<em>${window.kade.cpath}/${input.value}</em>`], undefined, false, 5);
lightRefresh();
modalOut.remove();
postModal(modalOut.id);
postModal(modalOut.id);
});
});
} catch {

@ -4,14 +4,20 @@ module.exports = (e, target, window) => {
let ctx = document.getElementById('ctx');
ctx.style.display = 'block';
const ctxf = document.getElementById('ctx-folder');
const compress = document.getElementById('ctx-compress');
const compsel = document.getElementById('ctx-compress-selected');
if (target.classList.contains('folder') || (target.parentElement && target.parentElement.classList.contains('folder'))) {
ctxf.style.display = 'block';
ctxf.previousElementSibling.style.display = 'block';
if (target.classList.contains('folder')) {window.kade.currentFolder = target.children[1].innerHTML.trim();}
else {window.kade.currentFolder = target.parentElement.children[1].innerHTML.trim();}
compress.style.display = 'none';
compsel.style.display = 'block';
} else {
ctxf.style.display = 'none';
ctxf.previousElementSibling.style.display = 'none';
compress.style.display = 'block';
compsel.style.display = 'none';
}
document.getElementById('ctx-decompress').style.display = 'none';
ctx.style.left = `${Math.min(e.pageX, (window.innerWidth - (ctx.clientWidth + 2)))}px`;

Loading…
Cancel
Save