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.
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