allow for empty view

and reset view when interpreter restarts
This commit is contained in:
Torsten Ruger 2015-10-21 14:05:18 +03:00
parent 906017d1eb
commit 94292bf1ca
3 changed files with 26 additions and 5 deletions

View File

@ -4,7 +4,10 @@ class BlocksView < ListView
def initialize interpreter def initialize interpreter
@interpreter = interpreter @interpreter = interpreter
@interpreter.register_event(:instruction_changed, self) @interpreter.register_event(:instruction_changed, self)
super([BlockView.new(@interpreter.block)]) @interpreter.register_event(:state_changed, self)
show = []
show << BlockView.new(@interpreter.block) if @interpreter.block
super(show)
@method_name = method_name @method_name = method_name
end end
@ -20,12 +23,19 @@ class BlocksView < ListView
@method_name = new_name @method_name = new_name
@element.at_css(".method").text = method_name @element.at_css(".method").text = method_name
end end
return if @interpreter.block.object_id == @children.last.block.object_id if @children.last
@elements.last.at_css(".bright").remove_class("bright") return if @interpreter.block.object_id == @children.last.block.object_id
@elements.last.at_css(".bright").remove_class("bright")
end
append_view( BlockView.new(@interpreter.block) ) append_view( BlockView.new(@interpreter.block) )
remove_first if( @elements.length > 6) remove_first if( @elements.length > 6)
end end
def state_changed old , new_s
return unless new_s == :running
clear_view
end
def method_name def method_name
bl = @interpreter.block bl = @interpreter.block
return "" unless bl return "" unless bl

View File

@ -15,7 +15,7 @@ class ClassesView < ListView
def draw def draw
super() super()
wrap_element div("ul.nav!") wrap_element div("ul.nav!")
wrap_element( div(".classes") << div("h4" , "Classes") ) wrap_element( div("h4" , "Classes") )
return @element return @element
end end

View File

@ -5,8 +5,13 @@ class InstructionView < ListView
def initialize interpreter def initialize interpreter
@interpreter = interpreter @interpreter = interpreter
super([ConstantView.new( "span.bright" , "starting" )]) super([start_view])
@interpreter.register_event(:instruction_changed, self) @interpreter.register_event(:instruction_changed, self)
@interpreter.register_event(:state_changed, self)
end
def start_view
ConstantView.new( "span.bright" , "starting" )
end end
def instruction_changed def instruction_changed
@ -23,6 +28,12 @@ class InstructionView < ListView
@element @element
end end
def state_changed old , new_s
return unless new_s == :running
clear_view
append_view start_view
end
def instruction_text def instruction_text
return "" unless @interpreter.instruction return "" unless @interpreter.instruction
@interpreter.instruction.to_s @interpreter.instruction.to_s