- same name
- empty name
- remove empty folder
- close deleted file tab
 issues
pull/5370/head
LianaHus 5 years ago
parent c3efdd588c
commit 58ae06851f
  1. 26
      src/app/files/file-explorer.js
  2. 28
      src/app/files/fileProvider.js

@ -213,7 +213,7 @@ function fileExplorer (localRegistry, files, menuItems) {
modalDialogCustom.confirm(
'Discard changes',
'Are you sure you want to discard all your changes?',
() => { files.discardChanges(key) },
() => { self.files.discardChanges(key) },
() => {}
)
}
@ -244,6 +244,9 @@ function fileExplorer (localRegistry, files, menuItems) {
modalDialogCustom.confirm('Confirm to delete a folder', 'Are you sure you want to delete this folder?',
() => {
if (!files.remove(key)) tooltip(`failed to remove ${key}. Make sure the directory is empty before removing it.`)
else {
self.updatePath('browser')
}
}, () => {})
}
MENU_HANDLE = contextMenu(event, actions)
@ -265,7 +268,10 @@ function fileExplorer (localRegistry, files, menuItems) {
if (self.files.isReadOnly(key)) { return tooltip('cannot delete file. ' + self.files.type + ' is a read only explorer') }
modalDialogCustom.confirm(
'Delete a file', 'Are you sure you want to delete this file?',
() => { files.remove(key) },
() => {
files.remove(key)
self.updatePath('browser')
},
() => {}
)
}
@ -599,14 +605,24 @@ fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') {
fileExplorer.prototype.createNewFolder = function (parentFolder) {
let self = this
modalDialogCustom.prompt('Create new folder', '', '', (input) => {
modalDialogCustom.prompt('Create new folder', '', 'New folder', (input) => {
if (input === '') {
modalDialogCustom.alert('Failed to create folder. The name can not be empty')
return false
}
const currentPath = !parentFolder ? self._deps.fileManager.currentPath() : parentFolder
let newName = currentPath ? currentPath + '/' + input : self.files.type + '/' + input
newName = newName + '/'
if (!self.files.set(newName, '')) {
modalDialogCustom.alert('Failed to create folder ' + newName)
self.files.exists(newName, (error, exist) => {
if (error) return modalDialogCustom.alert('Unexpected error while creating folder: ' + error)
if (!exist) {
self.files.set(newName, '')
} else {
modalDialogCustom.alert('Folder already exists.', () => {})
}
})
}, null, true)
}

@ -64,6 +64,8 @@ class FileProvider {
}
exists (path, cb) {
// todo check the type (directory/file) as well #2386
// currently it is not possible to have a file and folder with same path
cb(null, this._exists(path))
}
@ -138,22 +140,36 @@ class FileProvider {
remove (path) {
path = this.removePrefix(path)
if (window.remixFileSystem.existsSync(path)) {
window.remixFileSystem.readdirSync(path).forEach((file, index) => {
let curPath = path + '/' + file
let stat = window.remixFileSystem.statSync(curPath)
const stat = window.remixFileSystem.statSync(path)
try {
if (stat.isDirectory()) {
if (!stat.isDirectory()) {
window.remixFileSystem.unlinkSync(path, console.log)
this.event.trigger('fileRemoved', [this._normalizePath(path)])
return true
} else {
let items = window.remixFileSystem.readdirSync(path)
if (items.length !== 0) {
items.forEach((item, index) => {
let curPath = path + '/' + item
if (window.remixFileSystem.statSync(curPath).isDirectory()) { // delete folder
this.remove(curPath)
window.remixFileSystem.rmdirSync(curPath, console.log)
} else { // delete file
window.remixFileSystem.unlinkSync(curPath, console.log)
this.event.trigger('fileRemoved', [this._normalizePath(path)])
}
})
if (window.remixFileSystem.readdirSync(path).length === 0) window.remixFileSystem.rmdirSync(path, console.log)
} else {
// folder is empty
window.remixFileSystem.rmdirSync(path, console.log)
}
}
} catch (e) {
console.log(e)
return false
}
})
}
return true
}
rename (oldPath, newPath, isFolder) {

Loading…
Cancel
Save