[macruby-changes] [1823] MacRuby/trunk/lib/hotcocoa
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 8 23:23:14 PDT 2009
Revision: 1823
http://trac.macosforge.org/projects/ruby/changeset/1823
Author: rich at infoether.com
Date: 2009-06-08 23:23:14 -0700 (Mon, 08 Jun 2009)
Log Message:
-----------
change how frameworks are checked, remove methods that are no longer needed because you can now used under_score_methods as construction params and they convert to camelCaaseAutomatically
Modified Paths:
--------------
MacRuby/trunk/lib/hotcocoa/kernel_ext.rb
MacRuby/trunk/lib/hotcocoa/mapper.rb
MacRuby/trunk/lib/hotcocoa/mappings/array_controller.rb
MacRuby/trunk/lib/hotcocoa/mappings/box.rb
MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb
MacRuby/trunk/lib/hotcocoa/mappings/column.rb
MacRuby/trunk/lib/hotcocoa/mappings/label.rb
MacRuby/trunk/lib/hotcocoa/mappings/movie_view.rb
MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb
MacRuby/trunk/lib/hotcocoa/mappings/table_view.rb
MacRuby/trunk/lib/hotcocoa/mappings/text_field.rb
MacRuby/trunk/lib/hotcocoa/mappings/window.rb
MacRuby/trunk/lib/hotcocoa/mappings.rb
Modified: MacRuby/trunk/lib/hotcocoa/kernel_ext.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/kernel_ext.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/kernel_ext.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -4,7 +4,7 @@
def framework(name)
if default_framework(name)
- HotCocoa::Mappings.framework_loaded(name)
+ HotCocoa::Mappings.framework_loaded
true
else
false
Modified: MacRuby/trunk/lib/hotcocoa/mapper.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mapper.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mapper.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -49,15 +49,20 @@
Views[guid] = control if guid
inst.customize(control)
map.each do |key, value|
- if control.respond_to?(key) and not control.respond_to?("#{key}=") and value == true
- if control.respond_to?("set#{key.to_s.capitalize}")
- eval "control.set#{key.to_s.capitalize}(true)"
+ if control.respond_to?("#{key}=")
+ eval "control.#{key} = value"
+ elsif control.respond_to?(key)
+ new_key = (key.start_with?('set') ? key : "set#{key[0].capitalize}#{key[1..(key.length - 1)]}")
+ if control.respond_to?(new_key)
+ eval "control.#{new_key}(value)"
else
control.send("#{key}")
end
+ elsif control.respond_to?("set#{Mapper.camel_case(key.to_s)}")
+ eval "control.set#{Mapper.camel_case(key.to_s)}(value)"
else
- eval "control.#{key}= value"
- end
+ NSLog "Unable to map #{key} as a method"
+ end
end
if default_empty_rect_used
control.sizeToFit if control.respondsToSelector(:sizeToFit) == true
@@ -168,7 +173,7 @@
bindings_module = Module.new
instance.exposedBindings.each do |exposed_binding|
bindings_module.module_eval %{
- def #{underscore(exposed_binding)}=(value)
+ def #{Mapper.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
@@ -200,14 +205,23 @@
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').
+ def self.underscore(string)
+ string.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
tr("-", "_").
downcase
end
+ def self.camel_case(string)
+ if string !~ /_/ && string =~ /[A-Z]+.*/
+ string
+ else
+ string.split('_').map{ |e| e.capitalize }.join
+ end
+ end
+
+
end
end
end
\ No newline at end of file
Modified: MacRuby/trunk/lib/hotcocoa/mappings/array_controller.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/array_controller.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/array_controller.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -10,18 +10,10 @@
custom_methods do
- def avoids_empty_selection=(value)
- setAvoidsEmptySelection(value)
- end
-
def avoids_empty_selection?
avoidsEmptySelection
end
- def preserves_selection=(value)
- setPreservesSelection(value)
- end
-
def preserves_selection?
preservesSelection
end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/box.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/box.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/box.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -26,26 +26,14 @@
custom_methods do
- def title_position=(value)
- setTitlePosition(value)
- end
-
def type=(value)
setBoxType(value)
end
-
- def corner_radius=(value)
- setCornerRadius(value)
- end
def border=(value)
setBorderType(value)
end
- def title_font=(value)
- setTitleFont(value)
- end
-
end
end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/collection_view.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -8,10 +8,6 @@
custom_methods do
- def item_prototype=(item)
- setItemPrototype(item)
- end
-
def item_prototype
itemPrototype
end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/column.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/column.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/column.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -16,18 +16,6 @@
headerCell.stringValue = newTitle
end
- def data_cell=(cell)
- setDataCell(cell)
- end
-
- def max_width=(val)
- setMaxWidth(val)
- end
-
- def min_width=(val)
- setMinWidth(val)
- end
-
end
end
\ No newline at end of file
Modified: MacRuby/trunk/lib/hotcocoa/mappings/label.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/label.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/label.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -20,10 +20,6 @@
setAlignment(value)
end
- def text_color=(value)
- setTextColor(value)
- end
-
end
end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/movie_view.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/movie_view.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/movie_view.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -22,10 +22,6 @@
setZoomButtonsVisible(buttons.include?(:zoom))
end
- def fill_color=(color)
- setFillColor(color)
- end
-
end
end
\ No newline at end of file
Modified: MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/scroll_view.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -12,10 +12,6 @@
setDocumentView(view)
end
- def document_view=(view)
- setDocumentView(view)
- end
-
def background=(value)
setDrawsBackground(value)
end
@@ -28,14 +24,6 @@
setHasHorizontalScroller(value)
end
- def autoresizes_subviews=(value)
- setAutoresizesSubviews(value)
- end
-
- def autohide_scrollers=(value)
- setAutohidesScrollers(value)
- end
-
end
end
Modified: MacRuby/trunk/lib/hotcocoa/mappings/table_view.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/table_view.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/table_view.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -29,10 +29,6 @@
setDataSource(data_source)
end
- def data_source
- dataSource
- end
-
def columns=(columns)
columns.each do |column|
addTableColumn(column)
@@ -55,14 +51,36 @@
reloadData
end
- def alternating_row_background_colors=(value)
- setUsesAlternatingRowBackgroundColors(value)
- end
-
def grid_style=(value)
setGridStyleMask(value)
end
-
+
+ def row_height=(value)
+ setRowHeight(value)
+ end
+
+ def on_double_action=(behavior)
+ if target && (
+ target.instance_variable_get("@action_behavior") ||
+ target.instance_variable_get("@double_action_behavior"))
+ object.instance_variable_set("@double_action_behavior", behavior)
+ object = target
+ else
+ object = Object.new
+ object.instance_variable_set("@double_action_behavior", behavior)
+ setTarget(object)
+ end
+ def object.perform_double_action(sender)
+ @double_action_behavior.call(sender)
+ end
+ setDoubleAction("perform_double_action:")
+ end
+
+ def on_double_action(&behavior)
+ self.on_double_action = behavior
+ self
+ end
+
end
end
\ No newline at end of file
Modified: MacRuby/trunk/lib/hotcocoa/mappings/text_field.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/text_field.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/text_field.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -29,10 +29,6 @@
setAlignment(value)
end
- def text_color=(value)
- setTextColor(value)
- end
-
end
delegating "control:textShouldBeginEditing:", :to => :should_begin_editing?, :parameters => [:textShouldBeginEditing]
Modified: MacRuby/trunk/lib/hotcocoa/mappings/window.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/window.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings/window.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -82,22 +82,10 @@
orderFrontRegardless
end
- def background_color=(color)
- setBackgroundColor(color)
- end
-
- def background_color
- backgroundColor
- end
-
def has_shadow?
hasShadow
end
- def has_shadow=(value)
- setHasShadow(value)
- end
-
end
delegating "window:shouldDragDocumentWithEvent:from:withPasteboard:", :to => :should_drag_document?, :parameters => [:shouldDragDocumentWithEvent, :from, :withPasteboard]
Modified: MacRuby/trunk/lib/hotcocoa/mappings.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings.rb 2009-06-09 06:21:32 UTC (rev 1822)
+++ MacRuby/trunk/lib/hotcocoa/mappings.rb 2009-06-09 06:23:14 UTC (rev 1823)
@@ -11,12 +11,19 @@
module TargetActionConvenience
def on_action=(behavior)
- object = Object.new
- object.instance_variable_set("@behavior", behavior)
+ if target && (
+ target.instance_variable_get("@action_behavior") ||
+ target.instance_variable_get("@double_action_behavior"))
+ object.instance_variable_set("@action_behavior", behavior)
+ object = target
+ else
+ object = Object.new
+ object.instance_variable_set("@action_behavior", behavior)
+ setTarget(object)
+ end
def object.perform_action(sender)
- @behavior.call(sender)
+ @action_behavior.call(sender)
end
- setTarget(object)
setAction("perform_action:")
end
@@ -67,7 +74,7 @@
# Registers a callback for after the specified framework has been loaded.
def self.on_framework(name, &block)
- (frameworks[name.to_s.downcase] ||= []) << block
+ (frameworks[name.to_s] ||= []) << block
end
# Returns the Hash of mapped frameworks.
@@ -81,19 +88,20 @@
end
# Registers a given framework as being loaded.
- def self.framework_loaded(name)
- name = name.to_s.downcase
- loaded_frameworks << name
- if frameworks[name]
- frameworks[name].each do |mapper|
- mapper.call
+ def self.framework_loaded
+ frameworks.keys.each do |key|
+ if loaded_framework?(key)
+ frameworks[key].each do |mapper|
+ mapper.call
+ end
+ frameworks.delete(key)
end
end
end
# Returns whether or not the framework has been loaded yet.
def self.loaded_framework?(name)
- loaded_frameworks.include?(name.to_s.downcase)
+ NSBundle.allFrameworks.map {|bundle| bundle.bundlePath.split("/").last}.select {|framework| framework.split(".")[1] == 'framework'}.map {|framework| framework.split(".")[0]}.include?(name.to_s)
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090608/affea72b/attachment-0001.html>
More information about the macruby-changes
mailing list