add contextview to editorpanel

pull/1/head
yann300 7 years ago
parent b000cab750
commit 31361b4dc1
  1. 50
      src/app/editor/contextView.js
  2. 13
      src/app/panels/editor-panel.js

@ -7,9 +7,13 @@ var csjs = require('csjs-inject')
var css = csjs` var css = csjs`
.contextview { .contextview {
position : absolute;
background-color : ${styles.colors.backgroundBlue}; background-color : ${styles.colors.backgroundBlue};
opacity : 0.8; opacity : 0.8;
width : 20em;
height : 5em;
border-color : transparent;
border-radius : 3px;
border : .3px solid hsla(0, 0%, 40%, .2);
} }
` `
@ -26,6 +30,7 @@ class ContextView {
this._event = event this._event = event
this._view this._view
this._nodes this._nodes
this._current
event.contextualListener.register('contextChanged', nodes => { event.contextualListener.register('contextChanged', nodes => {
this._nodes = nodes this._nodes = nodes
this.update() this.update()
@ -35,36 +40,59 @@ class ContextView {
render () { render () {
var view = yo`<div class=${css.contextview}> var view = yo`<div class=${css.contextview}>
<div> <div>
<span>${this._renderItems()}</span> <span>${this._renderTarget()}</span>
</div> </div>
</div>` </div>`
if (!this._view) { if (!this._view) {
this._view = view this._view = view
this.hide()
} }
return view return view
} }
hide () {
if (this._view) {
this._view.style.display = 'none'
}
}
show () {
if (this._view) {
this._view.style.display = 'block'
}
}
update () { update () {
if (this._view) { if (this._view) {
yo.update(this._view, this.render()) yo.update(this._view, this.render())
this._view.style.display = this._current ? 'block' : 'none'
} }
} }
_renderItems () { _renderTarget () {
this._current = null
if (this._nodes && this._nodes.length) { if (this._nodes && this._nodes.length) {
var last = this._nodes[this._nodes.length - 1] var last = this._nodes[this._nodes.length - 1]
if (this._api.contextualListener.declarationOf(last)) { if (last.name === 'ContractDefinition' || last.name === 'FunctionDefinition' || last.name === 'ModifierDefinition' || last.name === 'VariableDeclaration') {
return renderReference(last) this._current = last
} else {
var target = this._api.contextualListener.declarationOf(last)
if (target) {
this._current = target
}
} }
} }
return yo`` return this._renderDeclarations(this._current)
} }
}
_renderDeclarations (node) {
function renderReference (node) { if (!node) return yo`<div></div>`
yo`<div><span>${node.name}</span></div>` var references = this._api.contextualListener.referencesOf(node)
references = yo`<div>${references ? references.length : '0'} references</div>`
return yo`<div><div>${node.attributes.type} ${node.attributes.name} (${node.name})</div>
<div>${references}</div>
</div>`
}
} }
module.exports = ContextView module.exports = ContextView

@ -123,9 +123,17 @@ var css = csjs`
width : 100%; width : 100%;
} }
.banner { .banner {
width : 25em; width : 25em;
} }
.contextviewcontainer{
position : absolute;
z-index : 100;
right : 20px;
top : 20px;
width : 20em;
}
` `
class EditorPanel { class EditorPanel {
@ -221,6 +229,9 @@ class EditorPanel {
self._view.terminal = self._components.terminal.render() self._view.terminal = self._components.terminal.render()
self._view.content = yo` self._view.content = yo`
<div class=${css.content}> <div class=${css.content}>
<div class=${css.contextviewcontainer}>
${self._api.contextview.render()}
</div>
${self._view.editor} ${self._view.editor}
${self._view.terminal} ${self._view.terminal}
</div> </div>

Loading…
Cancel
Save