redo object view as list, introduce ref view

This commit is contained in:
Torsten Ruger 2015-08-22 20:11:33 +02:00
parent caa1da342c
commit 7885ae93c4
5 changed files with 49 additions and 30 deletions

View File

@ -56,10 +56,17 @@ class ElementView
wrapper << node wrapper << node
end 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) # return the div that was passed in (use << to return the @element)
def add_element div def append_element div
div.append_to @element @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 div
end end
@ -67,7 +74,7 @@ class ElementView
# add that new element to the @element # add that new element to the @element
# return the newly created element # return the newly created element
def add class_or_id , tex = nil def add class_or_id , tex = nil
add_element div( class_or_id , tex) append_element div( class_or_id , tex)
end end

View File

@ -14,7 +14,7 @@ class ListView < ElementView
def draw root = "div" def draw root = "div"
@element = div(root) @element = div(root)
@elements = @children.collect do | c | @elements = @children.collect do | c |
add_element c.draw append_element c.draw
end end
@element @element
end end

View File

@ -1,54 +1,42 @@
require_relative "ref_view"
class ObjectView < ElementView class ObjectView < ListView
def initialize interpreter , object_id def initialize interpreter , object_id
@object_id = object_id @object_id = object_id
@interpreter = interpreter @interpreter = interpreter
@interpreter.register_event(:object_changed, self) @interpreter.register_event(:object_changed, self)
super( content_elements )
end end
def draw def draw
@element = div("ul.nav!") @element = super("ul.nav!")
add( "li" ) << div("span" , class_header(@object_id) ) prepend_element div("li" , "-------------------------")
@element << div("li" , "-------------------------") prepend_element div( "li" ) << div("span" , class_header(@object_id) )
content(@object_id).each do |con3|
add("li") << div("a" , con3[0])
end
return @element return @element
end end
def object_changed reg def object_changed reg , at
puts "Object changed in #{reg}" puts "Object changed in #{reg}"
for_object = @interpreter.get_register( reg ) for_object = @interpreter.get_register( reg )
return unless for_object == @object_id return unless for_object == @object_id
puts "Object changed #{for_object}" puts "Object changed #{for_object} , at #{at}"
calc_fields
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
def class_header(id) def class_header(id)
object = Virtual.machine.objects[id] object = Virtual.machine.objects[id]
return "" unless object
clazz = object.class.name.split("::").last clazz = object.class.name.split("::").last
"#{clazz}:#{id}" [clazz, id].join " : "
end end
def content(id) def content_elements
object = Virtual.machine.objects[id] object = Virtual.machine.objects[@object_id]
fields = [] fields = []
if object and ! object.is_a?(String) if object and ! object.is_a?(String)
object.get_instance_variables.each do |variable| object.get_instance_variables.each do |variable|
f = object.get_instance_variable(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
end end
fields fields

24
lib/ref_view.rb Normal file
View File

@ -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

View File

@ -8,7 +8,7 @@ class ValueView < ElementView
DOM do |dom| DOM do |dom|
dom.ul.nav! do dom.ul.nav! do
dom.li do dom.li do
dom.a( :href => "#" ) { @value } dom.span( :href => "#" ) { @value }
end end
end end
end end