diff --git a/lib/base/element_view.rb b/lib/base/element_view.rb index 48ac2d2..d278c06 100644 --- a/lib/base/element_view.rb +++ b/lib/base/element_view.rb @@ -56,10 +56,17 @@ class ElementView wrapper << node end - # add the given element the @element + # add the given element to the @element, at the end # return the div that was passed in (use << to return the @element) - def add_element div - div.append_to @element + def append_element div + @element << div + div + end + + # add the given element to the @element , at the front + # return the div that was passed in (use >> to return the @element) + def prepend_element div + @element >> div div end @@ -67,7 +74,7 @@ class ElementView # add that new element to the @element # return the newly created element def add class_or_id , tex = nil - add_element div( class_or_id , tex) + append_element div( class_or_id , tex) end diff --git a/lib/base/list_view.rb b/lib/base/list_view.rb index 515ff8b..2b535b9 100644 --- a/lib/base/list_view.rb +++ b/lib/base/list_view.rb @@ -14,7 +14,7 @@ class ListView < ElementView def draw root = "div" @element = div(root) @elements = @children.collect do | c | - add_element c.draw + append_element c.draw end @element end diff --git a/lib/object_view.rb b/lib/object_view.rb index 9a79b5d..aa44dc0 100644 --- a/lib/object_view.rb +++ b/lib/object_view.rb @@ -1,54 +1,42 @@ +require_relative "ref_view" -class ObjectView < ElementView +class ObjectView < ListView def initialize interpreter , object_id @object_id = object_id @interpreter = interpreter @interpreter.register_event(:object_changed, self) + super( content_elements ) end def draw - @element = div("ul.nav!") - add( "li" ) << div("span" , class_header(@object_id) ) - @element << div("li" , "-------------------------") - content(@object_id).each do |con3| - add("li") << div("a" , con3[0]) - end + @element = super("ul.nav!") + prepend_element div("li" , "-------------------------") + prepend_element div( "li" ) << div("span" , class_header(@object_id) ) return @element end - def object_changed reg + def object_changed reg , at puts "Object changed in #{reg}" for_object = @interpreter.get_register( reg ) return unless for_object == @object_id - puts "Object changed #{for_object}" - calc_fields - end + puts "Object changed #{for_object} , at #{at}" - def marker id - var = Virtual.machine.objects[id] - if var.is_a? String - str "Wo" - else - str = var.class.name.split("::").last[0,2] - end - str + " : #{id.to_s}" end def class_header(id) object = Virtual.machine.objects[id] - return "" unless object clazz = object.class.name.split("::").last - "#{clazz}:#{id}" + [clazz, id].join " : " end - def content(id) - object = Virtual.machine.objects[id] + def content_elements + object = Virtual.machine.objects[@object_id] fields = [] if object and ! object.is_a?(String) object.get_instance_variables.each do |variable| f = object.get_instance_variable(variable) - fields << ["#{variable} : #{marker(f.object_id)}" , f.object_id] + fields << RefView.new( variable , f.object_id ) end end fields diff --git a/lib/ref_view.rb b/lib/ref_view.rb new file mode 100644 index 0000000..c137dce --- /dev/null +++ b/lib/ref_view.rb @@ -0,0 +1,24 @@ +class RefView < ElementView + + def initialize name , value + @name = name + @value = value + end + + attr_accessor :value + + def draw + @element = div("li") << div("a" , "#{@name} : #{marker(@value)}" ) + end + + def marker id + var = Virtual.machine.objects[id] + if var.is_a? String + str "Wo" + else + str = var.class.name.split("::").last[0,2] + end + str + " : #{id.to_s}" + end + +end diff --git a/lib/value_view.rb b/lib/value_view.rb index ed913e8..ebd2571 100644 --- a/lib/value_view.rb +++ b/lib/value_view.rb @@ -8,7 +8,7 @@ class ValueView < ElementView DOM do |dom| dom.ul.nav! do dom.li do - dom.a( :href => "#" ) { @value } + dom.span( :href => "#" ) { @value } end end end