[macruby-changes] [634] MacRuby/trunk/lib/hotcocoa

source_changes at macosforge.org source_changes at macosforge.org
Sat Sep 27 20:49:21 PDT 2008


Revision: 634
          http://trac.macosforge.org/projects/ruby/changeset/634
Author:   rich at infoether.com
Date:     2008-09-27 20:49:21 -0700 (Sat, 27 Sep 2008)
Log Message:
-----------
trying to figure out why delegate methods are not working, this has some debug code in it

Modified Paths:
--------------
    MacRuby/trunk/lib/hotcocoa/delegate_builder.rb
    MacRuby/trunk/lib/hotcocoa/mapper.rb

Modified: MacRuby/trunk/lib/hotcocoa/delegate_builder.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/delegate_builder.rb	2008-09-28 03:49:02 UTC (rev 633)
+++ MacRuby/trunk/lib/hotcocoa/delegate_builder.rb	2008-09-28 03:49:21 UTC (rev 634)
@@ -39,10 +39,12 @@
       end
       
       def clear_delegate
-        control.setDelegate(nil)
+        control.setDelegate(nil) if control.delegate
       end
       
       def set_delegate
+        puts "setting delegate (#{delegate}) on #{control.class} which has the following methods:"
+        puts (delegate.methods.sort - Object.methods).collect {|method| "- #{method}"}
         control.setDelegate(delegate)
       end
       

Modified: MacRuby/trunk/lib/hotcocoa/mapper.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mapper.rb	2008-09-28 03:49:02 UTC (rev 633)
+++ MacRuby/trunk/lib/hotcocoa/mapper.rb	2008-09-28 03:49:21 UTC (rev 634)
@@ -119,24 +119,25 @@
     end
     
     def delegate_module_for_control_class
-      return Mapper.delegate_modules[control_class] if Mapper.delegate_modules.has_key?(control_class)
-      delegate_module = Module.new
-      required_methods = []
-      inherited_delegate_methods.each do |delegate_method, mapping|
-        required_methods << delegate_method if mapping[:required]
+      unless Mapper.delegate_modules.has_key?(control_class)
+        delegate_module = Module.new
+        required_methods = []
+        inherited_delegate_methods.each do |delegate_method, mapping|
+          required_methods << delegate_method if mapping[:required]
+        end
+        inherited_delegate_methods.each do |delegate_method, mapping|
+          parameters = mapping[:parameters] ? ", "+mapping[:parameters].map {|param| %{"#{param}"} }.join(",") : ""
+          delegate_module.module_eval %{
+            def #{mapping[:to]}(&block)
+              raise "Must pass in a block to use this delegate method" unless block_given?
+              @_delegate_builder ||= HotCocoa::DelegateBuilder.new(self, #{required_methods.inspect})
+              @_delegate_builder.add_delegated_method(block, "#{delegate_method}" #{parameters})
+            end
+          }
+        end
+        Mapper.delegate_modules[control_class] = delegate_module
       end
-      inherited_delegate_methods.each do |delegate_method, mapping|
-        parameters = mapping[:parameters] ? ", "+mapping[:parameters].map {|param| %{"#{param}"} }.join(",") : ""
-        delegate_module.module_eval %{
-          def #{mapping[:to]}(&block)
-            raise "Must pass in a block to use this delegate method" unless block_given?
-            @_delegate_builder ||= HotCocoa::DelegateBuilder.new(self, #{required_methods.inspect})
-            @_delegate_builder.add_delegated_method(block, "#{delegate_method}" #{parameters})
-          end
-        }
-      end
-      Mapper.delegate_modules[control_class] = delegate_module
-      delegate_module
+      Mapper.delegate_modules[control_class] 
     end
     
     def decorate_with_bindings_methods(control)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080927/afea67f5/attachment-0001.html 


More information about the macruby-changes mailing list