lib/glimmer/swt/custom_widget.rb in glimmer-0.4.6 vs lib/glimmer/swt/custom_widget.rb in glimmer-0.4.7

- old
+ new

@@ -1,15 +1,17 @@ require 'set' require_relative 'proc_tracker' +require_relative 'observable_model' module Glimmer module SWT module CustomWidget include SuperModule include Glimmer include Parent + include ObservableModel class << self def for(underscored_custom_widget_name) namespaces = underscored_custom_widget_name. to_s. @@ -65,10 +67,24 @@ def body raise 'Not implemented!' end + # TODO consider using delegators + + def can_add_listener?(underscored_listener_name) + @body_root.can_add_listener?(underscored_listener_name) + end + + def add_listener(underscored_listener_name, &block) + @body_root.add_listener(underscored_listener_name, &block) + end + + def add_observer(observer, attribute_name) + @body_root.add_observer(observer, attribute_name) + end + def has_attribute?(attribute_name, *args) respond_to?(attribute_setter(attribute_name), args) || @body_root.has_attribute?(attribute_name, *args) end @@ -78,15 +94,27 @@ else @body_root.set_attribute(attribute_name, *args) end end + def get_attribute(attribute_name) + if respond_to?(attribute_name) + send(attribute_name) + else + @body_root.get_attribute(attribute_name) + end + end + def attribute_setter(attribute_name) "#{attribute_name}=" end def process_block(block) - @content.call if @content && !@content.called? + if block.source_location == @content&.__getobj__.source_location + @content.call unless @content.called? + else + block.call + end end end end end