4 * Construct and manage the preferences panel under cocoa.
6 * Copyright (c) 2008 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include "cocoaui/cocoaui.h"
23 @interface LxdreamPrefsToolbarDelegate : NSObject {
28 - (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
29 tooltip: (NSString *)tooltip icon: (NSString *)icon
33 @implementation LxdreamPrefsToolbarDelegate
36 NSToolbarItem *paths = [self createToolbarItem: @"Paths" label: @"Paths"
37 tooltip: @"Configure system paths" icon: @"tb-paths"
38 action: @selector(paths_action:)];
39 NSToolbarItem *ctrls = [self createToolbarItem: @"Controllers" label: @"Controllers"
40 tooltip: @"Configure controllers" icon: @"tb-ctrls"
41 action: @selector(controllers_action:)];
42 identifiers = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
43 defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
44 NSArray *values = [NSArray arrayWithObjects: paths, ctrls, nil ];
45 items = [NSDictionary dictionaryWithObjects: values forKeys: identifiers];
49 - (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
50 tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action
52 NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier: id];
53 [item setLabel: label];
54 [item setToolTip: tooltip];
55 [item setTarget: self];
56 NSString *iconFile = [[NSBundle mainBundle] pathForResource:icon ofType:@"png"];
57 NSImage *image = [[NSImage alloc] initWithContentsOfFile: iconFile];
58 [item setImage: image];
59 [item setAction: action];
63 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
68 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
73 - (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
75 return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil];
78 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier
79 willBeInsertedIntoToolbar:(BOOL)flag
81 return [items objectForKey: itemIdentifier];
83 - (void)paths_action: (id)sender
86 - (void)controllers_action: (id)sender
91 @implementation LxdreamPrefsPanel
92 - (NSView *)createPathsPane
94 NSView *pane = [NSView new];
96 for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
97 lxdream_config_entry_t entry = lxdream_get_config_entry(i);
98 if( entry->label != NULL ) {
103 - (id)initWithContentRect:(NSRect)contentRect
105 if( [super initWithContentRect: contentRect
106 styleMask: ( NSTitledWindowMask | NSClosableWindowMask |
107 NSMiniaturizableWindowMask | NSResizableWindowMask |
108 NSUnifiedTitleAndToolbarWindowMask )
109 backing: NSBackingStoreBuffered defer: NO ] == nil ) {
112 [self setTitle: NS_("Preferences")];
113 [self setDelegate: self];
114 NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
115 [toolbar setDelegate: [[LxdreamPrefsToolbarDelegate alloc] init]];
116 [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
117 [toolbar setSizeMode: NSToolbarSizeModeSmall];
118 [toolbar setSelectedItemIdentifier: @"Paths"];
119 [self setToolbar: toolbar];
120 [self setContentView: [self createPathsPane]];
124 - (void)windowWillClose: (NSNotification *)notice
.