From: Mark H. <di...@ma...> - 2005-06-02 15:07:46
|
On Jun 1, 2005, at 9:04 AM, Kevin Bullock wrote: > There's two problems with your code, both in the > toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar method. The > first is that when the method is called, itemid is an NSCFString, > not a Ruby String, and it doesn't get implicitly converted. Just > inserting 'itemid = itemid.to_s' will fix that though. (If you step > through that method, you might notice that neither branch of the if > is being called, because the comparison fails.) That was the show stopper... the other problems I managed to figure out, but for some reason I couldn't get that one :) > The other problem is that you're passing a string to > NSToolbarItem#setImage, which expects an NSImage. You can fix this > easily: > > tbi.setImage "NSApplicationIcon" > > becomes: > > tbi.setImage( NSImage.imageNamed( "NSApplicationIcon" ) ) > > and assuming there's an NSApplicationIcon.{tif,icns,...} in your > app bundle, it'll work. yeah, I noticed that one, and felt kinda dumb :) Setting the image to a string? Oh well. Also, NSImage.imageNamed("NSApplicationIcon") doesn't require an image with that name in the bundle; it automatically grabs the image used for the application's icon in the dock. I was using it because I figured it should never fail, and since I was having problems already... I'm playing with a ruby module right now that helps with various setup procedures, including NSToolbar and it's ilk. The verbosity of the code needed to create a toolbar item (let alone a toolbar itself) is rather staggering, coming from a Ruby standpoint. It makes Ruby look like Java :) thanks, Mark > Hope this helps. Let me know if anything is unclear. > > Pacem in terris / Mir / Shanti / Salaam / Heiwa > Kevin R. Bullock > > >> To: rub...@li... >> From: Mark Hubbart <di...@ma...> >> Date: Tue, 31 May 2005 07:59:04 -0700 >> Subject: [Rubycocoa-talk] anyone work with toolbars? >> Reply-To: rub...@li... >> >> 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 >> > > > ------------------------------------------------------- > This SF.Net email is sponsored by Yahoo. > Introducing Yahoo! Search Developer Network - Create apps using Yahoo! > Search APIs Find out how you can build Yahoo! directly into your own > Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg- > q22005 > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > |