pull/5370/head
yann300 4 years ago
parent d722a23ef9
commit c8b5a93b63
  1. 2
      apps/remix-ide/src/app/files/fileManager.js
  2. 34
      apps/remix-ide/src/app/panels/file-panel.js

@ -593,7 +593,7 @@ class FileManager extends Plugin {
async workspaceExists (name) { async workspaceExists (name) {
const workspaceProvider = this._deps.filesProviders.workspace const workspaceProvider = this._deps.filesProviders.workspace
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name
return this.exists(workspacePath) return this.exists(workspacePath)
} }
} }

@ -46,17 +46,17 @@ const profile = {
module.exports = class Filepanel extends ViewPlugin { module.exports = class Filepanel extends ViewPlugin {
constructor (appManager) { constructor (appManager) {
super(profile) super(profile)
this.event = new EventManager() this.event = new EventManager()
this._components = {} this._components = {}
this._components.registry = globalRegistry this._components.registry = globalRegistry
this._deps = { this._deps = {
fileProviders: this._components.registry.get('fileproviders').api, fileProviders: this._components.registry.get('fileproviders').api,
fileManager: this._components.registry.get('filemanager').api fileManager: this._components.registry.get('filemanager').api
} }
this.el = document.createElement('div') this.el = document.createElement('div')
this.el.setAttribute('id', 'fileExplorerView') this.el.setAttribute('id', 'fileExplorerView')
this.remixdHandle = new RemixdHandle(this.remixdExplorer, this._deps.fileProviders.localhost, appManager) this.remixdHandle = new RemixdHandle(this.remixdExplorer, this._deps.fileProviders.localhost, appManager)
this.gitHandle = new GitHandle() this.gitHandle = new GitHandle()
this.registeredMenuItems = [] this.registeredMenuItems = []
@ -69,7 +69,7 @@ module.exports = class Filepanel extends ViewPlugin {
return this.el return this.el
} }
renderComponent() { renderComponent () {
ReactDOM.render( ReactDOM.render(
<Workspace <Workspace
createWorkspace={this.createWorkspace.bind(this)} createWorkspace={this.createWorkspace.bind(this)}
@ -91,14 +91,14 @@ module.exports = class Filepanel extends ViewPlugin {
, this.el) , this.el)
} }
/** /**
* @param item { id: string, name: string, type?: string[], path?: string[], extension?: string[], pattern?: string[] } * @param item { id: string, name: string, type?: string[], path?: string[], extension?: string[], pattern?: string[] }
* @param callback (...args) => void * @param callback (...args) => void
*/ */
registerContextMenuItem (item) { registerContextMenuItem (item) {
if (!item) throw new Error('Invalid register context menu argument') if (!item) throw new Error('Invalid register context menu argument')
if (!item.name || !item.id) throw new Error('Item name and id is mandatory') if (!item.name || !item.id) throw new Error('Item name and id is mandatory')
if (!item.type && !item.path && !item.extension && !item.pattern) throw new Error('Invalid file matching criteria provided') if (!item.type && !item.path && !item.extension && !item.pattern) throw new Error('Invalid file matching criteria provided')
this.registeredMenuItems = [...this.registeredMenuItems, item] this.registeredMenuItems = [...this.registeredMenuItems, item]
this.renderComponent() this.renderComponent()
@ -166,12 +166,12 @@ module.exports = class Filepanel extends ViewPlugin {
async uploadFile () { async uploadFile () {
return await this.request.uploadFile() return await this.request.uploadFile()
} }
async createWorkspace (workspaceName) { async createWorkspace (workspaceName) {
if (await this._deps.fileManager.workspaceExists(workspaceName)) throw new Error('workspace already exists') if (await this._deps.fileManager.workspaceExists(workspaceName)) throw new Error('workspace already exists')
const workspacesPath = this._deps.fileProviders.workspace.workspacesPath const workspacesPath = this._deps.fileProviders.workspace.workspacesPath
await this._deps.fileManager.createWorkspace(workspaceName) await this._deps.fileManager.createWorkspace(workspaceName)
for (const file in examples) { for (const file in examples) {
try { try {
await this._deps.fileManager.writeFile('browser/' + workspacesPath + '/' + workspaceName + '/' + examples[file].name, examples[file].content) await this._deps.fileManager.writeFile('browser/' + workspacesPath + '/' + workspaceName + '/' + examples[file].name, examples[file].content)
@ -179,7 +179,7 @@ module.exports = class Filepanel extends ViewPlugin {
console.error(error) console.error(error)
} }
} }
} }
/** these are called by the react component, action is already finished whent it's called */ /** these are called by the react component, action is already finished whent it's called */
async setWorkspace (workspace) { async setWorkspace (workspace) {
@ -191,7 +191,7 @@ module.exports = class Filepanel extends ViewPlugin {
} }
this.emit('setWorkspace', workspace) this.emit('setWorkspace', workspace)
} }
workspaceRenamed (workspace) { workspaceRenamed (workspace) {
this.emit('renameWorkspace', workspace) this.emit('renameWorkspace', workspace)
} }
@ -203,5 +203,5 @@ module.exports = class Filepanel extends ViewPlugin {
workspaceCreated (workspace) { workspaceCreated (workspace) {
this.emit('createWorkspace', workspace) this.emit('createWorkspace', workspace)
} }
/** end section */ /** end section */
} }

Loading…
Cancel
Save