2015-08-22 20:11:33 +02:00
|
|
|
require_relative "ref_view"
|
2015-07-13 22:11:00 +02:00
|
|
|
|
2015-08-22 20:11:33 +02:00
|
|
|
class ObjectView < ListView
|
2015-07-13 22:11:00 +02:00
|
|
|
|
2015-10-04 21:39:02 +02:00
|
|
|
# z is the z-index
|
|
|
|
|
2015-08-23 02:16:32 +02:00
|
|
|
def initialize object_id , interpreter = nil , z = nil
|
2015-08-21 19:07:27 +02:00
|
|
|
@object_id = object_id
|
2015-08-23 02:16:32 +02:00
|
|
|
@z = z
|
2015-08-21 19:07:27 +02:00
|
|
|
@interpreter = interpreter
|
2015-08-22 21:17:32 +02:00
|
|
|
@interpreter.register_event(:object_changed, self) if interpreter
|
2015-08-22 20:11:33 +02:00
|
|
|
super( content_elements )
|
2015-07-13 22:11:00 +02:00
|
|
|
end
|
|
|
|
|
2015-08-21 19:07:27 +02:00
|
|
|
def draw
|
2015-08-22 21:17:32 +02:00
|
|
|
@element = super(@interpreter ? "ul.nav!" : "ul")
|
2015-08-22 20:11:33 +02:00
|
|
|
prepend_element div("li" , "-------------------------")
|
|
|
|
prepend_element div( "li" ) << div("span" , class_header(@object_id) )
|
2015-08-22 17:19:07 +02:00
|
|
|
return @element
|
2015-07-14 12:07:28 +02:00
|
|
|
end
|
|
|
|
|
2015-08-22 20:11:33 +02:00
|
|
|
def object_changed reg , at
|
2015-10-04 21:39:02 +02:00
|
|
|
at = at - 1 #take the layout off
|
|
|
|
#puts "Object changed in #{reg}"
|
2015-08-22 02:40:19 +02:00
|
|
|
for_object = @interpreter.get_register( reg )
|
|
|
|
return unless for_object == @object_id
|
2015-10-04 21:39:02 +02:00
|
|
|
#puts "Object changed #{for_object} , at #{at}"
|
|
|
|
object = Virtual.machine.objects[@object_id]
|
|
|
|
raise "error #{@object_id} , #{at}" unless object and ! object.is_a?(String)
|
|
|
|
variable = object.get_instance_variables.get(at)
|
2015-10-22 13:44:37 +02:00
|
|
|
if(variable)
|
|
|
|
f = object.get_instance_variable(variable)
|
|
|
|
else
|
|
|
|
at += 1 # add layout back
|
|
|
|
variable = at.to_s
|
|
|
|
f = object.internal_object_get(at)
|
|
|
|
end
|
2015-10-22 16:09:05 +02:00
|
|
|
#puts "got var name #{variable}#{variable.class} for #{at}, #{f}"
|
2015-10-22 13:44:37 +02:00
|
|
|
view = RefView.new( variable , f.object_id , @z )
|
|
|
|
if( @children[at] )
|
|
|
|
replace_at(at , view)
|
|
|
|
else
|
|
|
|
append_view(view)
|
|
|
|
end
|
2015-07-13 22:11:00 +02:00
|
|
|
end
|
2015-08-21 19:07:27 +02:00
|
|
|
|
|
|
|
def class_header(id)
|
|
|
|
object = Virtual.machine.objects[id]
|
|
|
|
clazz = object.class.name.split("::").last
|
2015-08-22 20:11:33 +02:00
|
|
|
[clazz, id].join " : "
|
2015-07-13 22:11:00 +02:00
|
|
|
end
|
2015-08-21 19:07:27 +02:00
|
|
|
|
2015-08-22 20:11:33 +02:00
|
|
|
def content_elements
|
|
|
|
object = Virtual.machine.objects[@object_id]
|
2015-08-21 19:07:27 +02:00
|
|
|
fields = []
|
|
|
|
if object and ! object.is_a?(String)
|
2015-08-25 09:57:08 +02:00
|
|
|
fields << RefView.new( "layout" , object.get_layout.object_id , @z )
|
2015-08-21 19:07:27 +02:00
|
|
|
object.get_instance_variables.each do |variable|
|
|
|
|
f = object.get_instance_variable(variable)
|
2015-08-23 02:16:32 +02:00
|
|
|
fields << RefView.new( variable , f.object_id , @z )
|
2015-08-21 19:07:27 +02:00
|
|
|
end
|
2015-08-25 11:54:44 +02:00
|
|
|
if( object.is_a?(Parfait::List) )
|
|
|
|
index = 1
|
|
|
|
object.each do | o , i|
|
|
|
|
fields << RefView.new( index.to_s , o.object_id , @z )
|
|
|
|
index += 1
|
|
|
|
end
|
|
|
|
end
|
2015-08-21 19:07:27 +02:00
|
|
|
end
|
|
|
|
fields
|
2015-07-13 22:11:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|