diff --git a/src/app/panels/righthand-panel.js b/src/app/panels/righthand-panel.js index 077f0d4334..c4a9784bf4 100644 --- a/src/app/panels/righthand-panel.js +++ b/src/app/panels/righthand-panel.js @@ -36,6 +36,7 @@ module.exports = class RighthandPanel { self._deps = { fileProviders: self._components.registry.get('fileproviders').api, + fileManager: self._components.registry.get('fileManager').api, compiler: self._components.registry.get('compiler').api, udapp: self._components.registry.get('udapp').api, app: self._components.registry.get('app').api, @@ -49,6 +50,7 @@ module.exports = class RighthandPanel { self._deps.compiler, self._deps.txlistener, self._deps.fileProviders, + self._deps.fileManager, self._deps.udapp ) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 67e42541ce..39d28c8184 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -4,7 +4,7 @@ var executionContext = require('../../execution-context') /* Defines available API. `key` / `type` */ -module.exports = (pluginManager, fileProviders, compiler, udapp) => { +module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => { return { app: { getExecutionContextProvider: (mod, cb) => { @@ -63,6 +63,36 @@ module.exports = (pluginManager, fileProviders, compiler, udapp) => { 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') + } + } } } } diff --git a/src/app/plugin/pluginManager.js b/src/app/plugin/pluginManager.js index 1f04a610bd..8db691e34a 100644 --- a/src/app/plugin/pluginManager.js +++ b/src/app/plugin/pluginManager.js @@ -78,11 +78,12 @@ const PluginAPI = require('./pluginAPI') * */ module.exports = class PluginManager { - constructor (app, compiler, txlistener, fileProviders, udapp) { + constructor (app, compiler, txlistener, fileProviders, fileManager, udapp) { const self = this var pluginAPI = new PluginAPI( this, fileProviders, + fileManager, compiler, udapp )