Merge pull request #2379 from ethereum/folderCreation

Folder creation
pull/1/head
yann300 5 years ago committed by GitHub
commit 499467ca00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      src/app/files/file-explorer.js
  2. 6
      src/app/files/fileManager.js

@ -28,7 +28,7 @@ function fileExplorer (localRegistry, files, menuItems) {
let allItems =
[
{ action: 'createNewFile',
title: 'Create New File in the Browser Storage Explorer',
title: 'Create New File',
icon: 'fas fa-plus-circle'
},
{ action: 'publishToGist',
@ -230,6 +230,9 @@ function fileExplorer (localRegistry, files, menuItems) {
)
}
}
actions['Create File'] = () => self.createNewFile(key)
actions['Create Folder'] = () => self.createNewFolder(key)
actions['Rename'] = () => {
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 + '"]')
@ -238,7 +241,10 @@ function fileExplorer (localRegistry, files, menuItems) {
}
actions['Delete'] = () => {
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)
})
@ -249,6 +255,7 @@ function fileExplorer (localRegistry, files, menuItems) {
let actions = {}
const provider = self._deps.fileManager.fileProviderOf(key)
if (!provider.isExternalFolder(key)) {
actions['Create Folder'] = () => self.createNewFolder(self._deps.fileManager.extractPathOf(key))
actions['Rename'] = () => {
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 + '"]')
@ -572,24 +579,39 @@ fileExplorer.prototype.copyFiles = function () {
}
}
fileExplorer.prototype.createNewFile = function () {
fileExplorer.prototype.createNewFile = function (parentFolder) {
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) => {
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, '')) {
modalDialogCustom.alert('Failed to create file ' + newName)
} else {
var file = self.files.type + '/' + newName
self._deps.fileManager.switchFile(file)
if (file.includes('_test.sol')) {
self.event.trigger('newTestFileCreated', [file])
self._deps.fileManager.switchFile(newName)
if (newName.includes('_test.sol')) {
self.event.trigger('newTestFileCreated', [newName])
}
}
})
}, 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 () {
let items = ''
if (this.menuItems) {

@ -119,8 +119,12 @@ class FileManager extends Plugin {
currentPath () {
var currentFile = this._deps.config.get('currentFile')
return this.extractPathOf(currentFile)
}
extractPathOf (file) {
var reg = /(.*)(\/).*/
var path = reg.exec(currentFile)
var path = reg.exec(file)
return path ? path[1] : null
}

Loading…
Cancel
Save