redo object view as list, introduce ref view
This commit is contained in:
parent
caa1da342c
commit
7885ae93c4
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
24
lib/ref_view.rb
Normal file
24
lib/ref_view.rb
Normal 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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user