rubyx-debugger/lib/views/ref_view.rb

72 lines
1.1 KiB
Ruby
Raw Normal View History

class RefView < ListView
2015-08-23 02:16:32 +02:00
def initialize name , value , z = nil
@name = name
@value = value
2015-08-23 02:16:32 +02:00
@z = z
super []
end
attr_reader :value
def value= val
@value = val
add_hover
end
def draw
@element = div("li") << div("a" , ref_text )
add_hover
2015-08-23 02:16:32 +02:00
@element.style["z-index"] = @z if @z
@element
end
def ref_text
2015-11-04 19:29:09 +01:00
"#{@name} : #{marker()}"
end
2015-11-04 11:20:44 +01:00
def add_hover
2015-08-25 11:54:44 +02:00
return if is_string?
@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?
@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?
end
def hover
2015-10-04 21:39:02 +02:00
#puts "hovering #{@name}"
append_view ObjectView.new(@value)
@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
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
end
end
end