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
|
2015-11-04 19:29:09 +01:00
|
|
|
"#{@name} : #{marker()}"
|
2015-10-29 22:36:04 +01:00
|
|
|
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 19:29:09 +01:00
|
|
|
return false if @value.is_a?(Fixnum)
|
|
|
|
return false unless @value
|
|
|
|
! is_label?
|
2015-08-25 11:54:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_string?()
|
2015-11-04 19:29:09 +01:00
|
|
|
@value.is_a? String
|
2015-08-25 11:54:44 +02:00
|
|
|
end
|
|
|
|
|
2015-11-04 11:20:44 +01:00
|
|
|
def is_label?
|
2018-04-03 15:48:45 +02:00
|
|
|
@value.is_a?(Risc::Label)
|
2015-11-04 11:20:44 +01:00
|
|
|
end
|
|
|
|
|
2015-08-25 11:54:44 +02:00
|
|
|
def is_nil?()
|
2015-11-04 19:29:09 +01:00
|
|
|
@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-11-04 19:29:09 +01:00
|
|
|
def marker
|
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-11-04 19:29:09 +01:00
|
|
|
var = @value
|
2015-08-22 20:11:33 +02:00
|
|
|
str = var.class.name.split("::").last[0,2]
|
2018-04-03 17:24:57 +02:00
|
|
|
str + " : #{@value.object_id.to_s(16)}"
|
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
|