]> Dogcows Code - chaz/thecheat/blob - PreferenceController.m
update contact information and project URL
[chaz/thecheat] / PreferenceController.m
1
2 /*
3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
5 *
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
7 *
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.
10 */
11
12 #import "PreferenceController.h"
13
14
15 @implementation PreferenceController
16
17
18 - (id)init
19 {
20 if ( self = [super initWithWindowNibName:@"Preferences"] )
21 {
22 [self setWindowFrameAutosaveName:@"TCPreferencWindowPosition"];
23 }
24 return self;
25 }
26
27 - (void)dealloc
28 {
29 [_toolbar release];
30 [_contentView release];
31 [super dealloc];
32 }
33
34
35 - (void)windowDidLoad
36 {
37 _toolbar = [[NSToolbar alloc] initWithIdentifier:@"TCPreferencesToolbar"];
38 [_toolbar setDelegate:self];
39 [_toolbar setVisible:YES];
40 [[self window] setToolbar:_toolbar];
41
42 _contentView = [[[self window] contentView] retain];
43
44 [self initialInterfaceSetup];
45 }
46
47
48 - (void)initialInterfaceSetup
49 {
50 [self chooseGeneral:self];
51 }
52
53
54 - (void)chooseGeneral:(id)object
55 {
56 NSWindow *window = [self window];
57 [self switchToView:ibGeneralView];
58 [window setTitle:@"General"];
59 if ( MacOSXVersion() >= 0x1030 ) {
60 [_toolbar setSelectedItemIdentifier:@"General"];
61 }
62 }
63
64 - (void)chooseServer:(id)object
65 {
66 NSWindow *window = [self window];
67 [self switchToView:ibServerView];
68 [window setTitle:@"Server"];
69 if ( MacOSXVersion() >= 0x1030 ) {
70 [_toolbar setSelectedItemIdentifier:@"Server"];
71 }
72 }
73
74 - (void)chooseUpdate:(id)object
75 {
76 NSWindow *window = [self window];
77 [self switchToView:ibUpdateCheckView];
78 [window setTitle:@"Update Check"];
79 if ( MacOSXVersion() >= 0x1030 ) {
80 [_toolbar setSelectedItemIdentifier:@"Update Check"];
81 }
82 }
83
84 - (void)switchToView:(NSView *)view
85 {
86 NSWindow *window = [self window];
87 NSRect frame = [window frame];
88 float xdif, ydif;
89
90 if ( view == [window contentView] ) {
91 return;
92 }
93
94 xdif = [view frame].size.width - [[window contentView] frame].size.width;
95 ydif = [view frame].size.height - [[window contentView] frame].size.height;
96
97 frame.size.width += xdif;
98 frame.size.height += ydif;
99 frame.origin.y -= ydif;
100
101 // switch to the new view
102 [window setContentView:_contentView];
103 [window setFrame:frame display:YES animate:YES];
104 [window setContentView:view];
105 [window makeFirstResponder:view];
106 }
107
108
109 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
110 {
111 NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
112
113 [item setLabel:itemIdentifier];
114 [item setPaletteLabel:itemIdentifier];
115 [item setImage:[NSImage imageNamed:itemIdentifier]];
116 [item setTarget:self];
117 [item setAction:NSSelectorFromString( [NSString stringWithFormat:@"choose%@:", itemIdentifier] )];
118
119 return [item autorelease];
120 }
121
122 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
123 {
124 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
125 }
126
127 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
128 {
129 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
130 }
131
132 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
133 {
134 return [NSArray arrayWithObjects:@"General", @"Update", @"Server", nil];
135 }
136
137
138 @end
This page took 0.037563 seconds and 4 git commands to generate.