rubyx-debugger/lib/blocks_view.rb

39 lines
948 B
Ruby
Raw Normal View History

2015-08-22 18:37:42 +02:00
require_relative "block_view"
class BlocksView < ListView
2015-08-21 00:37:41 +02:00
def initialize interpreter
@interpreter = interpreter
@interpreter.register_event(:instruction_changed, self)
2015-08-22 18:37:42 +02:00
super([BlockView.new(@interpreter.block)])
2015-08-21 00:37:41 +02:00
end
def draw
super()
2015-08-22 18:37:42 +02:00
wrap_element div("div.block_view") << div("h4" , "Method #{method_name}") << div("h4" , "Block" )
return @element
2015-08-21 00:37:41 +02:00
end
2015-08-22 18:37:42 +02:00
def instruction_changed
return if @interpreter.block.name == active_block_name
@elements.last.at_css(".bright").remove_class("bright")
append( BlockView.new(@interpreter.block) )
remove_first if( @elements.length > 5)
2015-08-21 00:37:41 +02:00
end
2015-08-22 18:37:42 +02:00
def active_block_name
@children.last.block.name
2015-08-21 00:37:41 +02:00
end
def block_name
@interpreter.block ? @interpreter.block.name : ""
end
2015-08-22 18:37:42 +02:00
2015-08-21 00:37:41 +02:00
def method_name
bl = @interpreter.block
return "" unless bl
return bl.method if bl.method.is_a? String
"#{bl.method.for_class.name}.#{bl.method.name}"
end
end