4 * Construct and manage the paths configuration pane
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.
22 #include "dreamcast.h"
24 @interface LxdreamPrefsPathPane: LxdreamPrefsPane
26 NSTextField *fields[CONFIG_KEY_MAX];
28 + (LxdreamPrefsPathPane *)new;
31 @implementation LxdreamPrefsPathPane
32 + (LxdreamPrefsPathPane *)new
34 return [[LxdreamPrefsPathPane alloc] initWithFrame: NSMakeRect(0,0,600,400)];
36 - (id)initWithFrame: (NSRect)frameRect
38 if( [super initWithFrame: frameRect title: NS_("Paths")] == nil ) {
42 int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;
45 for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
46 const struct lxdream_config_entry *entry = lxdream_get_global_config_entry(i);
47 if( entry->label != NULL ) {
48 NSRect frame = NSMakeRect( TEXT_GAP, y+2, 150, LABEL_HEIGHT );
49 NSTextField *label = cocoa_gui_add_label(self, NS_(entry->label), frame);
50 [label setAlignment: NSRightTextAlignment];
52 frame = NSMakeRect( 150 + (TEXT_GAP*2), y, 360, TEXT_HEIGHT );
53 NSTextField *field = [[NSTextField alloc] initWithFrame: frame];
55 [field setStringValue: [NSString stringWithCString: entry->value]];
56 [field setDelegate: self];
57 [field setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];
59 frame = NSMakeRect( 510 + (TEXT_GAP*3), y, TEXT_HEIGHT, TEXT_HEIGHT );
60 NSButton *button = [[NSButton alloc] initWithFrame: frame];
62 [button setTitle: @""];
63 [button setButtonType: NSMomentaryPushInButton];
64 [button setBezelStyle: NSRoundedDisclosureBezelStyle];
65 [button setAutoresizingMask: (NSViewMinYMargin|NSViewMinXMargin)];
66 [button setTarget: self];
67 if( entry->type == CONFIG_TYPE_FILE ) {
68 [button setAction: @selector(openFileDialog:)];
70 [button setAction: @selector(openDirDialog:)];
73 [self addSubview: label];
74 [self addSubview: field];
75 [self addSubview: button];
77 y -= (TEXT_HEIGHT + TEXT_GAP);
83 - (void)controlTextDidEndEditing:(NSNotification *)notify
85 int tag = [[notify object] tag];
86 const char *str = [[[notify object] stringValue] UTF8String];
87 const char *oldval = lxdream_get_global_config_value(tag);
90 if( oldval == NULL ? str != NULL : (str == NULL || strcmp(oldval,str) != 0 ) ) {
91 lxdream_set_global_config_value(tag, str);
92 lxdream_save_config();
93 dreamcast_config_changed();
96 - (void)openFileDialog: (id)sender
98 int tag = [sender tag];
99 NSString *text = [fields[tag] stringValue];
100 NSOpenPanel *panel = [NSOpenPanel openPanel];
101 int result = [panel runModalForDirectory: nil file: nil types: nil];
102 if( result == NSOKButton && [[panel filenames] count] > 0 ) {
103 NSString *filename = [[panel filenames] objectAtIndex: 0];
104 gchar *str = get_escaped_path( [filename UTF8String] );
105 [fields[tag] setStringValue: [NSString stringWithUTF8String: str]];
106 lxdream_set_global_config_value(tag,str);
107 lxdream_save_config();
108 dreamcast_config_changed();
111 - (void)openDirDialog: (id)sender
113 int tag = [sender tag];
114 NSString *text = [fields[tag] stringValue];
115 NSOpenPanel *panel = [NSOpenPanel openPanel];
116 [panel setCanChooseDirectories: YES];
117 [panel setCanCreateDirectories: YES];
118 int result = [panel runModalForDirectory: nil file: nil types: nil];
119 if( result == NSOKButton && [[panel filenames] count] > 0 ) {
120 NSString *filename = [[panel filenames] objectAtIndex: 0];
121 gchar *str = get_escaped_path( [filename UTF8String] );
122 [fields[tag] setStringValue: [NSString stringWithUTF8String: str]];
123 lxdream_set_global_config_value(tag,str);
124 lxdream_save_config();
125 dreamcast_config_changed();
132 NSView *cocoa_gui_create_prefs_path_pane()
134 return [LxdreamPrefsPathPane new];
.