From 0cd50b5f924e9a37ca27e6a1a109123a2ab96df7 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 26 Sep 2019 16:21:24 +0200 Subject: [PATCH 1/9] added Discard changes for external folder. removed readonly. --- src/app/compiler/compiler-imports.js | 10 +++- src/app/files/file-explorer.js | 37 ++++++------ src/app/files/fileManager.js | 6 +- src/app/files/fileProvider.js | 75 ++++++++++++++++++------- src/app/tabs/compile-tab.js | 4 +- src/app/tabs/compileTab/compileTab.js | 2 +- src/app/ui/landing-page/landing-page.js | 2 +- 7 files changed, 92 insertions(+), 44 deletions(-) diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index 21e5549a501..244d1c4f311 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -110,10 +110,18 @@ module.exports = class CompilerImports extends Plugin { }) } - import (url, loadingCb, cb) { + import (url, force, loadingCb, cb) { + if (typeof force !== 'boolean') { + let temp = loadingCb + loadingCb = force + cb = temp + force = false + } if (!loadingCb) loadingCb = () => {} + if (!cb) cb = () => {} var self = this + if (force) delete this.previouslyHandled[url] var imported = this.previouslyHandled[url] if (imported) { return cb(null, imported.content, imported.cleanUrl, imported.type, url) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 9ed63ca39a9..0249ab783a1 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -194,17 +194,29 @@ function fileExplorer (localRegistry, files, menuItems) { if (self.files.readonly) return if (key === self.files.type) return MENU_HANDLE && MENU_HANDLE.hide(null, true) - MENU_HANDLE = contextMenu(event, { - 'Rename': () => { + let actions = {} + const provider = self._deps.fileManager.fileProviderOf(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) }, + () => {} + ) + } + } else { + actions['Rename'] = () => { if (self.files.readonly) { 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) - }, - 'Delete': () => { - if (self.files.readonly) { 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) }, () => {}) } - }) + } + actions['Delete'] = () => { + if (self.files.readonly) { 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) }, () => {}) + } + MENU_HANDLE = contextMenu(event, actions) }) self.treeView.event.register('leafRightClick', function (key, data, label, event) { @@ -212,7 +224,7 @@ function fileExplorer (localRegistry, files, menuItems) { MENU_HANDLE && MENU_HANDLE.hide(null, true) let actions = {} const provider = self._deps.fileManager.fileProviderOf(key) - if (!provider.isReadOnly(key)) { + if (!provider.isExternalFolder(key)) { actions['Rename'] = () => { 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 + '"]') @@ -226,15 +238,6 @@ function fileExplorer (localRegistry, files, menuItems) { () => {} ) } - } else { - actions['Delete from remix'] = () => { - modalDialogCustom.confirm( - 'Delete from remix', - 'Are you sure you want to delete this file from remix?', - () => { files.remove(key) }, - () => {} - ) - } } MENU_HANDLE = contextMenu(event, actions) }) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index e1b9a573819..ced094987b8 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -49,7 +49,7 @@ class FileManager extends Plugin { localhostExplorer: this._components.registry.get('fileproviders/localhost').api, filesProviders: this._components.registry.get('fileproviders').api } - + this._deps.browserExplorer.event.register('fileChanged', (path) => { this.fileChangedEvent(path) }) this._deps.browserExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) }) this._deps.localhostExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) }) this._deps.browserExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) @@ -58,6 +58,10 @@ class FileManager extends Plugin { this._deps.localhostExplorer.event.register('closed', (event) => { this.removeTabsOf(this._deps.localhostExplorer) }) } + fileChangedEvent (path) { + this.syncEditor(path) + } + fileRenamedEvent (oldName, newName, isFolder) { if (!isFolder) { this._deps.config.set('currentFile', '') diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index 21c5c679e2e..29cc29cfd69 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -1,13 +1,59 @@ 'use strict' -var EventManager = require('../../lib/events') +const CompilerImport = require('../compiler/compiler-imports') +const EventManager = require('../../lib/events') +const modalDialogCustom = require('../ui/modal-dialog-custom') +const tooltip = require('../ui/tooltip') +const remixLib = require('remix-lib') +const Storage = remixLib.Storage class FileProvider { constructor (name) { this.event = new EventManager() this.type = name - this.normalizedNames = {} // contains the raw url associated with the displayed path - this.readonlyItems = ['browser'] + this.providerExternalsStorage = new Storage('providerExternals:') + this.externalFolders = [this.type + '/swarm', this.type + '/ipfs', this.type + '/github', this.type + '/gist', this.type + '/https'] + } + + addNormalizedName (path, url) { + this.providerExternalsStorage.set(this.type + '/' + path, url) + } + + removeNormalizedName (path) { + this.providerExternalsStorage.remove(path) + } + + normalizedNameExists (path) { + return this.providerExternalsStorage.exists(path) + } + + getNormalizedName (path) { + return this.providerExternalsStorage.get(path) + } + + isExternalFolder (path) { + return this.externalFolders.includes(path) + } + + discardChanges (path) { + this.remove(path) + const compilerImport = new CompilerImport() + this.providerExternalsStorage.keys().map(value => { + if (value.indexOf(path) === 0) { + compilerImport.import( + this.getNormalizedName(value), + true, + (loadingMsg) => { tooltip(loadingMsg) }, + (error, content, cleanUrl, type, url) => { + if (error) { + modalDialogCustom.alert(error) + } else { + this.addExternal(type + '/' + cleanUrl, content, url) + } + } + ) + } + }) } exists (path, cb) { @@ -25,7 +71,7 @@ class FileProvider { get (path, cb) { cb = cb || function () {} - if (this.normalizedNames[path]) path = this.normalizedNames[path] // ensure we actually use the normalized path from here + if (this.normalizedNameExists[path]) path = this.getNormalizedName(path) // ensure we actually use the normalized path from here var unprefixedpath = this.removePrefix(path) var exists = window.remixFileSystem.existsSync(unprefixedpath) if (!exists) return cb(null, null) @@ -36,10 +82,6 @@ class FileProvider { set (path, content, cb) { 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 exists = window.remixFileSystem.existsSync(unprefixedpath) if (!exists && unprefixedpath.indexOf('/') !== -1) { @@ -70,26 +112,17 @@ class FileProvider { return true } - addReadOnly (path, content, url) { - this.readonlyItems.push(this.type + '/' + path) - if (!url) this.normalizedNames[url] = path + // this will not add a folder as readonly but keep the original url to be able to restore it later + addExternal (path, content, url) { + if (url) this.addNormalizedName(path, url) return this.set(path, content) } isReadOnly (path) { - return this.readonlyItems.includes(path) - } - - _removeFromReadonlyList (path) { - const indexToRemove = this.readonlyItems.indexOf(path) - if (indexToRemove !== -1) { - this.readonlyItems.splice(indexToRemove, 1) - } + return false } remove (path) { - this._removeFromReadonlyList(path) - var unprefixedpath = this.removePrefix(path) if (!this._exists(unprefixedpath)) { return false diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index ededb6d5f27..28aaab0a4c6 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -313,7 +313,7 @@ class CompileTab extends ViewPlugin { modalDialogCustom.alert(yo`Metadata published successfully.
${result}
`) } }, (item) => { // triggered each time there's a new verified publish (means hash correspond) - this.fileProvider.addReadOnly('swarm/' + item.hash, item.content) + this.fileProvider.addExternal('swarm/' + item.hash, item.content) }) } else { publishOnIpfs(contract, this.fileManager, function (err, uploaded) { @@ -330,7 +330,7 @@ class CompileTab extends ViewPlugin { modalDialogCustom.alert(yo`Metadata published successfully.
${result}
`) } }, (item) => { // triggered each time there's a new verified publish (means hash correspond) - this.fileProvider.addReadOnly('ipfs/' + item.hash, item.content) + this.fileProvider.addExternal('ipfs/' + item.hash, item.content) }) } } diff --git a/src/app/tabs/compileTab/compileTab.js b/src/app/tabs/compileTab/compileTab.js index f2751d1d8c5..e8f88da2ccd 100644 --- a/src/app/tabs/compileTab/compileTab.js +++ b/src/app/tabs/compileTab/compileTab.js @@ -93,7 +93,7 @@ class CompileTab { if (error) return cb(error) if (this.fileProvider) { - this.fileProvider.addReadOnly(cleanUrl, content, url) + this.fileProvider.addExternal(cleanUrl, content, url) } cb(null, content) }) diff --git a/src/app/ui/landing-page/landing-page.js b/src/app/ui/landing-page/landing-page.js index 908a78d2843..a87235cd2ef 100644 --- a/src/app/ui/landing-page/landing-page.js +++ b/src/app/ui/landing-page/landing-page.js @@ -106,7 +106,7 @@ export class LandingPage extends ViewPlugin { if (error) { modalDialogCustom.alert(error) } else { - fileProviders['browser'].addReadOnly(type + '/' + cleanUrl, content, url) + fileProviders['browser'].addExternal(type + '/' + cleanUrl, content, url) this.verticalIcons.select('fileExplorers') } } From 483a1ad8dcf2ff321731af57cd71cad36ba85a87 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 26 Sep 2019 16:43:03 +0200 Subject: [PATCH 2/9] cleanup --- src/app/files/file-explorer.js | 8 ++++---- src/app/files/fileProvider.js | 2 +- src/app/files/remixDProvider.js | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 0249ab783a1..ec9f86b6140 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -207,13 +207,13 @@ function fileExplorer (localRegistry, files, menuItems) { } } else { actions['Rename'] = () => { - if (self.files.readonly) { 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 + '"]') if (name) editModeOn(name) } } actions['Delete'] = () => { - if (self.files.readonly) { return tooltip('cannot delete folder. ' + self.files.type + ' is a read only explorer') } + 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) }, () => {}) } MENU_HANDLE = contextMenu(event, actions) @@ -226,12 +226,12 @@ function fileExplorer (localRegistry, files, menuItems) { const provider = self._deps.fileManager.fileProviderOf(key) if (!provider.isExternalFolder(key)) { actions['Rename'] = () => { - if (self.files.readonly) { 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 + '"]') if (name) editModeOn(name) } actions['Delete'] = () => { - if (self.files.readonly) { return tooltip('cannot delete file. ' + self.files.type + ' is a read only explorer') } + 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) }, diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index 29cc29cfd69..ca741075ed3 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -71,7 +71,7 @@ class FileProvider { get (path, cb) { cb = cb || function () {} - if (this.normalizedNameExists[path]) path = this.getNormalizedName(path) // ensure we actually use the normalized path from here + if (this.normalizedNameExists(path)) path = this.getNormalizedName(path) // ensure we actually use the normalized path from here var unprefixedpath = this.removePrefix(path) var exists = window.remixFileSystem.existsSync(unprefixedpath) if (!exists) return cb(null, null) diff --git a/src/app/files/remixDProvider.js b/src/app/files/remixDProvider.js index 796ac09a53a..bbf9ce68a16 100644 --- a/src/app/files/remixDProvider.js +++ b/src/app/files/remixDProvider.js @@ -113,10 +113,6 @@ module.exports = class RemixDProvider { return true } - addReadOnly (path, content) { - return false - } - isReadOnly (path) { return this._readOnlyMode || this._readOnlyFiles[path] === 1 } From 3e4dc371639689a695e54390949328f2d0dbc596 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 26 Sep 2019 17:37:11 +0200 Subject: [PATCH 3/9] -removed "rename" from folder's right click. -added padding to context-menu --- src/app/files/file-explorer.js | 12 ++++++++---- src/app/ui/contextMenu.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index ec9f86b6140..44be2a4e662 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -206,10 +206,14 @@ function fileExplorer (localRegistry, files, menuItems) { ) } } else { - 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) + // extracts first two folders + const firstTwoFolders = key.substring(0, key.indexOf('/', key.indexOf('/', 1) + 1)) + if (!provider.isExternalFolder(firstTwoFolders)) { + 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'] = () => { diff --git a/src/app/ui/contextMenu.js b/src/app/ui/contextMenu.js index 8052adf5f7f..a4371f6a40c 100644 --- a/src/app/ui/contextMenu.js +++ b/src/app/ui/contextMenu.js @@ -45,7 +45,7 @@ module.exports = (event, items) => { current.onclick = () => { hide(null, true); items[item]() } return current }) - var container = yo`
` + var container = yo`
` container.style.left = event.pageX + 'px' container.style.top = event.pageY + 'px' container.style.display = 'block' From 6f68cce0ec1002ddec550823ec28244910955be3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 26 Sep 2019 18:41:26 +0200 Subject: [PATCH 4/9] if file does not need to be updated, just return --- src/app/files/fileProvider.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index ca741075ed3..fa315d5c17e 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -98,6 +98,7 @@ class FileProvider { }) } try { + if (window.remixFileSystem.readFileSync(unprefixedpath, 'utf8') === content) return true window.remixFileSystem.writeFileSync(unprefixedpath, content) } catch (e) { cb(e) From 5b2f422c6390d777c8a256db9882200c6071c081 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 26 Sep 2019 23:05:38 +0200 Subject: [PATCH 5/9] push to gist --- src/app/files/file-explorer.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 44be2a4e662..ab14aae341d 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -190,6 +190,16 @@ function fileExplorer (localRegistry, files, menuItems) { } }) + /** + * Extracts furst two folders as a subpath from the path. + **/ + function extractExternalFolder (path) { + const firstSlIndex = path.indexOf('/', 1) + if (firstSlIndex === -1) return '' + const secondSlIndex = path.indexOf('/', firstSlIndex + 1) + if (secondSlIndex === -1) return '' + return path.substring(0, secondSlIndex) + } self.treeView.event.register('nodeRightClick', function (key, data, label, event) { if (self.files.readonly) return if (key === self.files.type) return @@ -206,9 +216,19 @@ function fileExplorer (localRegistry, files, menuItems) { ) } } else { - // extracts first two folders - const firstTwoFolders = key.substring(0, key.indexOf('/', key.indexOf('/', 1) + 1)) - if (!provider.isExternalFolder(firstTwoFolders)) { + const folderPath = extractExternalFolder(key) + if (folderPath === 'browser/gists') { + const id = key.substr(key.lastIndexOf('/'), key.length - 1) + actions['Push changes to gist'] = () => { + modalDialogCustom.confirm( + 'Push back to Gist', + 'Are you sure you want to push all your changes back to Gist?', + () => { this.toGist(id) }, + () => {} + ) + } + } + if (!provider.isExternalFolder(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 + '"]') From 2c0e911ef124394f96cc788a1848410bea9d7a8d Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 27 Sep 2019 11:14:16 +0200 Subject: [PATCH 6/9] check file content only if file exist --- src/app/files/fileProvider.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index fa315d5c17e..6695a906f84 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -84,6 +84,8 @@ class FileProvider { cb = cb || function () {} var unprefixedpath = this.removePrefix(path) var exists = window.remixFileSystem.existsSync(unprefixedpath) + if (exists && window.remixFileSystem.readFileSync(unprefixedpath, 'utf8') === content) return true + if (!exists && unprefixedpath.indexOf('/') !== -1) { const paths = unprefixedpath.split('/') paths.pop() // last element should the filename @@ -98,7 +100,6 @@ class FileProvider { }) } try { - if (window.remixFileSystem.readFileSync(unprefixedpath, 'utf8') === content) return true window.remixFileSystem.writeFileSync(unprefixedpath, content) } catch (e) { cb(e) From f92f5bb48ba6efcd37c37838e9859cf00889caf8 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Fri, 27 Sep 2019 16:37:28 +0200 Subject: [PATCH 7/9] fixed upload gist --- src/app/files/file-explorer.js | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index ab14aae341d..7a714039f8b 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -218,12 +218,12 @@ function fileExplorer (localRegistry, files, menuItems) { } else { const folderPath = extractExternalFolder(key) if (folderPath === 'browser/gists') { - const id = key.substr(key.lastIndexOf('/'), key.length - 1) actions['Push changes to gist'] = () => { + const id = key.substr(key.lastIndexOf('/') + 1, key.length - 1) modalDialogCustom.confirm( 'Push back to Gist', 'Are you sure you want to push all your changes back to Gist?', - () => { this.toGist(id) }, + () => { self.toGist(id) }, () => {} ) } @@ -430,6 +430,7 @@ fileExplorer.prototype.toGist = function (id) { let proccedResult = function (error, data) { if (error) { modalDialogCustom.alert('Failed to manage gist: ' + error) + console.log('Failed to manage gist: ' + error) } else { if (data.html_url) { modalDialogCustom.confirm('Gist is ready', `The gist is at ${data.html_url}. Would you like to open it in a new window?`, () => { @@ -513,13 +514,13 @@ fileExplorer.prototype.packageFiles = function (filesProvider, callback) { else { async.eachSeries(Object.keys(files), (path, cb) => { filesProvider.get(path, (error, content) => { - if (/^\s+$/.test(content) || !content.length) { - content = '// this line is added to create a gist. Empty file is not allowed.' - } if (error) cb(error) - else { - ret[path] = { content } - cb() + else if (/^\s+$/.test(content) || !content.length) { + content = '// this line is added to create a gist. Empty file is not allowed.' + if (!error) { + ret[path] = { content } + cb() + } } }) }, (error) => { @@ -559,16 +560,6 @@ fileExplorer.prototype.copyFiles = function () { } } -// ------------------ gist publish -------------- -fileExplorer.prototype.updateGist = function () { - const gistId = this.files.id - if (!gistId) { - tooltip('no gist content is currently loaded.') - } else { - this.toGist(gistId) - } -} - fileExplorer.prototype.createNewFile = function () { let self = this modalDialogCustom.prompt('Create new file', 'File Path (Untitled.sol, Folder1/Untitled.sol)', 'Untitled.sol', (input) => { From bef86abaf0dfcdc08e79c3133d5eceb32bb16920 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Mon, 30 Sep 2019 11:07:16 +0200 Subject: [PATCH 8/9] gist edit --- src/app/files/file-explorer.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 7a714039f8b..5ddc5d48fe2 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -442,7 +442,7 @@ fileExplorer.prototype.toGist = function (id) { } } - this.packageFiles(this.files, (error, packaged) => { + this.packageFiles(this.files, 'browser/gists/' + id, (error, packaged) => { if (error) { console.log(error) modalDialogCustom.alert('Failed to create gist: ' + error) @@ -473,7 +473,9 @@ fileExplorer.prototype.toGist = function (id) { }), this.files.origGistFiles) // adding new files updatedFileList.forEach((file) => { - allItems[file] = packaged[file] + const _items = file.split('/') + const _fileName = _items[_items.length - 1] + allItems[_fileName] = packaged[file] }) tooltip('Saving gist (' + id + ') ...') @@ -507,21 +509,19 @@ fileExplorer.prototype.toGist = function (id) { } // return all the files, except the temporary/readonly ones.. -fileExplorer.prototype.packageFiles = function (filesProvider, callback) { +fileExplorer.prototype.packageFiles = function (filesProvider, directory, callback) { var ret = {} - filesProvider.resolveDirectory('/', (error, files) => { + filesProvider.resolveDirectory(directory, (error, files) => { if (error) callback(error) else { async.eachSeries(Object.keys(files), (path, cb) => { filesProvider.get(path, (error, content) => { - if (error) cb(error) - else if (/^\s+$/.test(content) || !content.length) { + if (error) return cb(error) + if (/^\s+$/.test(content) || !content.length) { content = '// this line is added to create a gist. Empty file is not allowed.' - if (!error) { - ret[path] = { content } - cb() - } } + ret[path] = { content } + cb() }) }, (error) => { callback(error, ret) @@ -543,7 +543,7 @@ fileExplorer.prototype.copyFiles = function () { ) function doCopy (target) { // package only files from the browser storage. - self.packageFiles(self.files, (error, packaged) => { + self.packageFiles(self.files, '/', (error, packaged) => { if (error) { console.log(error) } else { From 33d15900ebd969cd848be479ba39e2561481122e Mon Sep 17 00:00:00 2001 From: LianaHus Date: Mon, 30 Sep 2019 17:09:24 +0200 Subject: [PATCH 9/9] added isExternalFolder to remixdProvider --- src/app/files/file-explorer.js | 13 ++++++------- src/app/files/remixDProvider.js | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 5ddc5d48fe2..3e1acf96954 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -191,7 +191,7 @@ function fileExplorer (localRegistry, files, menuItems) { }) /** - * Extracts furst two folders as a subpath from the path. + * Extracts first two folders as a subpath from the path. **/ function extractExternalFolder (path) { const firstSlIndex = path.indexOf('/', 1) @@ -200,6 +200,7 @@ function fileExplorer (localRegistry, files, menuItems) { if (secondSlIndex === -1) return '' return path.substring(0, secondSlIndex) } + self.treeView.event.register('nodeRightClick', function (key, data, label, event) { if (self.files.readonly) return if (key === self.files.type) return @@ -228,12 +229,10 @@ function fileExplorer (localRegistry, files, menuItems) { ) } } - if (!provider.isExternalFolder(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['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'] = () => { diff --git a/src/app/files/remixDProvider.js b/src/app/files/remixDProvider.js index bbf9ce68a16..b7f8909ad2b 100644 --- a/src/app/files/remixDProvider.js +++ b/src/app/files/remixDProvider.js @@ -150,6 +150,10 @@ module.exports = class RemixDProvider { return true } + isExternalFolder (path) { + return false + } + removePrefix (path) { path = path.indexOf(this.type) === 0 ? path.replace(this.type, '') : path if (path[0] === '/') return path.substring(1)