2015-08-22 17:30:27 +02:00
|
|
|
|
|
|
|
class BlocksView < ListView
|
2015-08-21 00:37:41 +02:00
|
|
|
|
|
|
|
def initialize interpreter
|
|
|
|
@interpreter = interpreter
|
|
|
|
@interpreter.register_event(:instruction_changed, self)
|
2015-10-21 13:05:18 +02:00
|
|
|
@interpreter.register_event(:state_changed, self)
|
|
|
|
show = []
|
|
|
|
show << BlockView.new(@interpreter.block) if @interpreter.block
|
|
|
|
super(show)
|
2015-08-23 02:28:31 +02:00
|
|
|
@method_name = method_name
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2015-08-22 17:30:27 +02:00
|
|
|
super()
|
2015-08-24 02:19:41 +02:00
|
|
|
wrap_element div("div.block_view") << div("h4" , "Method + Block " ) << div("h4.method" , @method_name)
|
2015-08-22 17:30:27 +02:00
|
|
|
return @element
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
|
|
|
|
2015-08-22 18:37:42 +02:00
|
|
|
def instruction_changed
|
2015-08-24 02:19:41 +02:00
|
|
|
new_name = method_name
|
|
|
|
unless new_name == @method_name
|
|
|
|
@method_name = new_name
|
|
|
|
@element.at_css(".method").text = method_name
|
|
|
|
end
|
2015-10-21 13:05:18 +02:00
|
|
|
if @children.last
|
|
|
|
return if @interpreter.block.object_id == @children.last.block.object_id
|
|
|
|
@elements.last.at_css(".bright").remove_class("bright")
|
|
|
|
end
|
2015-08-24 02:04:07 +02:00
|
|
|
append_view( BlockView.new(@interpreter.block) )
|
|
|
|
remove_first if( @elements.length > 6)
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
2015-08-22 18:37:42 +02:00
|
|
|
|
2015-10-21 13:05:18 +02:00
|
|
|
def state_changed old , new_s
|
|
|
|
return unless new_s == :running
|
|
|
|
clear_view
|
|
|
|
end
|
|
|
|
|
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
|
2015-08-24 01:49:41 +02:00
|
|
|
|
|
|
|
class BlockView < ElementView
|
|
|
|
|
|
|
|
def initialize block
|
|
|
|
@block = block
|
|
|
|
end
|
|
|
|
attr_reader :block
|
|
|
|
|
|
|
|
def draw
|
2015-08-24 02:19:41 +02:00
|
|
|
@element = div("div") << div("span.bright" , block_name )
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_name
|
|
|
|
return @block.method if @block.method.is_a? String
|
|
|
|
@block.method.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def block_name
|
|
|
|
return @block if @block.is_a? String
|
|
|
|
"#{method_name}.#{@block.name}"
|
2015-08-24 01:49:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|