remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/remix-debugger/src/ui/CodeListView.js

91 lines
2.7 KiB

8 years ago
'use strict'
var style = require('./styles/basicStyles')
var yo = require('yo-yo')
7 years ago
var remixLib = require('remix-lib')
var ui = remixLib.helpers.ui
8 years ago
var DropdownPanel = require('./DropdownPanel')
7 years ago
var EventManager = remixLib.EventManager
var csjs = require('csjs-inject')
var styleGuide = remixLib.ui.styleGuide
var styles = styleGuide()
8 years ago
var css = csjs`
.instructions {
${styles.rightPanel.debuggerTab.box_Debugger}
width: 75%;
overflow-y: scroll;
max-height: 250px;
}
`
8 years ago
function CodeListView (_parent, _codeManager) {
this.event = new EventManager()
8 years ago
this.parent = _parent
this.codeManager = _codeManager
this.code
this.address
this.codeView
this.itemSelected
this.basicPanel = new DropdownPanel('Instructions', {json: false})
this.basicPanel.event.register('hide', () => {
this.event.trigger('hide', [])
})
this.basicPanel.event.register('show', () => {
this.event.trigger('show', [])
})
8 years ago
this.init()
}
8 years ago
CodeListView.prototype.render = function () {
8 years ago
return yo`<div id='asmcodes' >${this.basicPanel.render({height: style.instructionsList.height})}</div>`
}
8 years ago
CodeListView.prototype.init = function () {
8 years ago
var self = this
this.codeManager.event.register('changed', this, this.changed)
this.parent.event.register('traceUnloaded', this, function () {
8 years ago
self.changed([], '', -1)
})
}
8 years ago
CodeListView.prototype.indexChanged = function (index) {
8 years ago
if (index >= 0) {
if (this.itemSelected) {
8 years ago
this.itemSelected.removeAttribute('selected')
8 years ago
this.itemSelected.removeAttribute('style')
if (this.itemSelected.firstChild) {
this.itemSelected.firstChild.removeAttribute('style')
}
8 years ago
}
this.itemSelected = this.codeView.children[index]
this.itemSelected.setAttribute('style', ui.formatCss({'background-color': '#eeeeee'}))
8 years ago
this.itemSelected.setAttribute('selected', 'selected')
if (this.itemSelected.firstChild) {
this.itemSelected.firstChild.setAttribute('style', ui.formatCss({'margin-left': '2px'}))
}
this.codeView.scrollTop = this.itemSelected.offsetTop - parseInt(this.codeView.offsetTop)
8 years ago
}
}
8 years ago
CodeListView.prototype.changed = function (code, address, index) {
8 years ago
if (this.address !== address) {
this.code = code
this.address = address
this.codeView = this.renderAssemblyItems()
this.basicPanel.setContent(this.codeView)
8 years ago
}
this.indexChanged(index)
}
8 years ago
CodeListView.prototype.renderAssemblyItems = function () {
8 years ago
if (this.code) {
var codeView = this.code.map(function (item, i) {
8 years ago
return yo`<div key=${i} value=${i}><span>${item}</span></div>`
8 years ago
})
return yo`<div class=${css.instructions} id='asmitems' ref='itemsList'>
8 years ago
${codeView}
8 years ago
</div>`
8 years ago
}
}
8 years ago
module.exports = CodeListView