From e272f8bd27e30d810e60ded02cefef942eaec5f9 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Mon, 23 Sep 2019 17:36:08 +0200 Subject: [PATCH 1/3] - fixes import with github, http,reslver-engine - fixes tooltip for publish to gist - add readonly mode(is not finished yet) --- src/app/files/file-explorer.js | 2 +- src/app/files/fileProvider.js | 15 +++++++++++++-- src/app/ui/landing-page/landing-page.js | 6 ++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index a2841a4ed4..fcb5040ebb 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -350,7 +350,7 @@ fileExplorer.prototype.init = function () { fileExplorer.prototype.publishToGist = function () { modalDialogCustom.confirm( '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?', () => { this.toGist() } ) } diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index f3096d72e9..0b78379b10 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -6,6 +6,8 @@ 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'] } exists (path, cb) { @@ -23,6 +25,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 var unprefixedpath = this.removePrefix(path) var exists = window.remixFileSystem.existsSync(unprefixedpath) if (!exists) return cb(null, null) @@ -63,15 +66,23 @@ class FileProvider { return true } - addReadOnly (path, content) { + addReadOnly (path, content, url) { + this.readonlyItems.push(path) + if (url !== undefined) this.normalizedNames[url] = path return this.set(path, content) } isReadOnly (path) { - return false + return !this.readonlyItems.includes(path) } remove (path) { + // remove from readonly list + const indexToRemove = this.readonlyItems.indexOf(path) + if (indexToRemove !== -1) { + this.readonlyItems.splice(indexToRemove, 1) + } + var unprefixedpath = this.removePrefix(path) if (!this._exists(unprefixedpath)) { return false diff --git a/src/app/ui/landing-page/landing-page.js b/src/app/ui/landing-page/landing-page.js index c7043935ec..c0edcbff32 100644 --- a/src/app/ui/landing-page/landing-page.js +++ b/src/app/ui/landing-page/landing-page.js @@ -110,10 +110,8 @@ export class LandingPage extends ViewPlugin { if (error) { modalDialogCustom.alert(error) } else { - if (fileProviders[type]) { - fileProviders[type].addReadOnly(cleanUrl, content, url) - globalRegistry.get('verticalicon').api.select('fileExplorers') - } + fileProviders['browser'].addReadOnly(type + '/' + cleanUrl, content, url) + globalRegistry.get('verticalicon').api.select('fileExplorers') } } ) From 4dc66e2e2dd990a7a4cc4525a92e299ecb8bcc0b Mon Sep 17 00:00:00 2001 From: LianaHus Date: Mon, 23 Sep 2019 21:43:34 +0200 Subject: [PATCH 2/3] fixes after review standard --- src/app/files/file-explorer.js | 12 ++++++------ src/app/files/fileProvider.js | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index fcb5040ebb..27164ca7a9 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -211,7 +211,8 @@ function fileExplorer (localRegistry, files, menuItems) { if (key === self.files.type) return MENU_HANDLE && MENU_HANDLE.hide(null, true) let actions = {} - if (!self.files.readonly) { + const provider = self._deps.fileManager.fileProviderOf(key) + if (!provider.isReadOnly(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 + '"]') @@ -221,8 +222,7 @@ function fileExplorer (localRegistry, files, menuItems) { 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) }, () => {}) } - } - if (self.files.type !== 'browser') { + } else { actions['Copy to Browser explorer'] = () => { files.get(key, (error, content) => { if (error) return tooltip(error) @@ -245,13 +245,13 @@ function fileExplorer (localRegistry, files, menuItems) { // register to main app, trigger when the current file in the editor changed 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) { self.focusElement.classList.remove('bg-secondary') self.focusElement = null self.focusPath = null } - if (explorer && (explorer.type === files.type)) { + if (provider && (provider.type === files.type)) { self.focusElement = self.treeView.labelAt(newFile) if (self.focusElement) { self.focusElement.classList.add('bg-secondary') @@ -350,7 +350,7 @@ fileExplorer.prototype.init = function () { fileExplorer.prototype.publishToGist = function () { modalDialogCustom.confirm( 'Create a public gist', - 'Are you sure you want to publish all your files in browser directory 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() } ) } diff --git a/src/app/files/fileProvider.js b/src/app/files/fileProvider.js index 0b78379b10..b9d6b27411 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -36,6 +36,10 @@ 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) { @@ -67,13 +71,13 @@ class FileProvider { } addReadOnly (path, content, url) { - this.readonlyItems.push(path) - if (url !== undefined) this.normalizedNames[url] = path + this.readonlyItems.push('browser/' + path) + if (!url) this.normalizedNames[url] = path return this.set(path, content) } isReadOnly (path) { - return !this.readonlyItems.includes(path) + return this.readonlyItems.includes(path) } remove (path) { From ddf8d1c5dd5f08b6eb4640d15577d8c70474197f Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 24 Sep 2019 13:12:01 +0200 Subject: [PATCH 3/3] added "delete from remix" --- src/app/files/file-explorer.js | 18 ++++++++++++------ src/app/files/fileProvider.js | 9 ++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 27164ca7a9..9ed63ca39a 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -220,14 +220,20 @@ function fileExplorer (localRegistry, files, menuItems) { } actions['Delete'] = () => { 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 { - actions['Copy to Browser explorer'] = () => { - files.get(key, (error, content) => { - if (error) return tooltip(error) - self._deps.fileManager.setFile(`browser/${label.innerText}`, content) - }) + 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/fileProvider.js b/src/app/files/fileProvider.js index b9d6b27411..21c5c679e2 100644 --- a/src/app/files/fileProvider.js +++ b/src/app/files/fileProvider.js @@ -71,7 +71,7 @@ class FileProvider { } addReadOnly (path, content, url) { - this.readonlyItems.push('browser/' + path) + this.readonlyItems.push(this.type + '/' + path) if (!url) this.normalizedNames[url] = path return this.set(path, content) } @@ -80,12 +80,15 @@ class FileProvider { return this.readonlyItems.includes(path) } - remove (path) { - // remove from readonly list + _removeFromReadonlyList (path) { const indexToRemove = this.readonlyItems.indexOf(path) if (indexToRemove !== -1) { this.readonlyItems.splice(indexToRemove, 1) } + } + + remove (path) { + this._removeFromReadonlyList(path) var unprefixedpath = this.removePrefix(path) if (!this._exists(unprefixedpath)) {