Class: Glimmer::DataBinding::Tk::ListSelectionBinding

Inherits:
Object
  • Object
show all
Includes:
Glimmer, Observable, Observer
Defined in:
lib/glimmer/data_binding/tk/list_selection_binding.rb

Overview

Tk List widget selection binding

Constant Summary collapse

PROPERTY_TYPE_UPDATERS =
{
  :string => lambda do |widget_proxy, value|
    widget_proxy.selection = value.to_s
  end,
  :array => lambda do |widget_proxy, value|
    widget_proxy.selection = (value || [])
  end
}
PROPERTY_EVALUATORS =
{
  :string => lambda do |selection_array|
    return nil if selection_array.empty?
    selection_array.map(&:text)[0]
  end,
  :array => lambda do |selection_array|
    selection_array.map(&:text)
  end
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(widget_proxy) ⇒ ListSelectionBinding

Initialize with list widget and property_type property_type :string represents default list single selection property_type :array represents list multi selection



58
59
60
61
62
# File 'lib/glimmer/data_binding/tk/list_selection_binding.rb', line 58

def initialize(widget_proxy)
  property_type = widget_proxy.selectmode == 'browse' ? :string : :array
  @widget_proxy = widget_proxy
  @property_type = property_type
end

Instance Attribute Details

#widget_proxyObject (readonly)

Returns the value of attribute widget_proxy.



34
35
36
# File 'lib/glimmer/data_binding/tk/list_selection_binding.rb', line 34

def widget_proxy
  @widget_proxy
end

Instance Method Details

#call(value) ⇒ Object



64
65
66
# File 'lib/glimmer/data_binding/tk/list_selection_binding.rb', line 64

def call(value)
  PROPERTY_TYPE_UPDATERS[@property_type].call(@widget_proxy, value) unless evaluate_property == value
end

#evaluate_propertyObject



68
69
70
71
# File 'lib/glimmer/data_binding/tk/list_selection_binding.rb', line 68

def evaluate_property
  selection_array = @widget_proxy.tk.selection.to_a
  PROPERTY_EVALUATORS[@property_type].call(selection_array)
end