revision 1039:98b9f0791bff
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 1039:98b9f0791bff |
parent | 1038:f220d18c0615 |
child | 1040:9e3e41eab2db |
author | nkeynes |
date | Thu Jun 25 09:06:44 2009 +0000 (10 years ago) |
(Finally) add file open dialogs to the path preferences
1.1 --- a/src/cocoaui/cocoa_path.m Thu Jun 25 01:15:25 2009 +00001.2 +++ b/src/cocoaui/cocoa_path.m Thu Jun 25 09:06:44 2009 +00001.3 @@ -22,6 +22,7 @@1.5 @interface LxdreamPrefsPathPane: LxdreamPrefsPane1.6 {1.7 + NSTextField *fields[CONFIG_KEY_MAX];1.8 }1.9 + (LxdreamPrefsPathPane *)new;1.10 @end1.11 @@ -38,25 +39,41 @@1.12 } else {1.13 int i;1.14 int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;1.15 + int y = height;1.17 for( i=0; i<=CONFIG_KEY_MAX; i++ ) {1.18 const struct lxdream_config_entry *entry = lxdream_get_global_config_entry(i);1.19 if( entry->label != NULL ) {1.20 - NSRect frame = NSMakeRect( TEXT_GAP, height -((TEXT_HEIGHT+TEXT_GAP)*i - 2),1.21 - 150, LABEL_HEIGHT );1.22 + NSRect frame = NSMakeRect( TEXT_GAP, y - 2, 150, LABEL_HEIGHT );1.23 NSTextField *label = cocoa_gui_add_label(self, NS_(entry->label), frame);1.24 [label setAlignment: NSRightTextAlignment];1.26 - frame = NSMakeRect( 150 + (TEXT_GAP*2),1.27 - height -((TEXT_HEIGHT+TEXT_GAP)*i),1.28 - 360, TEXT_HEIGHT );1.29 + frame = NSMakeRect( 150 + (TEXT_GAP*2), y, 360, TEXT_HEIGHT );1.30 NSTextField *field = [[NSTextField alloc] initWithFrame: frame];1.31 [field setTag: i];1.32 [field setStringValue: [NSString stringWithCString: entry->value]];1.33 [field setDelegate: self];1.34 [field setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];1.35 +1.36 + frame = NSMakeRect( 510 + (TEXT_GAP*3), y, TEXT_HEIGHT, TEXT_HEIGHT );1.37 + NSButton *button = [[NSButton alloc] initWithFrame: frame];1.38 + [button setTag: i];1.39 + [button setTitle: @""];1.40 + [button setButtonType: NSMomentaryPushInButton];1.41 + [button setBezelStyle: NSRoundedDisclosureBezelStyle];1.42 + [button setAutoresizingMask: (NSViewMinYMargin|NSViewMinXMargin)];1.43 + [button setTarget: self];1.44 + if( entry->type == CONFIG_TYPE_FILE ) {1.45 + [button setAction: @selector(openFileDialog:)];1.46 + } else {1.47 + [button setAction: @selector(openDirDialog:)];1.48 + }1.49 +1.50 [self addSubview: label];1.51 [self addSubview: field];1.52 + [self addSubview: button];1.53 + fields[i] = field;1.54 + y -= (TEXT_HEIGHT + TEXT_GAP);1.55 }1.56 }1.57 }1.58 @@ -75,6 +92,39 @@1.59 dreamcast_config_changed();1.60 }1.61 }1.62 +- (void)openFileDialog: (id)sender1.63 +{1.64 + int tag = [sender tag];1.65 + NSString *text = [fields[tag] stringValue];1.66 + NSOpenPanel *panel = [NSOpenPanel openPanel];1.67 + int result = [panel runModalForDirectory: nil file: nil types: nil];1.68 + if( result == NSOKButton && [[panel filenames] count] > 0 ) {1.69 + NSString *filename = [[panel filenames] objectAtIndex: 0];1.70 + gchar *str = get_escaped_path( [filename UTF8String] );1.71 + [fields[tag] setStringValue: [NSString stringWithUTF8String: str]];1.72 + lxdream_set_global_config_value(tag,str);1.73 + lxdream_save_config();1.74 + dreamcast_config_changed();1.75 + }1.76 +}1.77 +- (void)openDirDialog: (id)sender1.78 +{1.79 + int tag = [sender tag];1.80 + NSString *text = [fields[tag] stringValue];1.81 + NSOpenPanel *panel = [NSOpenPanel openPanel];1.82 + [panel setCanChooseDirectories: YES];1.83 + [panel setCanCreateDirectories: YES];1.84 + int result = [panel runModalForDirectory: nil file: nil types: nil];1.85 + if( result == NSOKButton && [[panel filenames] count] > 0 ) {1.86 + NSString *filename = [[panel filenames] objectAtIndex: 0];1.87 + gchar *str = get_escaped_path( [filename UTF8String] );1.88 + [fields[tag] setStringValue: [NSString stringWithUTF8String: str]];1.89 + lxdream_set_global_config_value(tag,str);1.90 + lxdream_save_config();1.91 + dreamcast_config_changed();1.92 + }1.93 +}1.94 +1.95 @end
.