From c450e4dbf3eebc5b003e395ffbce8c7eaa1be0fd Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 12:34:16 +0200 Subject: [PATCH 1/3] add editor getCurrent, get, set --- src/app/panels/righthand-panel.js | 2 ++ src/app/plugin/pluginAPI.js | 32 ++++++++++++++++++++++++++++++- src/app/plugin/pluginManager.js | 3 ++- 3 files changed, 35 insertions(+), 2 deletions(-) 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 ) From e3a98ab74c54e52bbdf11b067cf515d7ae3962f0 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 13:20:42 +0200 Subject: [PATCH 2/3] highlight content --- src/app/editor/sourceHighlighter.js | 43 +++++++++++++++++++---------- src/app/panels/righthand-panel.js | 2 +- src/app/plugin/pluginAPI.js | 13 +++++++-- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/app/editor/sourceHighlighter.js b/src/app/editor/sourceHighlighter.js index 13839c6c73..8a64d52580 100644 --- a/src/app/editor/sourceHighlighter.js +++ b/src/app/editor/sourceHighlighter.js @@ -4,20 +4,6 @@ var globlalRegistry = require('../../global/registry') var styleGuide = require('../ui/styles-guide/theme-chooser') var styles = styleGuide.chooser() -var css = csjs` - .highlightcode { - position:absolute; - z-index:20; - background-color: ${styles.editor.backgroundColor_DebuggerMode}; - } - .highlightcode_fullLine { - position:absolute; - z-index:20; - background-color: ${styles.editor.backgroundColor_DebuggerMode}; - opacity: 0.5; - } -` - class SourceHighlighter { constructor (localRegistry) { const self = this @@ -36,18 +22,45 @@ class SourceHighlighter { } currentSourceLocation (lineColumnPos, location) { + if (this.statementMarker) this._deps.editor.removeMarker(this.statementMarker, this.source) + if (this.fullLineMarker) this._deps.editor.removeMarker(this.fullLineMarker, this.source) + if (location && location.file !== undefined) { + var path = this._deps.compiler.getSourceName(location.file) + if (path) { + this.currentSourceLocationFromfileName(lineColumnPos, path) + } + } + } + + currentSourceLocationFromfileName (lineColumnPos, filePath, style) { if (this.statementMarker) this._deps.editor.removeMarker(this.statementMarker, this.source) if (this.fullLineMarker) this._deps.editor.removeMarker(this.fullLineMarker, this.source) this.statementMarker = null this.fullLineMarker = null this.source = null if (lineColumnPos) { - this.source = this._deps.compiler.getSourceName(location.file) + this.source = filePath if (this._deps.config.get('currentFile') !== this.source) { this._deps.fileManager.switchFile(this.source) } + + var css = csjs` + .highlightcode { + position:absolute; + z-index:20; + background-color: ${style || styles.editor.backgroundColor_DebuggerMode}; + } + .highlightcode_fullLine { + position:absolute; + z-index:20; + background-color: ${style || styles.editor.backgroundColor_DebuggerMode}; + opacity: 0.5; + } + ` + this.statementMarker = this._deps.editor.addMarker(lineColumnPos, this.source, css.highlightcode) this._deps.editor.scrollToLine(lineColumnPos.start.line, true, true, function () {}) + if (lineColumnPos.start.line === lineColumnPos.end.line) { this.fullLineMarker = this._deps.editor.addMarker({ start: { diff --git a/src/app/panels/righthand-panel.js b/src/app/panels/righthand-panel.js index c4a9784bf4..969d5f5525 100644 --- a/src/app/panels/righthand-panel.js +++ b/src/app/panels/righthand-panel.js @@ -36,7 +36,7 @@ module.exports = class RighthandPanel { self._deps = { fileProviders: self._components.registry.get('fileproviders').api, - fileManager: self._components.registry.get('fileManager').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, diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 39d28c8184..a1fdae2aae 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -1,10 +1,11 @@ 'use strict' var executionContext = require('../../execution-context') - +var SourceHighlighter = require('../editor/sourceHighlighter') /* Defines available API. `key` / `type` */ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => { + var highlighter = new SourceHighlighter() return { app: { getExecutionContextProvider: (mod, cb) => { @@ -76,22 +77,28 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => getFile: (mod, path, cb) => { var provider = fileManager.fileProviderOf(path) if (provider) { + // TODO add approval to user for external plugin to get the content of the given `path` provider.get(mod + '/' + path, (error, content) => { cb(error, content) }) } else { - cb(path + 'not available') + cb(path + ' not available') } }, setFile: (mod, path, content, cb) => { var provider = fileManager.fileProviderOf(path) if (provider) { + // TODO add approval to user for external plugin to set the content of the given `path` provider.set(mod + '/' + path, content, (error) => { cb(error) }) } else { - cb(path + 'not available') + cb(path + ' not available') } + }, + highlight: (mod, lineColumnPos, filePath, hexColor, cb) => { + highlighter.currentSourceLocation(null) + highlighter.currentSourceLocation(lineColumnPos, filePath, hexColor) } } } From 0cd0dd6ea2500935b6e4146a248f35df3550f14e Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 15:31:06 +0200 Subject: [PATCH 3/3] `getCurrentFile` returns a path --- src/app/plugin/pluginAPI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index a1fdae2aae..c0d1f2f389 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -71,7 +71,7 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => if (!path) { cb('no file selected') } else { - this.getFile(mod, path, cb) + cb(null, path) } }, getFile: (mod, path, cb) => {