rubyx-debugger/lib/blocks_view.rb

44 lines
1.1 KiB
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-23 02:28:31 +02:00
@method_name = method_name
2015-08-21 00:37:41 +02:00
end
def draw
super()
2015-08-23 02:28:31 +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-23 02:28:31 +02:00
new_name = method_name
return if new_name == @method_name
@method_name = new_name
@element.at_css(".method").text = method_name
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