@ -1,4 +1,4 @@
/* global FileReader, confirm */
/* global FileReader */
var yo = require ( 'yo-yo' )
var csjs = require ( 'csjs-inject' )
var Treeview = require ( 'ethereum-remix' ) . ui . TreeView
@ -133,8 +133,7 @@ function fileExplorer (appAPI, files) {
this . events = events
var api = { }
api . addFile = function addFile ( file ) {
var name = files . type + '/' + file . name
if ( ! files . exists ( name ) || confirm ( 'The file ' + name + ' already exists! Would you like to overwrite it?' ) ) {
function loadFile ( ) {
var fileReader = new FileReader ( )
fileReader . onload = function ( event ) {
var success = files . set ( name , event . target . result )
@ -143,6 +142,13 @@ function fileExplorer (appAPI, files) {
}
fileReader . readAsText ( file )
}
var name = files . type + '/' + file . name
if ( ! files . exists ( name ) ) {
loadFile ( )
} else {
modalDialogCustom . confirm ( null , ` The file ${ name } already exists! Would you like to overwrite it? ` , ( ) => { loadFile ( ) } )
}
}
this . api = api
@ -193,10 +199,10 @@ function fileExplorer (appAPI, files) {
var path = label . dataset . path
var isFolder = ! ! ~ label . className . indexOf ( 'folder' )
if ( isFolder ) path += '/'
if ( confirm ( ` Do you really want to delete " ${ path } " ? ` ) ) {
modalDialogCustom . confirm ( null , ` Do you really want to delete " ${ path } " ? ` , ( ) => {
li . parentElement . removeChild ( li )
removeSubtree ( files , path , isFolder )
}
} )
}
function editModeOn ( event ) {
@ -213,31 +219,38 @@ function fileExplorer (appAPI, files) {
function editModeOff ( event ) {
var label = this
function rename ( ) {
var newPath = label . dataset . path
newPath = newPath . split ( '/' )
newPath [ newPath . length - 1 ] = label . innerText
newPath = newPath . join ( '/' )
if ( label . innerText === '' ) {
modalDialogCustom . alert ( 'File name cannot be empty' )
label . innerText = textUnderEdit
} else if ( label . innerText . match ( /(\/|:|\*|\?|"|<|>|\\|\||')/ ) !== null ) {
modalDialogCustom . alert ( 'Special characters are not allowed' )
label . innerText = textUnderEdit
} else if ( ! files . exists ( newPath ) ) {
files . rename ( label . dataset . path , newPath , isFolder )
} else {
modalDialogCustom . alert ( 'File already exists.' )
label . innerText = textUnderEdit
}
}
function cancelRename ( ) {
label . innerText = textUnderEdit
label . removeAttribute ( 'contenteditable' )
label . classList . remove ( css . rename )
}
if ( event . which === 13 ) event . preventDefault ( )
if ( ( event . type === 'blur' || event . which === 27 || event . which === 13 ) && label . getAttribute ( 'contenteditable' ) ) {
var isFolder = label . className . indexOf ( 'folder' ) !== - 1
var save = textUnderEdit !== label . innerText
if ( save && event . which !== 13 ) save = confirm ( 'Do you want to rename?' )
if ( save ) {
var newPath = label . dataset . path
newPath = newPath . split ( '/' )
newPath [ newPath . length - 1 ] = label . innerText
newPath = newPath . join ( '/' )
if ( label . innerText === '' ) {
modalDialogCustom . alert ( 'File name cannot be empty' )
label . innerText = textUnderEdit
} else if ( label . innerText . match ( /(\/|:|\*|\?|"|<|>|\\|\||')/ ) !== null ) {
modalDialogCustom . alert ( 'Special characters are not allowed' )
label . innerText = textUnderEdit
} else if ( ! files . exists ( newPath ) ) {
files . rename ( label . dataset . path , newPath , isFolder )
} else {
modalDialogCustom . alert ( 'File already exists.' )
label . innerText = textUnderEdit
}
} else label . innerText = textUnderEdit
label . removeAttribute ( 'contenteditable' )
label . classList . remove ( css . rename )
if ( save && event . which !== 13 ) {
modalDialogCustom . confirm ( null , ` Do you want to rename? ` , ( ) => { rename ( ) } , ( ) => { cancelRename ( ) } )
}
}
}