开发者

Cocoa/MacRuby: How to write a toolbar which accepts custom items?

I'm doing my first steps in MacRuby. Does anyone know how I can add a custom Toolbar to my Cocoa/MacRuby application, which will accept "regular" items for e.g. switching the view (see http://www.stevestreeting.com/wp-content/uploads/2011/06/SelectableToolbarDemo001.png).

I've read some tutorials and I guess I have to create a custom delegate for the T开发者_开发技巧oolbar and then connect it via the Outlets window, but how does the myCustomDelegate.rb have to look like?


There is an excellent tutorial here: http://www.mere-mortal-software.com/blog/details.php?d=2007-03-14

It is targeted at preferences windows, but of course you could use the window class anywhere.

I have not bothered to port the window superclass to Macruby, I just use it as is. Then I use macruby to write the subclass, for example:

class MopenPrefsWindowController < DBPrefsWindowController
  attr_accessor :generalPrefsView
  attr_accessor :openingPrefsView
  attr_accessor :advancedPrefsView
  attr_accessor :appearancePrefsView  

  def setupToolbar
    self.addView(generalPrefsView, label:"General", image:NSImage.imageNamed(NSImageNamePreferencesGeneral))
    self.addView(openingPrefsView, label:"Opening")
    self.addView(advancedPrefsView, label:"Advanced", image:NSImage.imageNamed(NSImageNameAdvanced))
    self.addView(appearancePrefsView, label:"Appearance")
  end
end

The one thing that might cause me to some day port the window class to macruby is to give it the ability to have a bottom section that appears on all panes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜