Commit 974efc51 authored by LianaHus's avatar LianaHus

fixed

- same name - empty name - remove empty folder - close deleted file tab issues
parent 5e667faf
...@@ -213,7 +213,7 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -213,7 +213,7 @@ function fileExplorer (localRegistry, files, menuItems) {
modalDialogCustom.confirm( modalDialogCustom.confirm(
'Discard changes', 'Discard changes',
'Are you sure you want to discard all your 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) { ...@@ -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?', 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.`) 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) MENU_HANDLE = contextMenu(event, actions)
...@@ -265,7 +268,10 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -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') } if (self.files.isReadOnly(key)) { return tooltip('cannot delete file. ' + self.files.type + ' is a read only explorer') }
modalDialogCustom.confirm( modalDialogCustom.confirm(
'Delete a file', 'Are you sure you want to delete this file?', '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') { ...@@ -599,14 +605,24 @@ fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') {
fileExplorer.prototype.createNewFolder = function (parentFolder) { fileExplorer.prototype.createNewFolder = function (parentFolder) {
let self = this 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 const currentPath = !parentFolder ? self._deps.fileManager.currentPath() : parentFolder
let newName = currentPath ? currentPath + '/' + input : self.files.type + '/' + input let newName = currentPath ? currentPath + '/' + input : self.files.type + '/' + input
newName = newName + '/' newName = newName + '/'
if (!self.files.set(newName, '')) { self.files.exists(newName, (error, exist) => {
modalDialogCustom.alert('Failed to create folder ' + newName) 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) }, null, true)
} }
......
...@@ -64,6 +64,8 @@ class FileProvider { ...@@ -64,6 +64,8 @@ class FileProvider {
} }
exists (path, cb) { 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)) cb(null, this._exists(path))
} }
...@@ -138,22 +140,36 @@ class FileProvider { ...@@ -138,22 +140,36 @@ class FileProvider {
remove (path) { remove (path) {
path = this.removePrefix(path) path = this.removePrefix(path)
if (window.remixFileSystem.existsSync(path)) { if (window.remixFileSystem.existsSync(path)) {
window.remixFileSystem.readdirSync(path).forEach((file, index) => { const stat = window.remixFileSystem.statSync(path)
let curPath = path + '/' + file try {
let stat = window.remixFileSystem.statSync(curPath) if (!stat.isDirectory()) {
try { window.remixFileSystem.unlinkSync(path, console.log)
if (stat.isDirectory()) { this.event.trigger('fileRemoved', [this._normalizePath(path)])
this.remove(curPath) return true
window.remixFileSystem.rmdirSync(curPath, console.log) } else {
} else { // delete file let items = window.remixFileSystem.readdirSync(path)
window.remixFileSystem.unlinkSync(curPath, console.log) if (items.length !== 0) {
items.forEach((item, index) => {
let curPath = path + '/' + item
if (window.remixFileSystem.statSync(curPath).isDirectory()) { // delete folder
this.remove(curPath)
} 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
} }
}) } catch (e) {
console.log(e)
return false
}
} }
return true
} }
rename (oldPath, newPath, isFolder) { rename (oldPath, newPath, isFolder) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment