|
|
|
@ -158,7 +158,6 @@ function fileExplorer (localRegistry, files, menuItems) { |
|
|
|
|
var isFile = false |
|
|
|
|
Object.keys(value).filter(function keep (x) { |
|
|
|
|
if (x === '/content') isFile = true |
|
|
|
|
// if (x === '/readOnly') isReadOnly = true
|
|
|
|
|
if (x[0] !== '/') return true |
|
|
|
|
}).forEach(function (x) { newValue[x] = value[x] }) |
|
|
|
|
return { |
|
|
|
@ -208,17 +207,35 @@ function fileExplorer (localRegistry, files, menuItems) { |
|
|
|
|
MENU_HANDLE && MENU_HANDLE.hide(null, true) |
|
|
|
|
let actions = {} |
|
|
|
|
const provider = self._deps.fileManager.fileProviderOf(key) |
|
|
|
|
actions['Create File'] = () => self.createNewFile(key) |
|
|
|
|
actions['Create Folder'] = () => self.createNewFolder(key) |
|
|
|
|
if (provider.isExternalFolder(key)) { |
|
|
|
|
actions['Discard changes'] = () => { |
|
|
|
|
modalDialogCustom.confirm( |
|
|
|
|
'Discard changes', |
|
|
|
|
'Are you sure you want to discard all your changes?', |
|
|
|
|
() => { files.discardChanges(key) }, |
|
|
|
|
() => { self.files.discardChanges(key) }, |
|
|
|
|
() => {} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
const folderPath = extractExternalFolder(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 + '"]') |
|
|
|
|
if (name) editModeOn(name) |
|
|
|
|
} |
|
|
|
|
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?', |
|
|
|
|
() => { |
|
|
|
|
if (!files.remove(key)) { |
|
|
|
|
tooltip(`failed to remove ${key}. Make sure the directory is empty before removing it.`) |
|
|
|
|
} else { |
|
|
|
|
self.updatePath('browser') |
|
|
|
|
} |
|
|
|
|
}, () => {}) |
|
|
|
|
} |
|
|
|
|
if (folderPath === 'browser/gists') { |
|
|
|
|
actions['Push changes to gist'] = () => { |
|
|
|
|
const id = key.substr(key.lastIndexOf('/') + 1, key.length - 1) |
|
|
|
@ -230,21 +247,6 @@ 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 + '"]') |
|
|
|
|
if (name) editModeOn(name) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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?', |
|
|
|
|
() => { |
|
|
|
|
if (!files.remove(key)) tooltip(`failed to remove ${key}. Make sure the directory is empty before removing it.`) |
|
|
|
|
}, () => {}) |
|
|
|
|
} |
|
|
|
|
MENU_HANDLE = contextMenu(event, actions) |
|
|
|
|
}) |
|
|
|
@ -265,7 +267,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') |
|
|
|
|
}, |
|
|
|
|
() => {} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -579,16 +584,15 @@ fileExplorer.prototype.copyFiles = function () { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileExplorer.prototype.createNewFile = function (parentFolder) { |
|
|
|
|
fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') { |
|
|
|
|
let self = this |
|
|
|
|
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 (!input) input = 'New file' |
|
|
|
|
helper.createNonClashingName(parentFolder + '/' + input, self.files, (error, newName) => { |
|
|
|
|
if (error) return tooltip('Failed to create file ' + newName + ' ' + error) |
|
|
|
|
|
|
|
|
|
if (!self.files.set(newName, '')) { |
|
|
|
|
modalDialogCustom.alert('Failed to create file ' + newName) |
|
|
|
|
tooltip('Failed to create file ' + newName) |
|
|
|
|
} else { |
|
|
|
|
self._deps.fileManager.switchFile(newName) |
|
|
|
|
if (newName.includes('_test.sol')) { |
|
|
|
@ -601,14 +605,23 @@ fileExplorer.prototype.createNewFile = function (parentFolder) { |
|
|
|
|
|
|
|
|
|
fileExplorer.prototype.createNewFolder = function (parentFolder) { |
|
|
|
|
let self = this |
|
|
|
|
modalDialogCustom.prompt('Create new folder', '', '', (input) => { |
|
|
|
|
modalDialogCustom.prompt('Create new folder', '', 'New folder', (input) => { |
|
|
|
|
if (!input) { |
|
|
|
|
return tooltip('Failed to create folder. The name can not be empty') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 tooltip('Unexpected error while creating folder: ' + error) |
|
|
|
|
if (!exist) { |
|
|
|
|
self.files.set(newName, '') |
|
|
|
|
} else { |
|
|
|
|
tooltip('Folder already exists.', () => {}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, null, true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|