[macruby-changes] [374] MacRuby/trunk/lib/hotcocoa
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jul 14 21:27:37 PDT 2008
Revision: 374
http://trac.macosforge.org/projects/ruby/changeset/374
Author: rich at infoether.com
Date: 2008-07-14 21:27:37 -0700 (Mon, 14 Jul 2008)
Log Message:
-----------
add collection view and enable binding methods on all objects
Modified Paths:
--------------
MacRuby/trunk/lib/hotcocoa/mapper.rb
MacRuby/trunk/lib/hotcocoa/mappings/image_view.rb
MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb
Added Paths:
-----------
MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb
Modified: MacRuby/trunk/lib/hotcocoa/mapper.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mapper.rb 2008-07-13 06:02:07 UTC (rev 373)
+++ MacRuby/trunk/lib/hotcocoa/mapper.rb 2008-07-15 04:27:37 UTC (rev 374)
@@ -96,6 +96,7 @@
control.send(@extension_method, custom_methods)
end
decorate_with_delegate_methods(control)
+ decorate_with_bindings_methods(control)
end
def decorate_with_delegate_methods(control)
@@ -112,6 +113,29 @@
end
control.send(@extension_method, delegate_module)
end
+
+ def decorate_with_bindings_methods(control)
+ return if control_class == NSApplication
+ bindings_module = Module.new
+ instance = if control == control_class
+ control_class.alloc.init
+ else
+ control
+ end
+ instance.exposedBindings.each do |exposed_binding|
+ bindings_module.module_eval %{
+ def #{underscore(exposed_binding)}=(value)
+ if value.kind_of?(Hash)
+ options = value.delete(:options)
+ bind "#{exposed_binding}", toObject:value.keys.first, withKeyPath:value.values.first, options:options
+ else
+ set#{exposed_binding.capitalize}(value)
+ end
+ end
+ }
+ end
+ control.send(@extension_method, bindings_module)
+ end
def remap_constants(tags)
constants = inherited_constants
@@ -130,6 +154,14 @@
end
result
end
+
+ def underscore(camel_cased_word)
+ camel_cased_word.to_s.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
end
end
\ No newline at end of file
Added: MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb (rev 0)
+++ MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb 2008-07-15 04:27:37 UTC (rev 374)
@@ -0,0 +1,32 @@
+HotCocoa::Mappings.map :collection_view => :NSCollectionView do
+
+ defaults :layout => {}, :frame => [0,0,0,0]
+
+ def init_with_options(collection_view, options)
+ collection_view.initWithFrame options.delete(:frame)
+ end
+
+ custom_methods do
+
+ def item_prototype=(item)
+ setItemPrototype(item)
+ end
+
+ def item_prototype
+ itemPrototype
+ end
+
+ def item_view
+ item_prototype ? item_prototype.view : nil
+ end
+
+ def item_view=(view)
+ item = NSCollectionViewItem.alloc.init
+ item.setView(view)
+ view.collection_item = item if view.respond_to?(:collection_item=)
+ setItemPrototype(item)
+ end
+
+ end
+
+end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/image_view.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/image_view.rb 2008-07-13 06:02:07 UTC (rev 373)
+++ MacRuby/trunk/lib/hotcocoa/mappings/image_view.rb 2008-07-15 04:27:37 UTC (rev 374)
@@ -1,13 +1,25 @@
HotCocoa::Mappings.map :image_view => :NSImageView do
- defaults :layout => {}
+ defaults :layout => {}, :frame_style => :none
+ constant :frame_style, {
+ :none => NSImageFrameNone,
+ :photo => NSImageFramePhoto,
+ :bezel => NSImageFrameGrayBezel,
+ :groove => NSImageFrameGroove,
+ :button => NSImageFrameButton
+ }
+
def init_with_options(image_view, options)
image_view.initWithFrame options.delete(:frame)
end
custom_methods do
+ def frame_style=(value)
+ setImageFrameStyle(value)
+ end
+
def url=(url)
setImage(NSImage.alloc.initByReferencingURL(NSURL.alloc.initWithString(url)))
end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb 2008-07-13 06:02:07 UTC (rev 373)
+++ MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb 2008-07-15 04:27:37 UTC (rev 374)
@@ -1,6 +1,6 @@
HotCocoa::Mappings.map :scroll_view => :NSScrollView do
- defaults :vertical_scroller => true, :horizontal_scroller => true, :layout => {}
+ defaults :vertical_scroller => true, :horizontal_scroller => true, :autoresizes_subviews => true, :layout => {}, :frame => [0,0,0,0]
def init_with_options(scroll_view, options)
scroll_view.initWithFrame options.delete(:frame)
@@ -12,6 +12,14 @@
setDocumentView(view)
end
+ def document_view=(view)
+ setDocumentView(view)
+ end
+
+ def background=(value)
+ setDrawsBackground(value)
+ end
+
def vertical_scroller=(value)
setHasVerticalScroller(value)
end
@@ -20,6 +28,10 @@
setHasHorizontalScroller(value)
end
+ def autoresizes_subviews=(value)
+ setAutoresizesSubviews(value)
+ end
+
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080714/73c5ff8f/attachment.html
More information about the macruby-changes
mailing list