filename | src/cocoaui/cocoa_path.m |
changeset | 1041:5fcc39857c5c |
prev | 1039:98b9f0791bff |
next | 1070:f543ee84dceb |
author | nkeynes |
date | Sun Jun 28 12:08:16 2009 +0000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Fix creating first VMU (failed to add to list) Fix device-changed causing second device-changed to fire |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Construct and manage the paths configuration pane
5 *
6 * Copyright (c) 2008 Nathan Keynes.
7 *
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.
12 *
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.
17 */
19 #include "cocoaui.h"
20 #include "config.h"
21 #include "lxpaths.h"
22 #include "dreamcast.h"
24 @interface LxdreamPrefsPathPane: LxdreamPrefsPane
25 {
26 NSTextField *fields[CONFIG_KEY_MAX];
27 }
28 + (LxdreamPrefsPathPane *)new;
29 @end
31 @implementation LxdreamPrefsPathPane
32 + (LxdreamPrefsPathPane *)new
33 {
34 return [[LxdreamPrefsPathPane alloc] initWithFrame: NSMakeRect(0,0,600,400)];
35 }
36 - (id)initWithFrame: (NSRect)frameRect
37 {
38 if( [super initWithFrame: frameRect title: NS_("Paths")] == nil ) {
39 return nil;
40 } else {
41 int i;
42 int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;
43 int y = height;
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];
54 [field setTag: i];
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];
61 [button setTag: i];
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:)];
69 } else {
70 [button setAction: @selector(openDirDialog:)];
71 }
73 [self addSubview: label];
74 [self addSubview: field];
75 [self addSubview: button];
76 fields[i] = field;
77 y -= (TEXT_HEIGHT + TEXT_GAP);
78 }
79 }
80 }
81 return self;
82 }
83 - (void)controlTextDidEndEditing:(NSNotification *)notify
84 {
85 int tag = [[notify object] tag];
86 const char *str = [[[notify object] stringValue] UTF8String];
87 const char *oldval = lxdream_get_global_config_value(tag);
88 if( str[0] == '\0' )
89 str = NULL;
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();
94 }
95 }
96 - (void)openFileDialog: (id)sender
97 {
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();
109 }
110 }
111 - (void)openDirDialog: (id)sender
112 {
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();
126 }
127 }
129 @end
132 NSView *cocoa_gui_create_prefs_path_pane()
133 {
134 return [LxdreamPrefsPathPane new];
135 }
.