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-11-04 19:29:09 +01:00
|
|
|
def initialize object , interpreter = nil , z = nil
|
|
|
|
@object = object
|
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-11-04 19:29:09 +01:00
|
|
|
prepend_element div( "li" ) << div("span" , class_header )
|
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-27 19:08:23 +01:00
|
|
|
#puts "Object changed in #{reg} , at #{at}"
|
2015-08-22 02:40:19 +02:00
|
|
|
for_object = @interpreter.get_register( reg )
|
2015-11-04 19:29:09 +01:00
|
|
|
return unless for_object == @object
|
2015-10-04 21:39:02 +02:00
|
|
|
#puts "Object changed #{for_object} , at #{at}"
|
2015-11-04 19:29:09 +01:00
|
|
|
variable = @object.get_instance_variables.get(at)
|
2015-10-22 13:44:37 +02:00
|
|
|
if(variable)
|
2015-11-04 19:29:09 +01:00
|
|
|
f = @object.get_instance_variable(variable)
|
2015-10-22 13:44:37 +02:00
|
|
|
else
|
2015-11-04 19:29:09 +01:00
|
|
|
variable = (at - @object.class.get_length_index).to_s
|
2015-11-24 15:26:49 +01:00
|
|
|
f = @object.get_internal_word(at)
|
2015-10-22 13:44:37 +02:00
|
|
|
end
|
2015-10-22 16:09:05 +02:00
|
|
|
#puts "got var name #{variable}#{variable.class} for #{at}, #{f}"
|
2015-11-04 19:29:09 +01:00
|
|
|
view = RefView.new( variable , f , @z )
|
2015-10-27 19:08:23 +01:00
|
|
|
if( @children[at] )
|
|
|
|
replace_at(at , view)
|
2015-10-22 13:44:37 +02:00
|
|
|
else
|
|
|
|
append_view(view)
|
|
|
|
end
|
2015-07-13 22:11:00 +02:00
|
|
|
end
|
2015-08-21 19:07:27 +02:00
|
|
|
|
2015-11-04 19:29:09 +01:00
|
|
|
def class_header
|
|
|
|
clazz = @object.class.name.split("::").last
|
2018-04-03 17:24:57 +02:00
|
|
|
[clazz, @object.object_id.to_s(16)].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
|
2015-10-27 19:08:23 +01:00
|
|
|
fields = [ConstantView.new("li" , "-------------------------")]
|
2015-11-04 19:29:09 +01:00
|
|
|
object = @object
|
2015-08-21 19:07:27 +02:00
|
|
|
if object and ! object.is_a?(String)
|
|
|
|
object.get_instance_variables.each do |variable|
|
|
|
|
f = object.get_instance_variable(variable)
|
2015-11-04 19:29:09 +01:00
|
|
|
fields << RefView.new( variable , f , @z )
|
2015-08-21 19:07:27 +02:00
|
|
|
end
|
2018-04-03 17:24:57 +02:00
|
|
|
if( object.is_a?(Parfait::List) )
|
2015-08-25 11:54:44 +02:00
|
|
|
index = 1
|
2015-10-27 17:09:50 +01:00
|
|
|
object.each do | o|
|
2015-11-04 19:29:09 +01:00
|
|
|
fields << RefView.new( index.to_s , o , @z )
|
2015-08-25 11:54:44 +02:00
|
|
|
index += 1
|
|
|
|
end
|
|
|
|
end
|
2015-08-21 19:07:27 +02:00
|
|
|
end
|
|
|
|
fields
|
2015-07-13 22:11:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|