rubyx-debugger/lib/views/blocks_view.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

class BlocksView < ListView
2015-08-21 00:37:41 +02:00
def initialize interpreter
@interpreter = interpreter
@interpreter.register_event(:instruction_changed, self)
@interpreter.register_event(:state_changed, self)
show = []
2015-10-27 11:46:53 +01:00
show << LabelView.new(@interpreter.instruction) if @interpreter.instruction.is_a?(Register::Label)
super(show)
2015-08-21 00:37:41 +02:00
end
def draw
super()
2015-10-27 11:46:53 +01:00
wrap_element div("div.label_view") << div("h4" , "Method + Block " ) << div("h4.method" , @method_name)
return @element
2015-08-21 00:37:41 +02:00
end
2015-08-22 18:37:42 +02:00
def instruction_changed
2015-10-27 11:46:53 +01:00
return unless @interpreter.instruction.is_a?(Register::Label)
if @children.last
2015-10-27 11:46:53 +01:00
return if @interpreter.instruction.object_id == @children.last.label.object_id
@elements.last.at_css(".bright").remove_class("bright")
end
2015-10-27 11:46:53 +01:00
append_view( LabelView.new(@interpreter.instruction) )
remove_first if( @elements.length > 6)
2015-08-21 00:37:41 +02:00
end
2015-08-22 18:37:42 +02:00
def state_changed old , new_s
return unless new_s == :running
clear_view
end
2015-08-21 00:37:41 +02:00
end
2015-08-24 01:49:41 +02:00
2015-10-27 11:46:53 +01:00
class LabelView < ElementView
2015-08-24 01:49:41 +02:00
2015-10-27 11:46:53 +01:00
def initialize label
@label = label
2015-08-24 01:49:41 +02:00
end
2015-10-27 11:46:53 +01:00
attr_reader :label
2015-08-24 01:49:41 +02:00
def draw
2015-10-27 11:46:53 +01:00
@element = div("div") << div("span.bright" , label_name )
2015-08-24 02:19:41 +02:00
end
2015-10-27 11:46:53 +01:00
def label_name
return @label if @label.is_a? String
@label.name
2015-08-24 01:49:41 +02:00
end
end