2015-08-22 21:17:32 +02:00
|
|
|
class RefView < ListView
|
2015-08-22 20:11:33 +02:00
|
|
|
|
2015-08-23 02:16:32 +02:00
|
|
|
def initialize name , value , z = nil
|
2015-08-22 20:11:33 +02:00
|
|
|
@name = name
|
|
|
|
@value = value
|
2015-08-23 02:16:32 +02:00
|
|
|
@z = z
|
2015-08-22 21:17:32 +02:00
|
|
|
super []
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :value
|
|
|
|
|
|
|
|
def value= val
|
|
|
|
@value = val
|
|
|
|
add_hover
|
2015-08-22 20:11:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2015-10-29 22:36:04 +01:00
|
|
|
@element = div("li") << div("a" , ref_text )
|
2015-08-22 21:17:32 +02:00
|
|
|
add_hover
|
2015-08-23 02:16:32 +02:00
|
|
|
@element.style["z-index"] = @z if @z
|
2015-08-22 21:17:32 +02:00
|
|
|
@element
|
|
|
|
end
|
|
|
|
|
2015-10-29 22:36:04 +01:00
|
|
|
def ref_text
|
|
|
|
"#{@name} : #{marker(@value)}"
|
|
|
|
end
|
2015-11-04 11:20:44 +01:00
|
|
|
|
2015-08-22 21:17:32 +02:00
|
|
|
def add_hover
|
2015-08-25 11:54:44 +02:00
|
|
|
return if is_string?
|
2015-08-22 21:17:32 +02:00
|
|
|
@element.on("hover"){ hover } if is_object?(@value)
|
|
|
|
end
|
|
|
|
|
2015-08-25 11:54:44 +02:00
|
|
|
def is_object?( )
|
2015-11-04 11:20:44 +01:00
|
|
|
has = Register.machine.objects[@value]
|
|
|
|
return false unless has
|
|
|
|
! is_label?
|
2015-08-25 11:54:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_string?()
|
2015-10-27 11:44:02 +01:00
|
|
|
Register.machine.objects[@value].is_a? String
|
2015-08-25 11:54:44 +02:00
|
|
|
end
|
|
|
|
|
2015-11-04 11:20:44 +01:00
|
|
|
def is_label?
|
|
|
|
Register.machine.objects[@value].is_a?(Register::Label)
|
|
|
|
end
|
|
|
|
|
2015-08-25 11:54:44 +02:00
|
|
|
def is_nil?()
|
2015-10-27 11:44:02 +01:00
|
|
|
Register.machine.objects[@value].nil?
|
2015-08-22 20:11:33 +02:00
|
|
|
end
|
|
|
|
|
2015-08-22 21:17:32 +02:00
|
|
|
def hover
|
2015-10-04 21:39:02 +02:00
|
|
|
#puts "hovering #{@name}"
|
2015-08-24 02:04:07 +02:00
|
|
|
append_view ObjectView.new(@value)
|
2015-08-22 21:17:32 +02:00
|
|
|
@element.off("hover")
|
|
|
|
end
|
2015-08-23 02:16:32 +02:00
|
|
|
|
2015-08-22 20:11:33 +02:00
|
|
|
def marker id
|
2015-08-25 11:54:44 +02:00
|
|
|
if is_string?
|
|
|
|
str = @value
|
2015-10-27 17:09:50 +01:00
|
|
|
elsif is_object?
|
2015-10-27 11:44:02 +01:00
|
|
|
var = Register.machine.objects[id]
|
2015-08-22 20:11:33 +02:00
|
|
|
str = var.class.name.split("::").last[0,2]
|
2015-08-25 11:54:44 +02:00
|
|
|
str + " : #{id.to_s}"
|
2015-11-04 11:20:44 +01:00
|
|
|
elsif is_label?
|
|
|
|
str = "Label"
|
2015-10-27 17:09:50 +01:00
|
|
|
else
|
|
|
|
str = @value.to_s
|
2015-08-22 20:11:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|