Add create New folder action

pull/5370/head
yann300 5 years ago
parent c4a22336ac
commit 5691cc1486
  1. 33
      src/app/files/file-explorer.js
  2. 6
      src/app/files/fileManager.js

@ -27,7 +27,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',
@ -229,6 +229,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 + '"]')
@ -251,6 +254,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 + '"]')
@ -562,24 +566,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 {
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
} }

Loading…
Cancel
Save