3 * Copyright (c) 2007 - 2010, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import "PreferencesController.h"
22 @interface PreferencesController (Private
)
23 - (void)resizeWindowToSize
:(NSSize
)size
;
27 @implementation PreferencesController
30 * Loads the NIB and shows the preferences
34 if (self = [super initWithWindowNibName
:@
"Preferences"])
36 blankView
= [[NSView alloc
] init
];
55 generalSize
= [generalPreferencesView frame
].size
;
56 pathsSize
= [pathsPreferencesView frame
].size
;
60 * Shows the preferences controller window
62 - (void)showPreferencesWindow
64 [self showGeneral
:self];
65 [[self window
] center
];
66 [[self window
] makeKeyAndOrderFront
:self];
69 #pragma mark Panel Switching
72 * Shows the general panel
74 - (IBAction
)showGeneral
:(id)sender
76 if ([[self window
] contentView
] == generalPreferencesView
)
79 [self resizeWindowToSize
:generalSize
];
81 [[self window
] setContentView
:generalPreferencesView
];
82 [toolbar setSelectedItemIdentifier
:[generalPreferencesItem itemIdentifier
]];
86 * Shows the path replacement panel
88 - (IBAction
)showPaths
:(id)sender
90 if ([[self window
] contentView
] == pathsPreferencesView
)
93 [self resizeWindowToSize
:pathsSize
];
95 [[self window
] setContentView
:pathsPreferencesView
];
96 [toolbar setSelectedItemIdentifier
:[pathsPreferencesItem itemIdentifier
]];
99 #pragma mark NSToolbar Delegate
102 * Returns the selection names
104 - (NSArray
*)toolbarSelectableItemIdentifiers
:(NSToolbar
*)toolbar
106 return [NSArray arrayWithObjects
:
107 [generalPreferencesItem itemIdentifier
],
108 [pathsPreferencesItem itemIdentifier
],
116 * Resizes the preferences window to be the size of the given preferences panel
118 - (void)resizeWindowToSize
:(NSSize
)size
120 [[self window
] setContentView
:blankView
]; // don't want weird redraw artifacts
124 newFrame
= [NSWindow contentRectForFrameRect
:[[self window
] frame
] styleMask
:[[self window
] styleMask
]];
126 float height
= size.height
+ 55;
128 newFrame.origin.y
+= newFrame.size.height
;
129 newFrame.origin.y
-= height
;
130 newFrame.size.height
= height
;
131 newFrame.size.width
= size.width
;
133 newFrame
= [NSWindow frameRectForContentRect
:newFrame styleMask
:[[self window
] styleMask
]];
135 [[self window
] setFrame
:newFrame display
:YES animate
:YES
];