[macruby-changes] [636] MacRuby/trunk/lib/hotcocoa/mappings/timer.rb
source_changes at macosforge.org
source_changes at macosforge.org
Sun Sep 28 18:51:41 PDT 2008
Revision: 636
http://trac.macosforge.org/projects/ruby/changeset/636
Author: rich at infoether.com
Date: 2008-09-28 18:51:41 -0700 (Sun, 28 Sep 2008)
Log Message:
-----------
add timer
Added Paths:
-----------
MacRuby/trunk/lib/hotcocoa/mappings/timer.rb
Added: MacRuby/trunk/lib/hotcocoa/mappings/timer.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings/timer.rb (rev 0)
+++ MacRuby/trunk/lib/hotcocoa/mappings/timer.rb 2008-09-29 01:51:41 UTC (rev 636)
@@ -0,0 +1,25 @@
+HotCocoa::Mappings.map :timer => :NSTimer do
+
+ defaults :scheduled => true, :repeats => false
+
+ def alloc_with_options(options)
+ raise ArgumentError, "timer requires :interval" unless options.has_key?(:interval)
+ target = options.delete(:target)
+ selector = options.delete(:selector)
+ if !target || !selector
+ raise ArgumentError, "timer requires either :target and :selector or :on_action" unless options.has_key?(:on_action)
+ target = Object.new
+ target.instance_variable_set(:@block, options.delete(:on_action))
+ def target.fire(timer)
+ @block.call(timer)
+ end
+ selector = "fire:"
+ end
+ if options.delete(:scheduled)
+ NSTimer.scheduledTimerWithTimeInterval(options.delete(:interval), target:target, selector:selector, userInfo:options.delete(:info), repeats:options.delete(:repeats))
+ else
+ NSTimer.timerWithTimeInterval(options.delete(:interval), target:target, selector:selector, userInfo:options.delete(:info), repeats:options.delete(:repeats))
+ end
+ end
+
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080928/ab278de1/attachment.html
More information about the macruby-changes
mailing list