Class: Glimmer::DataBinding::Tk::ListSelectionBinding
- Inherits:
-
Object
- Object
- Glimmer::DataBinding::Tk::ListSelectionBinding
- 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 |, value| .selection = value.to_s end, :array => lambda do |, value| .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
-
#widget_proxy ⇒ Object
readonly
Returns the value of attribute widget_proxy.
Instance Method Summary collapse
- #call(value) ⇒ Object
- #evaluate_property ⇒ Object
-
#initialize(widget_proxy) ⇒ ListSelectionBinding
constructor
Initialize with list widget and property_type property_type :string represents default list single selection property_type :array represents list multi selection.
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() property_type = .selectmode == 'browse' ? :string : :array @widget_proxy = @property_type = property_type end |
Instance Attribute Details
#widget_proxy ⇒ Object (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 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_property ⇒ Object
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 |