Unverified Commit f000ed1a authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #2363 from ethereum/kuku

Various Fixes File explorer
parents 2a010ad9 2413a190
...@@ -211,7 +211,8 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -211,7 +211,8 @@ function fileExplorer (localRegistry, files, menuItems) {
if (key === self.files.type) return if (key === self.files.type) return
MENU_HANDLE && MENU_HANDLE.hide(null, true) MENU_HANDLE && MENU_HANDLE.hide(null, true)
let actions = {} let actions = {}
if (!self.files.readonly) { const provider = self._deps.fileManager.fileProviderOf(key)
if (!provider.isReadOnly(key)) {
actions['Rename'] = () => { actions['Rename'] = () => {
if (self.files.readonly) { return tooltip('cannot rename file. ' + self.files.type + ' is a read only explorer') } if (self.files.readonly) { 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 + '"]')
...@@ -219,15 +220,20 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -219,15 +220,20 @@ function fileExplorer (localRegistry, files, menuItems) {
} }
actions['Delete'] = () => { actions['Delete'] = () => {
if (self.files.readonly) { return tooltip('cannot delete file. ' + self.files.type + ' is a read only explorer') } if (self.files.readonly) { 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) }, () => {}) modalDialogCustom.confirm(
'Delete a file', 'Are you sure you want to delete this file?',
() => { files.remove(key) },
() => {}
)
} }
} } else {
if (self.files.type !== 'browser') { actions['Delete from remix'] = () => {
actions['Copy to Browser explorer'] = () => { modalDialogCustom.confirm(
files.get(key, (error, content) => { 'Delete from remix',
if (error) return tooltip(error) 'Are you sure you want to delete this file from remix?',
self._deps.fileManager.setFile(`browser/${label.innerText}`, content) () => { files.remove(key) },
}) () => {}
)
} }
} }
MENU_HANDLE = contextMenu(event, actions) MENU_HANDLE = contextMenu(event, actions)
...@@ -245,13 +251,13 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -245,13 +251,13 @@ function fileExplorer (localRegistry, files, menuItems) {
// register to main app, trigger when the current file in the editor changed // register to main app, trigger when the current file in the editor changed
self._deps.fileManager.events.on('currentFileChanged', (newFile) => { self._deps.fileManager.events.on('currentFileChanged', (newFile) => {
const explorer = self._deps.fileManager.fileProviderOf(newFile) const provider = self._deps.fileManager.fileProviderOf(newFile)
if (self.focusElement && self.focusPath !== newFile) { if (self.focusElement && self.focusPath !== newFile) {
self.focusElement.classList.remove('bg-secondary') self.focusElement.classList.remove('bg-secondary')
self.focusElement = null self.focusElement = null
self.focusPath = null self.focusPath = null
} }
if (explorer && (explorer.type === files.type)) { if (provider && (provider.type === files.type)) {
self.focusElement = self.treeView.labelAt(newFile) self.focusElement = self.treeView.labelAt(newFile)
if (self.focusElement) { if (self.focusElement) {
self.focusElement.classList.add('bg-secondary') self.focusElement.classList.add('bg-secondary')
...@@ -350,7 +356,7 @@ fileExplorer.prototype.init = function () { ...@@ -350,7 +356,7 @@ fileExplorer.prototype.init = function () {
fileExplorer.prototype.publishToGist = function () { fileExplorer.prototype.publishToGist = function () {
modalDialogCustom.confirm( modalDialogCustom.confirm(
'Create a public gist', 'Create a public gist',
'Are you sure you want to publish all your files anonymously as a public gist on github.com?', 'Are you sure you want to publish all your files in browser directory anonymously as a public gist on github.com? Note: this will not include directories.',
() => { this.toGist() } () => { this.toGist() }
) )
} }
......
...@@ -6,6 +6,8 @@ class FileProvider { ...@@ -6,6 +6,8 @@ class FileProvider {
constructor (name) { constructor (name) {
this.event = new EventManager() this.event = new EventManager()
this.type = name this.type = name
this.normalizedNames = {} // contains the raw url associated with the displayed path
this.readonlyItems = ['browser']
} }
exists (path, cb) { exists (path, cb) {
...@@ -23,6 +25,7 @@ class FileProvider { ...@@ -23,6 +25,7 @@ class FileProvider {
get (path, cb) { get (path, cb) {
cb = cb || function () {} cb = cb || function () {}
if (this.normalizedNames[path]) path = this.normalizedNames[path] // ensure we actually use the normalized path from here
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
var exists = window.remixFileSystem.existsSync(unprefixedpath) var exists = window.remixFileSystem.existsSync(unprefixedpath)
if (!exists) return cb(null, null) if (!exists) return cb(null, null)
...@@ -33,6 +36,10 @@ class FileProvider { ...@@ -33,6 +36,10 @@ class FileProvider {
set (path, content, cb) { set (path, content, cb) {
cb = cb || function () {} cb = cb || function () {}
if (this.isReadOnly(path)) {
cb(new Error('It is not possible to modify a readonly item'))
return false
}
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
var exists = window.remixFileSystem.existsSync(unprefixedpath) var exists = window.remixFileSystem.existsSync(unprefixedpath)
if (!exists && unprefixedpath.indexOf('/') !== -1) { if (!exists && unprefixedpath.indexOf('/') !== -1) {
...@@ -63,15 +70,26 @@ class FileProvider { ...@@ -63,15 +70,26 @@ class FileProvider {
return true return true
} }
addReadOnly (path, content) { addReadOnly (path, content, url) {
this.readonlyItems.push(this.type + '/' + path)
if (!url) this.normalizedNames[url] = path
return this.set(path, content) return this.set(path, content)
} }
isReadOnly (path) { isReadOnly (path) {
return false return this.readonlyItems.includes(path)
}
_removeFromReadonlyList (path) {
const indexToRemove = this.readonlyItems.indexOf(path)
if (indexToRemove !== -1) {
this.readonlyItems.splice(indexToRemove, 1)
}
} }
remove (path) { remove (path) {
this._removeFromReadonlyList(path)
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
if (!this._exists(unprefixedpath)) { if (!this._exists(unprefixedpath)) {
return false return false
......
...@@ -110,10 +110,8 @@ export class LandingPage extends ViewPlugin { ...@@ -110,10 +110,8 @@ export class LandingPage extends ViewPlugin {
if (error) { if (error) {
modalDialogCustom.alert(error) modalDialogCustom.alert(error)
} else { } else {
if (fileProviders[type]) { fileProviders['browser'].addReadOnly(type + '/' + cleanUrl, content, url)
fileProviders[type].addReadOnly(cleanUrl, content, url) globalRegistry.get('verticalicon').api.select('fileExplorers')
globalRegistry.get('verticalicon').api.select('fileExplorers')
}
} }
} }
) )
......
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