From d8975cf429dde86b57ef42152ce84a04dcf1fab1 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 7 Mar 2018 09:45:42 +0100 Subject: [PATCH] change gist explorer to be non read only && redeploy to gist --- src/app.js | 3 +- src/app/files/NotPersistedExplorer.js | 39 ++++++++++++++++++++++++++ src/app/files/basicReadOnlyExplorer.js | 1 - src/app/panels/file-panel.js | 11 +++++--- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/app/files/NotPersistedExplorer.js diff --git a/src/app.js b/src/app.js index b8ece07649..f6833e876d 100644 --- a/src/app.js +++ b/src/app.js @@ -40,6 +40,7 @@ var FileManager = require('./app/files/fileManager') var ContextualListener = require('./app/editor/contextualListener') var ContextView = require('./app/editor/contextView') var BasicReadOnlyExplorer = require('./app/files/basicReadOnlyExplorer') +var NotPersistedExplorer = require('./app/files/NotPersistedExplorer') var toolTip = require('./app/ui/tooltip') var CommandInterpreter = require('./lib/cmdInterpreter') @@ -128,7 +129,7 @@ class App { self._api.filesProviders['localhost'] = new SharedFolder(remixd) self._api.filesProviders['swarm'] = new BasicReadOnlyExplorer('swarm') self._api.filesProviders['github'] = new BasicReadOnlyExplorer('github') - self._api.filesProviders['gist'] = new BasicReadOnlyExplorer('gist') + self._api.filesProviders['gist'] = new NotPersistedExplorer('gist') self._api.filesProviders['ipfs'] = new BasicReadOnlyExplorer('ipfs') self._view = {} self._components = {} diff --git a/src/app/files/NotPersistedExplorer.js b/src/app/files/NotPersistedExplorer.js new file mode 100644 index 0000000000..2ab8b1d938 --- /dev/null +++ b/src/app/files/NotPersistedExplorer.js @@ -0,0 +1,39 @@ +'use strict' +var ReadOnlyExplorer = require('./basicReadOnlyExplorer') +var toolTip = require('../ui/tooltip') + +class NotPersistedExplorer extends ReadOnlyExplorer { + constructor (type) { + super(type) + this.readonly = false + } + + remove (path) { + var unprefixedPath = this.removePrefix(path) + var folderPath = path.substring(0, path.lastIndexOf('/')) + if (this.paths[folderPath]) { + delete this.paths[folderPath][unprefixedPath] + delete this.files[path] + } + this.event.trigger('fileRemoved', [this.type + '/' + unprefixedPath]) + return true + } + + rename (oldPath, newPath, isFolder) { + if (isFolder) { return toolTip('folder renaming is not handled by this explorer') } + var unprefixedoldPath = this.removePrefix(oldPath) + var unprefixednewPath = this.removePrefix(newPath) + this.get(oldPath, (error, content) => { + if (error) return console.log(error) + this.remove(oldPath) + this.set(newPath, content) + this.event.trigger('fileRenamed', [this.type + '/' + unprefixedoldPath, this.type + '/' + unprefixednewPath, isFolder]) + }) + } + + isReadOnly (path) { + return false + } +} + +module.exports = NotPersistedExplorer diff --git a/src/app/files/basicReadOnlyExplorer.js b/src/app/files/basicReadOnlyExplorer.js index 31c6081fd4..5baf5c790e 100644 --- a/src/app/files/basicReadOnlyExplorer.js +++ b/src/app/files/basicReadOnlyExplorer.js @@ -76,7 +76,6 @@ class BasicReadOnlyExplorer { } remove (path) { - delete this.files[path] } rename (oldPath, newPath, isFolder) { diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index a398882e5d..20f2a68852 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -80,7 +80,10 @@ function filepanel (appAPI, filesProvider) { ` : ''} - publishToGist(appAPI)}> + publishToGist('browser')}> + + + publishToGist('gist')}> @@ -270,7 +273,7 @@ function filepanel (appAPI, filesProvider) { // ------------------ gist publish -------------- - function publishToGist () { + function publishToGist (fileProviderName) { function cb (data) { if (data instanceof Error) { console.log('fail', data.message) @@ -288,7 +291,7 @@ function filepanel (appAPI, filesProvider) { } function toGist () { - packageFiles(filesProvider['browser'], (error, packaged) => { + packageFiles(filesProvider[fileProviderName], (error, packaged) => { if (error) { console.log(error) modalDialogCustom.alert('Failed to create gist: ' + error) @@ -338,7 +341,7 @@ function filepanel (appAPI, filesProvider) { // return all the files, except the temporary/readonly ones.. function packageFiles (filesProvider, callback) { var ret = {} - filesProvider.resolveDirectory('browser', (error, files) => { + filesProvider.resolveDirectory(filesProvider.type, (error, files) => { if (error) callback(error) else { async.eachSeries(Object.keys(files), (path, cb) => {