@ -12,26 +12,27 @@ const refresh = require('../fileview/refresh');
module . exports = ( ) => {
module . exports = ( ) => {
if ( window . kade . modal ) { return ; }
if ( window . kade . modal ) { return ; }
preModal ( 'new -folder-modal-container' ) ;
preModal ( 're nam e-folder-modal-container' ) ;
let modalOut = document . createElement ( 'div' ) ;
let modalOut = document . createElement ( 'div' ) ;
modalOut . className = 'modal' ;
modalOut . className = 'modal' ;
modalOut . id = 'new -folder-modal-container' ;
modalOut . id = 're nam e-folder-modal-container' ;
document . body . appendChild ( modalOut ) ;
document . body . appendChild ( modalOut ) ;
let modal = document . createElement ( 'div' ) ;
let modal = document . createElement ( 'div' ) ;
modal . className = 'modal-wrapper' ;
modal . className = 'modal-wrapper' ;
modalOut . appendChild ( modal ) ;
modalOut . appendChild ( modal ) ;
let title = document . createElement ( 'h2' ) ;
let title = document . createElement ( 'h2' ) ;
title . innerHTML = 'New Folder' ;
title . innerHTML = 'Rename Folder' ;
modal . appendChild ( title ) ;
modal . appendChild ( title ) ;
let text = document . createElement ( 'p' ) ;
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 ) ;
modal . appendChild ( text ) ;
let cont = document . createElement ( 'div' ) ;
let cont = document . createElement ( 'div' ) ;
cont . className = 'button-container' ;
cont . className = 'button-container' ;
modal . appendChild ( cont ) ;
modal . appendChild ( cont ) ;
let input = document . createElement ( 'input' ) ;
let input = document . createElement ( 'input' ) ;
input . placeholder = 'New Folder' ;
input . placeholder = window . kade . currentFolder ;
input . id = 'new-folder-input' ;
input . id = 'rename-folder-input' ;
input . value = window . kade . currentFolder ;
let lastIn = '' ;
let lastIn = '' ;
input . oninput = ( ) => {
input . oninput = ( ) => {
if ( ! input . value . match ( /^[a-zA-Z0-9-_() ]*$/gm ) ) { input . value = lastIn ; }
if ( ! input . value . match ( /^[a-zA-Z0-9-_() ]*$/gm ) ) { input . value = lastIn ; }
@ -39,7 +40,7 @@ module.exports = () => {
} ;
} ;
cont . appendChild ( input ) ;
cont . appendChild ( input ) ;
let conf = document . createElement ( 'button' ) ;
let conf = document . createElement ( 'button' ) ;
conf . innerHTML = 'Creat e' ;
conf . innerHTML = 'Renam e' ;
conf . onclick = ( ) => {
conf . onclick = ( ) => {
try {
try {
input . value . trim ( ) ;
input . value . trim ( ) ;
@ -53,11 +54,11 @@ module.exports = () => {
}
}
return ;
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 ( ) ;
lightRefresh ( ) ;
modalOut . remove ( ) ;
modalOut . remove ( ) ;
newToast (
newToast (
"Folder creat ed" , [ ` Folder " ${ input . value } " created successfully ` , ` <em> ${ window . kade . cpath } / ${ input . value } </em> ` ] , undefined , false , 5 ,
"Folder renam ed" , [ ` Folder " ${ window . kade . currentFolder } " was successfully renamed to " ${ input . value } " ` , ` <em> ${ window . kade . cpath } / ${ input . value } </em> ` ] , undefined , false , 5 ,
( ) => {
( ) => {
refresh ( ` ${ window . kade . cpath } / ${ input . value } ` ) ;
refresh ( ` ${ window . kade . cpath } / ${ input . value } ` ) ;
require ( 'electron' ) . clipboard . writeText ( ` ${ window . kade . cpath } ` ) ;
require ( 'electron' ) . clipboard . writeText ( ` ${ window . kade . cpath } ` ) ;
@ -65,7 +66,7 @@ module.exports = () => {
}
}
) ;
) ;
} catch {
} catch {
newToast ( "Folder not Created" , "An error caused that folder to not be creat ed." , "#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 renam ed." , "#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 ( ) ;
clearModals ( ) ;
}
}
postModal ( modalOut . id ) ;
postModal ( modalOut . id ) ;