rubyx-debugger/lib/views/ref_view.rb

60 lines
1.0 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" , "#{@name} : #{marker(@value)}" )
add_hover
2015-08-23 02:16:32 +02:00
@element.style["z-index"] = @z if @z
@element
end
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-10-27 11:44:02 +01:00
Register.machine.objects[@value] != nil
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
def is_nil?()
2015-10-27 11:44:02 +01:00
Register.machine.objects[@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
def marker id
2015-08-25 11:54:44 +02:00
if is_string?
str = @value
elsif is_nil?
str = "nil"
else
2015-10-27 11:44:02 +01:00
var = Register.machine.objects[id]
str = var.class.name.split("::").last[0,2]
2015-08-25 11:54:44 +02:00
str + " : #{id.to_s}"
end
end
end