[macruby-changes] [376] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 14 22:26:15 PDT 2008


Revision: 376
          http://trac.macosforge.org/projects/ruby/changeset/376
Author:   rich at infoether.com
Date:     2008-07-14 22:26:15 -0700 (Mon, 14 Jul 2008)
Log Message:
-----------
explicitly have to map bindings

Modified Paths:
--------------
    MacRuby/trunk/lib/hotcocoa/mapper.rb
    MacRuby/trunk/sample-macruby/HotCocoa/collection_view.rb

Modified: MacRuby/trunk/lib/hotcocoa/mapper.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mapper.rb	2008-07-15 04:28:57 UTC (rev 375)
+++ MacRuby/trunk/lib/hotcocoa/mapper.rb	2008-07-15 05:26:15 UTC (rev 376)
@@ -3,6 +3,8 @@
   class Mapper
     
     attr_reader :control_class, :builder_method, :control_module
+    
+    attr_accessor :map_bindings
 
     def self.map_class(klass)
       new(klass).include_in_class
@@ -12,6 +14,14 @@
       new(klass).map_method(builder_method, &block)
     end
     
+    def self.bindings_modules
+      @bindings_module ||= {}
+    end
+    
+    def self.delegate_modules
+      @delegate_modules ||= {}
+    end
+    
     def initialize(klass)
       @control_class = klass
     end
@@ -33,6 +43,7 @@
         map = (args.length == 1 ? args[0] : args[1]) || {}
         guid = args.length == 1 ? nil : args[0]
         map = inst.remap_constants(map)
+        inst.map_bindings = map.delete(:map_bindings)
         default_empty_rect_used = (map[:frame].__id__ == DefaultEmptyRect.__id__)
         control = inst.respond_to?(:init_with_options) ? inst.init_with_options(inst.control_class.alloc, map) : inst.alloc_with_options(map)
         Views[guid] = control if guid
@@ -100,6 +111,11 @@
     end
 
     def decorate_with_delegate_methods(control)
+      control.send(@extension_method, delegate_module_for_control_class)
+    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
       inherited_delegate_methods.each do |delegate_method, mapping|
         parameters = mapping[:parameters] ? ", "+mapping[:parameters].map {|param| %{"#{param}"} }.join(",") : ""
@@ -111,17 +127,23 @@
           end
         }
       end
-      control.send(@extension_method, delegate_module)
+      Mapper.delegate_modules[control_class] = delegate_module
+      delegate_module
     end
     
     def decorate_with_bindings_methods(control)
       return if control_class == NSApplication
-      bindings_module = Module.new
+      control.send(@extension_method, bindings_module_for_control(control)) if @map_bindings
+    end
+    
+    def bindings_module_for_control(control)
+      return Mapper.bindings_modules[control_class] if Mapper.bindings_modules.has_key?(control_class)
       instance = if control == control_class
         control_class.alloc.init
       else
         control
       end
+      bindings_module = Module.new
       instance.exposedBindings.each do |exposed_binding|
         bindings_module.module_eval %{
           def #{underscore(exposed_binding)}=(value)
@@ -134,7 +156,8 @@
           end
         }
       end
-      control.send(@extension_method, bindings_module)
+      Mapper.bindings_modules[control_class] = bindings_module
+      bindings_module
     end
 
     def remap_constants(tags)

Modified: MacRuby/trunk/sample-macruby/HotCocoa/collection_view.rb
===================================================================
--- MacRuby/trunk/sample-macruby/HotCocoa/collection_view.rb	2008-07-15 04:28:57 UTC (rev 375)
+++ MacRuby/trunk/sample-macruby/HotCocoa/collection_view.rb	2008-07-15 05:26:15 UTC (rev 376)
@@ -52,7 +52,8 @@
       cv = collection_view :frame => [0,0,480,470], 
                                        :content => {array_controller => "arrangedObjects"}, 
                                        :selection_indexes => {array_controller => "selectionIndexes"},
-                                       :item_view => MyIconView.create
+                                       :item_view => MyIconView.create,
+                                       :map_bindings => true
       scroll << cv
     end
   end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080714/f6c522bd/attachment.html 


More information about the macruby-changes mailing list