Convert the entire project to ARC.
[macgdbp.git] / Source / PreferencesController.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "PreferencesController.h"
18
19 NSSize generalSize;
20 NSSize pathsSize;
21
22 @interface PreferencesController (Private)
23 - (void)resizeWindowToSize:(NSSize)size;
24 @end
25
26
27 @implementation PreferencesController
28
29 /**
30 * Loads the NIB and shows the preferences
31 */
32 - (id)init
33 {
34 if (self = [super initWithWindowNibName:@"Preferences"])
35 {
36 blankView = [[NSView alloc] init];
37 }
38 return self;
39 }
40
41 /**
42 * Awake from nib
43 */
44 - (void)awakeFromNib
45 {
46 generalSize = [generalPreferencesView frame].size;
47 pathsSize = [pathsPreferencesView frame].size;
48 }
49
50 /**
51 * Shows the preferences controller window
52 */
53 - (void)showPreferencesWindow
54 {
55 [self showGeneral:self];
56 [[self window] center];
57 [[self window] makeKeyAndOrderFront:self];
58 }
59
60 #pragma mark Panel Switching
61
62 /**
63 * Shows the general panel
64 */
65 - (IBAction)showGeneral:(id)sender
66 {
67 if ([[self window] contentView] == generalPreferencesView)
68 return;
69
70 [self resizeWindowToSize:generalSize];
71
72 [[self window] setContentView:generalPreferencesView];
73 [toolbar setSelectedItemIdentifier:[generalPreferencesItem itemIdentifier]];
74 }
75
76 /**
77 * Shows the path replacement panel
78 */
79 - (IBAction)showPaths:(id)sender
80 {
81 if ([[self window] contentView] == pathsPreferencesView)
82 return;
83
84 [self resizeWindowToSize:pathsSize];
85
86 [[self window] setContentView:pathsPreferencesView];
87 [toolbar setSelectedItemIdentifier:[pathsPreferencesItem itemIdentifier]];
88 }
89
90 #pragma mark NSToolbar Delegate
91
92 /**
93 * Returns the selection names
94 */
95 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar
96 {
97 return [NSArray arrayWithObjects:
98 [generalPreferencesItem itemIdentifier],
99 [pathsPreferencesItem itemIdentifier],
100 nil
101 ];
102 }
103
104 #pragma mark Private
105
106 /**
107 * Resizes the preferences window to be the size of the given preferences panel
108 */
109 - (void)resizeWindowToSize:(NSSize)size
110 {
111 [[self window] setContentView:blankView]; // don't want weird redraw artifacts
112
113 NSRect newFrame;
114
115 newFrame = [NSWindow contentRectForFrameRect:[[self window] frame] styleMask:[[self window] styleMask]];
116
117 float height = size.height + 55;
118
119 newFrame.origin.y += newFrame.size.height;
120 newFrame.origin.y -= height;
121 newFrame.size.height = height;
122 newFrame.size.width = size.width;
123
124 newFrame = [NSWindow frameRectForContentRect:newFrame styleMask:[[self window] styleMask]];
125
126 [[self window] setFrame:newFrame display:YES animate:YES];
127 }
128
129 @end