|
From: Mark H. <di...@ma...> - 2005-05-31 14:59:13
|
Hi,
The main reasons I want to work with RubyCocoa is the ability to use
all the nifty cocoa features like toolbars, drawers, and sheets. I've
been fighting to figure out the whole toolbar thing, but I've gotten
a bit stuck. I've stuck what I have so far at the end of the message
(edited somewhat for brevity).
It doesn't work. There is nothing being shown in the toolbar, and it
seems that the toolbaritems I'm creating never get added to the
toolbar; calling @main_window.toolbar.items returns an empty NSArray.
Has anyone worked with toolbars under RubyCocoa, who could offer any
advice (or sample code!)? I'm a bit stuck here at the moment, so
*any* help would be appreciated.
Here's the code. The calls to breakpoint() are from the ruby-
breakpoint library, which has helped a lot in figuring out what I have.
-----
class AppController < OSX::NSObject
include OSX
ib_outlets :main_window
def awakeFromNib
tb = NSToolbar.alloc.initWithIdentifier "main window toolbar"
tb.setAllowsUserCustomization true
tb.setAutosavesConfiguration true
tb.setDisplayMode NSToolbarDisplayModeIconOnly
tb.setDelegate self
@main_window.setToolbar tb
breakpoint
end
def nullActionOfDoom(*args)
puts "Null action of doom!!!!"
p args
end
# --- delegate for toolbar
def toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar
(toolbar, itemid, insert)
if itemid == "install item toolbar item"
tbi = NSToolbarItem.alloc.initWithItemIdentifier itemid
tbi.setLabel "Install"
tbi.setPaletteLabel "Install"
tbi.setToolTip "Install this item"
tbi.setImage "NSApplicationIcon"
tbi.setTarget self
tbi.setAction :nullActionOfDoom # is this how you replace the
selector call?
elsif itemid == "remove item toolbar item"
tbi = NSToolbarItem.alloc.initWithItemIdentifier itemid
tbi.setLabel "Remove"
tbi.setPaletteLabel "Remove"
tbi.setToolTip "Remove this item"
tbi.setImage "NSApplicationIcon"
tbi.setTarget self
tbi.setAction :nullActionOfDoom
end
breakpoint
tbi
end
def toolbarAllowedItemIdentifiers(toolbar)
breakpoint
["install item toolbar item", "remove item toolbar item"]
end
def toolbarDefaultItemIdentifiers(toolbar)
breakpoint
["install item toolbar item", "remove item toolbar item"]
end
def toolbarDidRemoveItem(notification) breakpoint end
def toolbarSelectableItemIdentifiers(toolbar) breakpoint end
def toolbarWillAddItem(toolbar) breakpoint end
end
|