From 94292bf1cafeb56e97e260f6ce1f805d4b4e9b1e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 21 Oct 2015 14:05:18 +0300 Subject: [PATCH] allow for empty view and reset view when interpreter restarts --- lib/views/blocks_view.rb | 16 +++++++++++++--- lib/views/classes_view.rb | 2 +- lib/views/instruction_view.rb | 13 ++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/views/blocks_view.rb b/lib/views/blocks_view.rb index ce9bb4b..90fd80e 100644 --- a/lib/views/blocks_view.rb +++ b/lib/views/blocks_view.rb @@ -4,7 +4,10 @@ class BlocksView < ListView def initialize interpreter @interpreter = interpreter @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 end @@ -20,12 +23,19 @@ class BlocksView < ListView @method_name = new_name @element.at_css(".method").text = method_name end - return if @interpreter.block.object_id == @children.last.block.object_id - @elements.last.at_css(".bright").remove_class("bright") + if @children.last + 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) ) remove_first if( @elements.length > 6) end + def state_changed old , new_s + return unless new_s == :running + clear_view + end + def method_name bl = @interpreter.block return "" unless bl diff --git a/lib/views/classes_view.rb b/lib/views/classes_view.rb index cf9f57c..2c28a22 100644 --- a/lib/views/classes_view.rb +++ b/lib/views/classes_view.rb @@ -15,7 +15,7 @@ class ClassesView < ListView def draw super() wrap_element div("ul.nav!") - wrap_element( div(".classes") << div("h4" , "Classes") ) + wrap_element( div("h4" , "Classes") ) return @element end diff --git a/lib/views/instruction_view.rb b/lib/views/instruction_view.rb index ed30aff..698b746 100644 --- a/lib/views/instruction_view.rb +++ b/lib/views/instruction_view.rb @@ -5,8 +5,13 @@ class InstructionView < ListView def initialize interpreter @interpreter = interpreter - super([ConstantView.new( "span.bright" , "starting" )]) + super([start_view]) @interpreter.register_event(:instruction_changed, self) + @interpreter.register_event(:state_changed, self) + end + + def start_view + ConstantView.new( "span.bright" , "starting" ) end def instruction_changed @@ -23,6 +28,12 @@ class InstructionView < ListView @element end + def state_changed old , new_s + return unless new_s == :running + clear_view + append_view start_view + end + def instruction_text return "" unless @interpreter.instruction @interpreter.instruction.to_s