3 * Copyright (c) 2007 - 2011, 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
];
46 generalSize
= [generalPreferencesView frame
].size
;
47 pathsSize
= [pathsPreferencesView frame
].size
;
51 * Shows the preferences controller window
53 - (void)showPreferencesWindow
55 [self showGeneral
:self];
56 [[self window
] center
];
57 [[self window
] makeKeyAndOrderFront
:self];
60 #pragma mark Panel Switching
63 * Shows the general panel
65 - (IBAction
)showGeneral
:(id)sender
67 if ([[self window
] contentView
] == generalPreferencesView
)
70 [self resizeWindowToSize
:generalSize
];
72 [[self window
] setContentView
:generalPreferencesView
];
73 [toolbar setSelectedItemIdentifier
:[generalPreferencesItem itemIdentifier
]];
77 * Shows the path replacement panel
79 - (IBAction
)showPaths
:(id)sender
81 if ([[self window
] contentView
] == pathsPreferencesView
)
84 [self resizeWindowToSize
:pathsSize
];
86 [[self window
] setContentView
:pathsPreferencesView
];
87 [toolbar setSelectedItemIdentifier
:[pathsPreferencesItem itemIdentifier
]];
90 #pragma mark NSToolbar Delegate
93 * Returns the selection names
95 - (NSArray
*)toolbarSelectableItemIdentifiers
:(NSToolbar
*)toolbar
97 return [NSArray arrayWithObjects
:
98 [generalPreferencesItem itemIdentifier
],
99 [pathsPreferencesItem itemIdentifier
],
107 * Resizes the preferences window to be the size of the given preferences panel
109 - (void)resizeWindowToSize
:(NSSize
)size
111 [[self window
] setContentView
:blankView
]; // don't want weird redraw artifacts
115 newFrame
= [NSWindow contentRectForFrameRect
:[[self window
] frame
] styleMask
:[[self window
] styleMask
]];
117 float height
= size.height
+ 55;
119 newFrame.origin.y
+= newFrame.size.height
;
120 newFrame.origin.y
-= height
;
121 newFrame.size.height
= height
;
122 newFrame.size.width
= size.width
;
124 newFrame
= [NSWindow frameRectForContentRect
:newFrame styleMask
:[[self window
] styleMask
]];
126 [[self window
] setFrame
:newFrame display
:YES animate
:YES
];