no more blocks, replace with labels

This commit is contained in:
Torsten Ruger 2015-10-27 12:46:53 +02:00
parent 76a698f028
commit 922ec10f93

View File

@ -6,28 +6,23 @@ class BlocksView < ListView
@interpreter.register_event(:instruction_changed, self) @interpreter.register_event(:instruction_changed, self)
@interpreter.register_event(:state_changed, self) @interpreter.register_event(:state_changed, self)
show = [] show = []
show << BlockView.new(@interpreter.block) if @interpreter.block show << LabelView.new(@interpreter.instruction) if @interpreter.instruction.is_a?(Register::Label)
super(show) super(show)
@method_name = method_name
end end
def draw def draw
super() super()
wrap_element div("div.block_view") << div("h4" , "Method + Block " ) << div("h4.method" , @method_name) wrap_element div("div.label_view") << div("h4" , "Method + Block " ) << div("h4.method" , @method_name)
return @element return @element
end end
def instruction_changed def instruction_changed
new_name = method_name return unless @interpreter.instruction.is_a?(Register::Label)
unless new_name == @method_name
@method_name = new_name
@element.at_css(".method").text = method_name
end
if @children.last if @children.last
return if @interpreter.block.object_id == @children.last.block.object_id return if @interpreter.instruction.object_id == @children.last.label.object_id
@elements.last.at_css(".bright").remove_class("bright") @elements.last.at_css(".bright").remove_class("bright")
end end
append_view( BlockView.new(@interpreter.block) ) append_view( LabelView.new(@interpreter.instruction) )
remove_first if( @elements.length > 6) remove_first if( @elements.length > 6)
end end
@ -36,33 +31,22 @@ class BlocksView < ListView
clear_view clear_view
end end
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 end
class BlockView < ElementView class LabelView < ElementView
def initialize block def initialize label
@block = block @label = label
end end
attr_reader :block attr_reader :label
def draw def draw
@element = div("div") << div("span.bright" , block_name ) @element = div("div") << div("span.bright" , label_name )
end end
def method_name def label_name
return @block.method if @block.method.is_a? String return @label if @label.is_a? String
@block.method.name @label.name
end
def block_name
return @block if @block.is_a? String
"#{method_name}.#{@block.name}"
end end
end end