Merge pull request #1491 from ethereum/addAPIs2

Improve API
pull/1/head
yann300 6 years ago committed by GitHub
commit 00eba199bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      src/app/editor/sourceHighlighter.js
  2. 2
      src/app/panels/righthand-panel.js
  3. 41
      src/app/plugin/pluginAPI.js
  4. 3
      src/app/plugin/pluginManager.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: {

@ -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
)

@ -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, compiler, udapp) => {
module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => {
var highlighter = new SourceHighlighter()
return {
app: {
getExecutionContextProvider: (mod, cb) => {
@ -63,6 +64,42 @@ module.exports = (pluginManager, fileProviders, compiler, udapp) => {
cb(error, address)
})
}
},
editor: {
getCurrentFile: (mod, cb) => {
var path = fileManager.currentPath()
if (!path) {
cb('no file selected')
} else {
cb(null, path)
}
},
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')
}
},
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')
}
},
highlight: (mod, lineColumnPos, filePath, hexColor, cb) => {
highlighter.currentSourceLocation(null)
highlighter.currentSourceLocation(lineColumnPos, filePath, hexColor)
}
}
}
}

@ -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
)

Loading…
Cancel
Save