]> src.bluestatic.org Git - macgdbp.git/blob - Source/PreferencesController.m
Write BSProtocolThreadInvoker to replace ThreadSafeDelegate.
[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 * Destructor
43 */
44 - (void)dealloc
45 {
46 [blankView release];
47 [super dealloc];
48 }
49
50 /**
51 * Awake from nib
52 */
53 - (void)awakeFromNib
54 {
55 generalSize = [generalPreferencesView frame].size;
56 pathsSize = [pathsPreferencesView frame].size;
57 }
58
59 /**
60 * Shows the preferences controller window
61 */
62 - (void)showPreferencesWindow
63 {
64 [self showGeneral:self];
65 [[self window] center];
66 [[self window] makeKeyAndOrderFront:self];
67 }
68
69 #pragma mark Panel Switching
70
71 /**
72 * Shows the general panel
73 */
74 - (IBAction)showGeneral:(id)sender
75 {
76 if ([[self window] contentView] == generalPreferencesView)
77 return;
78
79 [self resizeWindowToSize:generalSize];
80
81 [[self window] setContentView:generalPreferencesView];
82 [toolbar setSelectedItemIdentifier:[generalPreferencesItem itemIdentifier]];
83 }
84
85 /**
86 * Shows the path replacement panel
87 */
88 - (IBAction)showPaths:(id)sender
89 {
90 if ([[self window] contentView] == pathsPreferencesView)
91 return;
92
93 [self resizeWindowToSize:pathsSize];
94
95 [[self window] setContentView:pathsPreferencesView];
96 [toolbar setSelectedItemIdentifier:[pathsPreferencesItem itemIdentifier]];
97 }
98
99 #pragma mark NSToolbar Delegate
100
101 /**
102 * Returns the selection names
103 */
104 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar
105 {
106 return [NSArray arrayWithObjects:
107 [generalPreferencesItem itemIdentifier],
108 [pathsPreferencesItem itemIdentifier],
109 nil
110 ];
111 }
112
113 #pragma mark Private
114
115 /**
116 * Resizes the preferences window to be the size of the given preferences panel
117 */
118 - (void)resizeWindowToSize:(NSSize)size
119 {
120 [[self window] setContentView:blankView]; // don't want weird redraw artifacts
121
122 NSRect newFrame;
123
124 newFrame = [NSWindow contentRectForFrameRect:[[self window] frame] styleMask:[[self window] styleMask]];
125
126 float height = size.height + 55;
127
128 newFrame.origin.y += newFrame.size.height;
129 newFrame.origin.y -= height;
130 newFrame.size.height = height;
131 newFrame.size.width = size.width;
132
133 newFrame = [NSWindow frameRectForContentRect:newFrame styleMask:[[self window] styleMask]];
134
135 [[self window] setFrame:newFrame display:YES animate:YES];
136 }
137
138 @end