3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
12 #import "PreferenceController.h"
15 @implementation PreferenceController
20 if ( self = [super initWithWindowNibName
:@
"Preferences"] )
22 [self setWindowFrameAutosaveName
:@
"TCPreferencWindowPosition"];
30 [_contentView release
];
37 _toolbar
= [[NSToolbar alloc
] initWithIdentifier
:@
"TCPreferencesToolbar"];
38 [_toolbar setDelegate
:self];
39 [_toolbar setVisible
:YES
];
40 [[self window
] setToolbar
:_toolbar
];
42 _contentView
= [[[self window
] contentView
] retain
];
44 [self initialInterfaceSetup
];
48 - (void)initialInterfaceSetup
50 [self chooseGeneral
:self];
54 - (void)chooseGeneral
:(id)object
56 NSWindow
*window
= [self window
];
57 [self switchToView
:ibGeneralView
];
58 [window setTitle
:@
"General"];
59 [_toolbar setSelectedItemIdentifier
:@
"General"];
62 - (void)chooseServer
:(id)object
64 NSWindow
*window
= [self window
];
65 [self switchToView
:ibServerView
];
66 [window setTitle
:@
"Server"];
67 [_toolbar setSelectedItemIdentifier
:@
"Server"];
70 - (void)chooseUpdate
:(id)object
72 NSWindow
*window
= [self window
];
73 [self switchToView
:ibUpdateCheckView
];
74 [window setTitle
:@
"Update Check"];
75 [_toolbar setSelectedItemIdentifier
:@
"Update Check"];
78 - (void)switchToView
:(NSView
*)view
80 NSWindow
*window
= [self window
];
81 NSRect frame
= [window frame
];
84 if ( view
== [window contentView
] ) {
88 xdif
= [view frame
].size.width
- [[window contentView
] frame
].size.width
;
89 ydif
= [view frame
].size.height
- [[window contentView
] frame
].size.height
;
91 frame.size.width
+= xdif
;
92 frame.size.height
+= ydif
;
93 frame.origin.y
-= ydif
;
95 // switch to the new view
96 [window setContentView
:_contentView
];
97 [window setFrame
:frame display
:YES animate
:YES
];
98 [window setContentView
:view
];
99 [window makeFirstResponder
:view
];
103 - (NSToolbarItem
*)toolbar
:(NSToolbar
*)toolbar itemForItemIdentifier
:(NSString
*)itemIdentifier willBeInsertedIntoToolbar
:(BOOL)flag
105 NSToolbarItem
*item
= [[NSToolbarItem alloc
] initWithItemIdentifier
:itemIdentifier
];
107 [item setLabel
:itemIdentifier
];
108 [item setPaletteLabel
:itemIdentifier
];
109 [item setImage
:[NSImage imageNamed
:itemIdentifier
]];
110 [item setTarget
:self];
111 [item setAction
:NSSelectorFromString( [NSString stringWithFormat
:@
"choose%@:", itemIdentifier
] )];
113 return [item autorelease
];
116 - (NSArray
*)toolbarAllowedItemIdentifiers
:(NSToolbar
*)toolbar
118 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];
121 - (NSArray
*)toolbarDefaultItemIdentifiers
:(NSToolbar
*)toolbar
123 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];
126 - (NSArray
*)toolbarSelectableItemIdentifiers
:(NSToolbar
*)toolbar
128 return [NSArray arrayWithObjects
:@
"General", @
"Update", @
"Server", nil];