Class: Motion::Xray::PropertyEditor

Inherits:
Editor
  • Object
show all
Defined in:
lib/motion-xray/xray_editors.rb

Direct Known Subclasses

BooleanEditor, FrameEditor

Instance Attribute Summary

Attributes inherited from Editor

#property, #target

Instance Method Summary collapse

Methods inherited from Editor

#did_change?, #get_edit_view, with_target

Constructor Details

#initialize(target, property) ⇒ PropertyEditor

Returns a new instance of PropertyEditor


34
35
36
37
# File 'lib/motion-xray/xray_editors.rb', line 34

def initialize(target, property)
  super
  @original = get_value
end

Instance Method Details

#get_valueObject


39
40
41
42
43
44
45
46
# File 'lib/motion-xray/xray_editors.rb', line 39

def get_value
  if target.respond_to?(property)
    return target.send(property)
  elsif target.respond_to?("#{property}?")
    value = target.send("#{property}?")
    return target.send("#{property}?")
  end
end

#set_value(value) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/motion-xray/xray_editors.rb', line 48

def set_value(value)
  assign = "#{property}="
  setter = "set#{property.sub(/^./) { |c| c.upcase }}"

  if target.respond_to?(assign)
    target.send(assign, value)
  elsif target.respond_to?(setter)
    target.send(setter, value)
  end
  XrayTargetDidChangeNotification.post_notification(@target, { 'property' => @property, 'value' => value, 'original' => @original })
end