## PreferencesController.rb
# PreferencesExample
## Created by Matthew McCray on 1/18/08.
# Copyright (c) 2008 Elucidata (www.elucidata.net). All rights reserved.
#require'osx/cocoa'classPreferencesController< OSX::NSWindowControllerincludeOSX
ib_outlets :generalPrefsView,:advancedPrefsView# This is the target action for the toolbar items
ib_action :selectPrefPaneldo |sender|
tag = sender.tag
view, title =self.viewForTag(tag)
previousView, prevTitle =self.viewForTag(@currentViewTag)@currentViewTag= tag
newFrame =self.newFrameForNewContentView(view)
window.title ="#{title} Preferences"# Using an animation grouping because we may be changing the duration
NSAnimationContext.beginGrouping
# Call the animator instead of the view / window directly
window.contentView.animator.replaceSubview_with(previousView, view)
window.animator.setFrame_display newFrame,trueNSAnimationContext.endGrouping
enddefinitselfifself.initWithWindowNibName_owner('Preferences',self)end# Delegate method that returns the itemIdentifiers for the selectable items
# (in our case, all of 'em)
deftoolbarSelectableItemIdentifiers(toolbar)@toolbaritemidents||=begin
window.toolbar.items.map {|item| item.itemIdentifier }endenddefawakeFromNib# Select the first toolbar item when the window loads
window.toolbar.selectedItemIdentifier = window.toolbar.items[0].itemIdentifier
# Show the initial preference pane
window.setContentSize @generalPrefsView.frame.size
window.contentView.addSubview @generalPrefsView
window.title ="General Preferences"@currentViewTag=0# Will use CoreAnimation for the panel changes:
window.contentView.wantsLayer =trueenddefviewForTag(tag)case tag
when0:[@generalPrefsView,"General"]when1:[@advancedPrefsView,"Advanced"]endenddefnewFrameForNewContentView(view)
newFrameRect = window.frameRectForContentRect(view.frame)
oldFrameRect = window.frame
newSize = newFrameRect.size
oldSize = oldFrameRect.size
frame = window.frame
frame.size = newSize
frame.origin.y = frame.origin.y -(newSize.height - oldSize.height)
frame
endend