[macruby-changes] [2205] MacRuby/branches/experimental/sample-macruby/HotCocoa/mvc/lib/mvc.rb
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 3 20:39:09 PDT 2009
Revision: 2205
http://trac.macosforge.org/projects/ruby/changeset/2205
Author: mattaimonetti at gmail.com
Date: 2009-08-03 20:39:08 -0700 (Mon, 03 Aug 2009)
Log Message:
-----------
updated the mvc framework demo (demo not 0.5 compatible yet, the mvc.rb file is)
Modified Paths:
--------------
MacRuby/branches/experimental/sample-macruby/HotCocoa/mvc/lib/mvc.rb
Modified: MacRuby/branches/experimental/sample-macruby/HotCocoa/mvc/lib/mvc.rb
===================================================================
--- MacRuby/branches/experimental/sample-macruby/HotCocoa/mvc/lib/mvc.rb 2009-08-04 03:36:58 UTC (rev 2204)
+++ MacRuby/branches/experimental/sample-macruby/HotCocoa/mvc/lib/mvc.rb 2009-08-04 03:39:08 UTC (rev 2205)
@@ -75,15 +75,32 @@
end
class HotCocoaApplicationController < HotCocoaController
-
+
def initialize(application)
super(application)
end
def application_window
- @application_window ||= ApplicationWindow.new(self).application_window
+ if @application_window
+ @application_window
+ else
+ @application_window = ApplicationWindow.new(self).application_window
+ @application_window.will_close{ exit }
+ # view callback when the window is rendered
+ application_view.after_render
+ # application controller callback for when the window is rendered
+ after_render
+ end
+ @application_window
end
+
+ # After window render callback placeholder
+ # at this point application_window is available
+ #
+ # Overwrite this method in your controller
+ def after_render; end
+
# help menu item
def on_help(menu)
end
@@ -112,8 +129,10 @@
end
def render
- @application_window = HotCocoa.window(:title => title)
- @application_window.view << application_controller.application_view
+ unless @application_window
+ @application_window = HotCocoa.window(:title => title)
+ @application_window.view << application_controller.application_view
+ end
end
def title
@@ -131,11 +150,11 @@
if name
@name = name
else
- @name || :application_controller
+ @name || name || :application_controller
end
end
def options(options=nil)
- @options = options if options
+ @options = options unless options.nil?
end
end
@@ -145,9 +164,13 @@
class_name = klass.name.underscore
HotCocoaController.class_eval %{
def #{class_name}
- view = HotCocoaController.view_instances[:#{class_name}] ||= #{klass.name}.alloc.initWithFrame([0,0,0,0])
- view.setup_view
- view
+ if HotCocoaController.view_instances[:#{class_name}].nil?
+ view = HotCocoaController.view_instances[:#{class_name}] = #{klass.name}.alloc.initWithFrame([0,0,0,0])
+ view.setup_view
+ view
+ else
+ HotCocoaController.view_instances[:#{class_name}]
+ end
end
}, __FILE__, __LINE__
end
@@ -155,11 +178,17 @@
attr_reader :controller
def setup_view
- @controller = class_controller
+ @controller ||= class_controller
self.layout = layout_options
- render
- end
+ render
+ end
+ # After window render callback placeholder
+ # at this point application_window is available
+ #
+ # Overwrite this method in your view
+ def after_render; end
+
private
def class_controller
@@ -176,7 +205,5 @@
end
-class ApplicationWindow < HotCocoaWindow
-
-end
-
+class ApplicationWindow < HotCocoaWindow
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090803/97ae4fdc/attachment.html>
More information about the macruby-changes
mailing list