Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored file-panel a bit #2298

Merged
merged 10 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,672 changes: 3,333 additions & 3,339 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ var { OffsetToLineColumnConverter } = require('./lib/offsetToLineColumnConverter
var QueryParams = require('./lib/query-params')
var GistHandler = require('./lib/gist-handler')
var Storage = remixLib.Storage
var Browserfiles = require('./app/files/browser-files')
var SharedFolder = require('./app/files/shared-folder')
var LocalStorageProvider = require('./app/files/localStorageProvider')
var RemixDProvider = require('./app/files/remixDProvider')
var Config = require('./config')
var Renderer = require('./app/ui/renderer')
var examples = require('./app/editor/example-contracts')
var modalDialogCustom = require('./app/ui/modal-dialog-custom')
var FileManager = require('./app/files/fileManager')
var BasicReadOnlyExplorer = require('./app/files/basicReadOnlyExplorer')
var NotPersistedExplorer = require('./app/files/NotPersistedExplorer')
var ReadonlyProvider = require('./app/files/readonlyProvider')
var BasicFileProvider = require('./app/files/basicFileProvider')
var toolTip = require('./app/ui/tooltip')
var CompilerMetadata = require('./app/files/compiler-metadata')
var CompilerImport = require('./app/compiler/compiler-imports')
Expand Down Expand Up @@ -113,7 +113,7 @@ class App {

// load file system
self._components.filesProviders = {}
self._components.filesProviders['browser'] = new Browserfiles(fileStorage)
self._components.filesProviders['browser'] = new LocalStorageProvider(fileStorage)
registry.put({api: self._components.filesProviders['browser'], name: 'fileproviders/browser'})

var remixd = new Remixd(65520)
Expand All @@ -122,13 +122,13 @@ class App {
if (message.error) toolTip(message.error)
})

self._components.filesProviders['localhost'] = new SharedFolder(remixd)
self._components.filesProviders['swarm'] = new BasicReadOnlyExplorer('swarm')
self._components.filesProviders['github'] = new BasicReadOnlyExplorer('github')
self._components.filesProviders['gist'] = new NotPersistedExplorer('gist')
self._components.filesProviders['ipfs'] = new BasicReadOnlyExplorer('ipfs')
self._components.filesProviders['https'] = new BasicReadOnlyExplorer('https')
self._components.filesProviders['http'] = new BasicReadOnlyExplorer('http')
self._components.filesProviders['localhost'] = new RemixDProvider(remixd)
self._components.filesProviders['swarm'] = new ReadonlyProvider('swarm')
self._components.filesProviders['github'] = new ReadonlyProvider('github')
self._components.filesProviders['gist'] = new BasicFileProvider('gist')
self._components.filesProviders['ipfs'] = new ReadonlyProvider('ipfs')
self._components.filesProviders['https'] = new ReadonlyProvider('https')
self._components.filesProviders['http'] = new ReadonlyProvider('http')
registry.put({api: self._components.filesProviders['localhost'], name: 'fileproviders/localhost'})
registry.put({api: self._components.filesProviders['swarm'], name: 'fileproviders/swarm'})
registry.put({api: self._components.filesProviders['github'], name: 'fileproviders/github'})
Expand Down
39 changes: 0 additions & 39 deletions src/app/files/NotPersistedExplorer.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'
var EventManager = require('../../lib/events')
const EventManager = require('../../lib/events')
const toolTip = require('../ui/tooltip')

class BasicReadOnlyExplorer {
class BasicFileProvider {
constructor (type) {
this.event = new EventManager()
this.files = {}
Expand Down Expand Up @@ -71,15 +72,31 @@ class BasicReadOnlyExplorer {
return true
}

isReadOnly (path) {
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
}

remove (path) {
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])
})
}

rename (oldPath, newPath, isFolder) {
return true
isReadOnly (path) {
return false
}

list () {
Expand All @@ -99,4 +116,4 @@ class BasicReadOnlyExplorer {
}
}

module.exports = BasicReadOnlyExplorer
module.exports = BasicFileProvider
4 changes: 4 additions & 0 deletions src/app/files/file-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function fileExplorer (localRegistry, files, menuItems) {
fileManager: self._components.registry.get('filemanager').api
}

self.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

self._components.registry.put({ api: self, name: `fileexplorer/${self.files.type}` })

// warn if file changed outside of Remix
Expand Down
8 changes: 4 additions & 4 deletions src/app/files/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ class FileManager extends Plugin {
if (file) return _switchFile(file)
else {
var browserProvider = this._deps.filesProviders['browser']
browserProvider.resolveDirectory('browser', (error, filesTree) => {
browserProvider.resolveDirectory('browser', (error, filesProvider) => {
if (error) console.error(error)
var fileList = Object.keys(filesTree)
var fileList = Object.keys(filesProvider)
if (fileList.length) {
_switchFile(browserProvider.type + '/' + fileList[0])
} else {
Expand All @@ -296,9 +296,9 @@ class FileManager extends Plugin {
return new Promise((resolve, reject) => {
const provider = this.fileProviderOf(path)
if (!provider) return reject(`provider for path ${path} not found`)
provider.resolveDirectory(path, (error, filesTree) => {
provider.resolveDirectory(path, (error, filesProvider) => {
if (error) reject(error)
resolve(filesTree)
resolve(filesProvider)
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var EventManager = require('../../lib/events')

class FilesTree {
class FileProvider {
constructor (name, storage) {
this.event = new EventManager()
this.storage = storage
Expand Down Expand Up @@ -136,4 +136,4 @@ class FilesTree {
}
}

module.exports = FilesTree
module.exports = FileProvider
29 changes: 29 additions & 0 deletions src/app/files/fileProviderBase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

class FileProvider {

exists (path, cb) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

init (cb) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

get (path, cb) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

set (path, content, cb) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

addReadOnly (path, content) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

isReadOnly (path) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

remove (path) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

rename (oldPath, newPath, isFolder) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

resolveDirectory (path, callback) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

removePrefix (path) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

updateRefs (path, type) { throw new Error(this.name + ' function is not implemented for ' + this.constructor.name + ' class') }

}

module.exports = FileProvider
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var EventManager = require('../../lib/events')

function Files (storage) {
function LocalStorageProvider (storage) {
var event = new EventManager()
this.event = event
var readonly = {}
Expand Down Expand Up @@ -145,4 +145,4 @@ function Files (storage) {
}
}

module.exports = Files
module.exports = LocalStorageProvider
18 changes: 18 additions & 0 deletions src/app/files/readonlyProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'
let BasicFileProvider = require('./basicFileProvider')

class ReadonlyProvider extends BasicFileProvider {

remove (path) {
return false
}

rename (oldPath, newPath, isFolder) {
return false
}

isReadOnly (path) {
return true
}
}
module.exports = ReadonlyProvider
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var EventManager = require('../../lib/events')
var pathtool = require('path')

module.exports = class SharedFolder {
module.exports = class RemixDProvider {
constructor (remixd) {
this.event = new EventManager()
this._remixd = remixd
Expand Down
2 changes: 1 addition & 1 deletion src/app/files/remixd-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const profile = {
name: 'remixd',
methods: [],
events: [],
description: 'using Remixd daemon, allow to access file system',
description: 'Using Remixd daemon, allow to access file system',
kind: 'other',
version: packageJson.version
}
Expand Down
73 changes: 26 additions & 47 deletions src/app/panels/file-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,40 @@ module.exports = class Filepanel extends ViewPlugin {
var fileExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['browser'],
['createNewFile', 'publishToGist', 'copyFiles', canUpload ? 'uploadFile' : '']
)
var fileSystemExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['localhost'])
var swarmExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['swarm'])
var githubExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['github'])
var gistExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['gist'], ['updateGist'])
var httpExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['http'])
var httpsExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['https'])
var ipfsExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['ipfs'])

function createProvider (key, menuItems) {
return new FileExplorer(self._components.registry, self._deps.fileProviders[key], menuItems)
}

var fileSystemExplorer = createProvider('localhost')
var swarmExplorer = createProvider('swarm')
var githubExplorer = createProvider('github')
var gistExplorer = createProvider('gist', ['updateGist'])
var httpExplorer = createProvider('http')
var httpsExplorer = createProvider('https')
var ipfsExplorer = createProvider('ipfs')

self.remixdHandle = new RemixdHandle(fileSystemExplorer, self._deps.fileProviders['localhost'], appManager)

const explorers = yo`
<div>
<div class=${css.treeview}>${fileExplorer.init()}</div>
<div class="filesystemexplorer ${css.treeview}">${fileSystemExplorer.init()}</div>
<div class="swarmexplorer ${css.treeview}">${swarmExplorer.init()}</div>
<div class="githubexplorer ${css.treeview}">${githubExplorer.init()}</div>
<div class="gistexplorer ${css.treeview}">${gistExplorer.init()}</div>
<div class="httpexplorer ${css.treeview}">${httpExplorer.init()}</div>
<div class="httpsexplorer ${css.treeview}">${httpsExplorer.init()}</div>
<div class="ipfsexplorer ${css.treeview}">${ipfsExplorer.init()}</div>
</div>
`

function template () {
return yo`
<div class=${css.container}>
<div class="${css.fileexplorer}">
<div class="${css.fileExplorerTree}">
<div class=${css.treeview}>${fileExplorer.init()}</div>
<div class="filesystemexplorer ${css.treeview}">${fileSystemExplorer.init()}</div>
<div class="swarmexplorer ${css.treeview}">${swarmExplorer.init()}</div>
<div class="githubexplorer ${css.treeview}">${githubExplorer.init()}</div>
<div class="gistexplorer ${css.treeview}">${gistExplorer.init()}</div>
<div class="httpexplorer ${css.treeview}">${httpExplorer.init()}</div>
<div class="httpsexplorer ${css.treeview}">${httpsExplorer.init()}</div>
<div class="httpsexplorer ${css.treeview}">${ipfsExplorer.init()}</div>
${explorers}
</div>
</div>
</div>
Expand All @@ -103,38 +114,6 @@ module.exports = class Filepanel extends ViewPlugin {
fileSystemExplorer.hide()
})

fileExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

fileSystemExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

swarmExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

githubExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

gistExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

httpExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

httpsExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

ipfsExplorer.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path)
})

self.render = function render () { return element }
}
}
Expand Down
1 change: 0 additions & 1 deletion src/app/tabs/compile-tab.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.