add editor getCurrent, get, set

pull/3094/head
yann300 6 years ago
parent 6df9e6a3b1
commit c450e4dbf3
  1. 2
      src/app/panels/righthand-panel.js
  2. 32
      src/app/plugin/pluginAPI.js
  3. 3
      src/app/plugin/pluginManager.js

@ -36,6 +36,7 @@ module.exports = class RighthandPanel {
self._deps = { self._deps = {
fileProviders: self._components.registry.get('fileproviders').api, fileProviders: self._components.registry.get('fileproviders').api,
fileManager: self._components.registry.get('fileManager').api,
compiler: self._components.registry.get('compiler').api, compiler: self._components.registry.get('compiler').api,
udapp: self._components.registry.get('udapp').api, udapp: self._components.registry.get('udapp').api,
app: self._components.registry.get('app').api, app: self._components.registry.get('app').api,
@ -49,6 +50,7 @@ module.exports = class RighthandPanel {
self._deps.compiler, self._deps.compiler,
self._deps.txlistener, self._deps.txlistener,
self._deps.fileProviders, self._deps.fileProviders,
self._deps.fileManager,
self._deps.udapp self._deps.udapp
) )

@ -4,7 +4,7 @@ var executionContext = require('../../execution-context')
/* /*
Defines available API. `key` / `type` Defines available API. `key` / `type`
*/ */
module.exports = (pluginManager, fileProviders, compiler, udapp) => { module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => {
return { return {
app: { app: {
getExecutionContextProvider: (mod, cb) => { getExecutionContextProvider: (mod, cb) => {
@ -63,6 +63,36 @@ module.exports = (pluginManager, fileProviders, compiler, udapp) => {
cb(error, address) cb(error, address)
}) })
} }
},
editor: {
getCurrentFile: (mod, cb) => {
var path = fileManager.currentPath()
if (!path) {
cb('no file selected')
} else {
this.getFile(mod, path, cb)
}
},
getFile: (mod, path, cb) => {
var provider = fileManager.fileProviderOf(path)
if (provider) {
provider.get(mod + '/' + path, (error, content) => {
cb(error, content)
})
} else {
cb(path + 'not available')
}
},
setFile: (mod, path, content, cb) => {
var provider = fileManager.fileProviderOf(path)
if (provider) {
provider.set(mod + '/' + path, content, (error) => {
cb(error)
})
} else {
cb(path + 'not available')
}
}
} }
} }
} }

@ -78,11 +78,12 @@ const PluginAPI = require('./pluginAPI')
* *
*/ */
module.exports = class PluginManager { module.exports = class PluginManager {
constructor (app, compiler, txlistener, fileProviders, udapp) { constructor (app, compiler, txlistener, fileProviders, fileManager, udapp) {
const self = this const self = this
var pluginAPI = new PluginAPI( var pluginAPI = new PluginAPI(
this, this,
fileProviders, fileProviders,
fileManager,
compiler, compiler,
udapp udapp
) )

Loading…
Cancel
Save