Unverified Commit 499467ca authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #2379 from ethereum/folderCreation

Folder creation
parents 73658927 b3a77508
...@@ -28,7 +28,7 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -28,7 +28,7 @@ function fileExplorer (localRegistry, files, menuItems) {
let allItems = let allItems =
[ [
{ action: 'createNewFile', { action: 'createNewFile',
title: 'Create New File in the Browser Storage Explorer', title: 'Create New File',
icon: 'fas fa-plus-circle' icon: 'fas fa-plus-circle'
}, },
{ action: 'publishToGist', { action: 'publishToGist',
...@@ -230,6 +230,9 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -230,6 +230,9 @@ function fileExplorer (localRegistry, files, menuItems) {
) )
} }
} }
actions['Create File'] = () => self.createNewFile(key)
actions['Create Folder'] = () => self.createNewFolder(key)
actions['Rename'] = () => { actions['Rename'] = () => {
if (self.files.isReadOnly(key)) { return tooltip('cannot rename folder. ' + self.files.type + ' is a read only explorer') } if (self.files.isReadOnly(key)) { return tooltip('cannot rename folder. ' + self.files.type + ' is a read only explorer') }
var name = label.querySelector('span[data-path="' + key + '"]') var name = label.querySelector('span[data-path="' + key + '"]')
...@@ -238,7 +241,10 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -238,7 +241,10 @@ function fileExplorer (localRegistry, files, menuItems) {
} }
actions['Delete'] = () => { actions['Delete'] = () => {
if (self.files.isReadOnly(key)) { return tooltip('cannot delete folder. ' + self.files.type + ' is a read only explorer') } if (self.files.isReadOnly(key)) { return tooltip('cannot delete folder. ' + self.files.type + ' is a read only explorer') }
modalDialogCustom.confirm('Confirm to delete a folder', 'Are you sure you want to delete this folder?', () => { files.remove(key) }, () => {}) 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.`)
}, () => {})
} }
MENU_HANDLE = contextMenu(event, actions) MENU_HANDLE = contextMenu(event, actions)
}) })
...@@ -249,6 +255,7 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -249,6 +255,7 @@ function fileExplorer (localRegistry, files, menuItems) {
let actions = {} let actions = {}
const provider = self._deps.fileManager.fileProviderOf(key) const provider = self._deps.fileManager.fileProviderOf(key)
if (!provider.isExternalFolder(key)) { if (!provider.isExternalFolder(key)) {
actions['Create Folder'] = () => self.createNewFolder(self._deps.fileManager.extractPathOf(key))
actions['Rename'] = () => { actions['Rename'] = () => {
if (self.files.isReadOnly(key)) { return tooltip('cannot rename file. ' + self.files.type + ' is a read only explorer') } if (self.files.isReadOnly(key)) { return tooltip('cannot rename file. ' + self.files.type + ' is a read only explorer') }
var name = label.querySelector('span[data-path="' + key + '"]') var name = label.querySelector('span[data-path="' + key + '"]')
...@@ -572,24 +579,39 @@ fileExplorer.prototype.copyFiles = function () { ...@@ -572,24 +579,39 @@ fileExplorer.prototype.copyFiles = function () {
} }
} }
fileExplorer.prototype.createNewFile = function () { fileExplorer.prototype.createNewFile = function (parentFolder) {
let self = this let self = this
modalDialogCustom.prompt('Create new file', 'File Path (Untitled.sol, Folder1/Untitled.sol)', 'Untitled.sol', (input) => { modalDialogCustom.prompt('Create new file', 'File Name (e.g Untitled.sol)', 'Untitled.sol', (input) => {
helper.createNonClashingName(input, self.files, (error, newName) => { helper.createNonClashingName(input, self.files, (error, newName) => {
if (error) return modalDialogCustom.alert('Failed to create file ' + newName + ' ' + error) if (error) return modalDialogCustom.alert('Failed to create file ' + newName + ' ' + error)
const currentPath = !parentFolder ? self._deps.fileManager.currentPath() : parentFolder
newName = currentPath ? currentPath + '/' + newName : self.files.type + '/' + newName
if (!self.files.set(newName, '')) { if (!self.files.set(newName, '')) {
modalDialogCustom.alert('Failed to create file ' + newName) modalDialogCustom.alert('Failed to create file ' + newName)
} else { } else {
var file = self.files.type + '/' + newName self._deps.fileManager.switchFile(newName)
self._deps.fileManager.switchFile(file) if (newName.includes('_test.sol')) {
if (file.includes('_test.sol')) { self.event.trigger('newTestFileCreated', [newName])
self.event.trigger('newTestFileCreated', [file])
} }
} }
}) })
}, null, true) }, null, true)
} }
fileExplorer.prototype.createNewFolder = function (parentFolder) {
let self = this
modalDialogCustom.prompt('Create new folder', '', '', (input) => {
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)
}
}, null, true)
}
fileExplorer.prototype.renderMenuItems = function () { fileExplorer.prototype.renderMenuItems = function () {
let items = '' let items = ''
if (this.menuItems) { if (this.menuItems) {
......
...@@ -119,8 +119,12 @@ class FileManager extends Plugin { ...@@ -119,8 +119,12 @@ class FileManager extends Plugin {
currentPath () { currentPath () {
var currentFile = this._deps.config.get('currentFile') var currentFile = this._deps.config.get('currentFile')
return this.extractPathOf(currentFile)
}
extractPathOf (file) {
var reg = /(.*)(\/).*/ var reg = /(.*)(\/).*/
var path = reg.exec(currentFile) var path = reg.exec(file)
return path ? path[1] : null return path ? path[1] : null
} }
......
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