Isn’t it enough to have a Class.h file as company of the Ruby.rb file like: // AppDelegate.h #import <Foundation/Foundation.h> @interface AppDelegate : NSWindowController { IBOutlet NSWindow *window; IBOutlet NSButton *homeButton; . . . etc etc } - (IBAction)loadStore:(id)sender; - (IBAction)sortContacts:(id)sender; . . . etc etc @end At least the IB is triggered by this but I admit i still don't have a big app running on Mavericks :) cheers, Rob On 10 Nov 2013, at 07:16, macruby-devel-request@lists.macosforge.org wrote:
Send MacRuby-devel mailing list submissions to macruby-devel@lists.macosforge.org
To subscribe or unsubscribe via the World Wide Web, visit https://lists.macosforge.org/mailman/listinfo/macruby-devel or, via email, send a message with subject or body 'help' to macruby-devel-request@lists.macosforge.org
You can reach the person managing the list at macruby-devel-owner@lists.macosforge.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of MacRuby-devel digest..."
Today's Topics:
1. Re: MacRuby on Mavericks (Robert Carl Rice)
----------------------------------------------------------------------
Message: 1 Date: Sun, 10 Nov 2013 01:16:12 -0500 From: Robert Carl Rice <rice.audio@pobox.com> To: "MacRuby development discussions." <macruby-devel@lists.macosforge.org> Subject: Re: [MacRuby-devel] MacRuby on Mavericks Message-ID: <8E18A9E4-8EB5-4C0C-8627-7D4C758DC6E2@pobox.com> Content-Type: text/plain; charset="us-ascii"
On Nov 7, 2013, at 9:07 AM, Joshua Ballanco <jballanc@gmail.com> wrote:
* MacRuby integration with Xcode relies on rb-nibtool, but the Xcode team has repeatedly signaled (not so subtly) that they are not interested in keeping this shim working.
I assume that rb-nibtool scans rb files to identify possible IBOutlet and IBAction targets. If this is it's only function then I would not miss it if it goes away. I have discovered that it is easy to define IBOutlet and IBAction targets in Objective-C files without recoding any ruby code into Objective-C. The results are much better because the linkage and error messages are very fast while the scanning of ruby files gets very slow on a large project.
To avoid adding a lot of files, I created a single Objective-C .h and .m file for each of my nib files, including the main, giving it a corresponding name.
// MainWindow.h // RiceCNC // // Created by Robert Rice on 11/9/13. // Copyright (c) 2013 Robert Rice. All rights reserved. //
#import <Foundation/Foundation.h>
@interface AppDelegate : NSObject
@property (weak) IBOutlet id template_menu; @property (weak) IBOutlet id example_menu;
- (IBAction)makeNewMachine:(id)sender; - (IBAction)makeNewEngine:(id)sender;
@end
// MainWindow.m // RiceCNC // // Created by Robert Rice on 11/9/13. // Copyright (c) 2013 Robert Rice. All rights reserved. //
#import "MainWindow.h"
@implementation AppDelegate
@synthesize template_menu; @synthesize example_menu;
- (IBAction)makeNewMachine:(id)sender {}; - (IBAction)makeNewEngine:(id)sender {};
@end
The IBActions are easy. I simply define empty methods for my actions. MacRuby will replace the empty methods with the ruby methods.
For each IBOutlet, I define a C property, remove the attr_writer or attr_accessor from my ruby class, then reference the property from my ruby class using the dot syntax.
For this example, I changed @template_menu to self.template_menu and @example_menu to self.example_menu:
# AppDelegate.rb # MacCNC # # Created by Robert Rice on 3/10/12. # Copyright 2012 Rice Audio. All rights reserved.
class AppDelegate # attr_writer :template_menu, :example_menu
def init if super # ErrorLog.instance.debug( "AppDelegate init" ) end @pdf_window_controller = nil @mail_bridge_window_controller = nil
self end
def awakeFromNib # ErrorLog.instance.debug( "AppDelegate awakeFromNib" ) bundle = NSBundle.mainBundle
engines = bundle.pathsForResourcesOfType( "engine", inDirectory:"Templates" ) engines.each do | path | title = path.split( '/' ).last.split( '.' ).first item = self.template_menu.addItemWithTitle( title, action:"open_engine_template:", keyEquivalent:"" ) item.setTarget( self ) end
examples = bundle.pathsForResourcesOfType( "cnc", inDirectory:"Examples" ) examples.each do | path | title = path.split( '/' ).last.split( '.' ).first item = self.example_menu.addItemWithTitle( title, action:"open_document_template:", keyEquivalent:"" ) item.setTarget( self ) end end
def makeNewMachine( sender ) makeNewDocument( "Machine" ) end
def makeNewEngine( sender ) makeNewDocument( "Engine" ) end
def makeNewDocument( type ) ErrorLog.instance.warn( "makeNewDocument #{ type }" )
nserror = Pointer.new( :object ) controller = NSDocumentController.sharedDocumentController document = controller.makeUntitledDocumentOfType( type, error:nserror ) if document controller.addDocument( document ) document.makeWindowControllers document.showWindows
else ErrorLog.instance.error( "Error creating new #{ type } Document" ) end
document end
def open_engine_template( sender ) open_file( NSBundle.mainBundle.pathForResource( sender.title, ofType:"engine", inDirectory:"Templates" ) ) end
def open_machine_template( sender ) open_file( NSBundle.mainBundle.pathForResource( sender.title, ofType:"machine", inDirectory:"Templates" ) ) end
def open_document_template( sender ) open_file( NSBundle.mainBundle.pathForResource( sender.title, ofType:"cnc", inDirectory:"Examples" ) ) end
def open_file( path ) url = NSURL.fileURLWithPath( path ) nserror = Pointer.new( :object ) NSDocumentController.sharedDocumentController.openDocumentWithContentsOfURL( url, display:true, error:nserror ) end
end