Merge pull request #1555 from ethereum/APIImprovement

Plugin API improvement
pull/1/head
yann300 6 years ago committed by GitHub
commit a73e2c4cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/app/panels/righthand-panel.js
  2. 9
      src/app/plugin/pluginAPI.js
  3. 2
      src/app/plugin/pluginManager.js
  4. 17
      src/app/tabs/settings-tab.js
  5. 4
      src/app/ui/draggableContent.js

@ -83,7 +83,7 @@ module.exports = class RighthandPanel {
}) })
var tab = new PluginTab(json) var tab = new PluginTab(json)
var content = tab.render() var content = tab.render()
document.querySelector('body').appendChild(modal.render(json.title, content)) document.querySelector('body').appendChild(modal.render(json.title, json.url, content))
self._components.pluginManager.register(json, modal, content) self._components.pluginManager.register(json, modal, content)
} }

@ -5,7 +5,7 @@ var SourceHighlighter = require('../editor/sourceHighlighter')
Defines available API. `key` / `type` Defines available API. `key` / `type`
*/ */
module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => { module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => {
var highlighter = new SourceHighlighter() let highlighters = {}
return { return {
app: { app: {
getExecutionContextProvider: (mod, cb) => { getExecutionContextProvider: (mod, cb) => {
@ -136,12 +136,13 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
} catch (e) { } catch (e) {
return cb(e.message) return cb(e.message)
} }
highlighter.currentSourceLocation(null) if (!highlighters[mod]) highlighters[mod] = new SourceHighlighter()
highlighter.currentSourceLocationFromfileName(position, filePath, hexColor) highlighters[mod].currentSourceLocation(null)
highlighters[mod].currentSourceLocationFromfileName(position, filePath, hexColor)
cb() cb()
}, },
discardHighlight: (mod, cb) => { discardHighlight: (mod, cb) => {
highlighter.currentSourceLocation(null) if (highlighters[mod]) highlighters[mod].currentSourceLocation(null)
cb() cb()
} }
} }

@ -90,6 +90,7 @@ module.exports = class PluginManager {
compiler, compiler,
udapp udapp
) )
self._components = { pluginAPI }
self.plugins = {} self.plugins = {}
self.origins = {} self.origins = {}
self.inFocus self.inFocus
@ -181,6 +182,7 @@ module.exports = class PluginManager {
} }
unregister (desc) { unregister (desc) {
const self = this const self = this
self._components.pluginAPI.editor.discardHighlight(desc.title, () => {})
delete self.plugins[desc.title] delete self.plugins[desc.title]
delete self.origins[desc.url] delete self.origins[desc.url]
} }

@ -136,14 +136,15 @@ module.exports = class SettingsTab {
function loadPlugins (plugins, opt) { function loadPlugins (plugins, opt) {
for (var k in plugins) { for (var k in plugins) {
var plugin = plugins[k] (function (plugin) {
if (!self._view.plugins[plugin.title]) self._view.plugins[plugin.title] = {} if (!self._view.plugins[plugin.title]) self._view.plugins[plugin.title] = {}
self._view.plugins[plugin.title].json = plugin self._view.plugins[plugin.title].json = plugin
self._view.plugins[plugin.title].el = yo`<div title=${plugin.title} class="${css.pluginLoad}"> self._view.plugins[plugin.title].el = yo`<div title=${plugin.title} class="${css.pluginLoad}">
<div class="${css.aPlugin}" onclick=${() => { onLoadPlugin(plugin.title) }}>${plugin.title}</div> <div class="${css.aPlugin}" onclick=${() => { onLoadPlugin(plugin.title) }}>${plugin.title}</div>
${opt.removable ? yo`<span class="${css.removePlugin}" onclick=${() => { onRemovePlugin(plugin.title) }}><i class="fa fa-close"></i></span>` : yo`<span></span>`} ${opt.removable ? yo`<span class="${css.removePlugin}" onclick=${() => { onRemovePlugin(plugin.title) }}><i class="fa fa-close"></i></span>` : yo`<span></span>`}
</div>` </div>`
self._view.config.plugins.appendChild(self._view.plugins[plugin.title].el) self._view.config.plugins.appendChild(self._view.plugins[plugin.title].el)
})(plugins[k])
} }
} }

@ -43,12 +43,12 @@ module.exports =
this.closeCb = closeCb this.closeCb = closeCb
} }
render (title, content) { render (title, url, content) {
this.content = content this.content = content
var el = yo` var el = yo`
<div class=${css.containerDraggableModal}> <div class=${css.containerDraggableModal}>
<div> <div>
<div class="${css.headerDraggableModal} title" title=${title}><span>${title}</span> <div class="${css.headerDraggableModal} title" title=${title}><span title="${title}" >${title}</span><span title="${url}" > - ${url}</span>
<div class=${css.modalActions}> <div class=${css.modalActions}>
<i onclick=${() => { this.minimize() }} class="fa fa-window-minimize ${css.modalAction}"></i> <i onclick=${() => { this.minimize() }} class="fa fa-window-minimize ${css.modalAction}"></i>
<i onclick=${() => { this.maximise() }} class="fa fa-window-maximize ${css.modalAction}"></i> <i onclick=${() => { this.maximise() }} class="fa fa-window-maximize ${css.modalAction}"></i>

Loading…
Cancel
Save