Search
lxdream.org :: lxdream/src/cocoaui/cocoa_path.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_path.c
changeset 770:429ff505c450
prev765:4cd066048203
next881:10b67e485aa4
author nkeynes
date Tue Jul 29 10:55:51 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Auto-cancel if the binding field loses focus
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"
    22 @interface LxdreamPrefsPathPane: LxdreamPrefsPane 
    23 {
    24 }
    25 + (LxdreamPrefsPathPane *)new;
    26 @end
    28 @implementation LxdreamPrefsPathPane
    29 + (LxdreamPrefsPathPane *)new
    30 {
    31     return [[LxdreamPrefsPathPane alloc] initWithFrame: NSMakeRect(0,0,600,400)];
    32 }
    33 - (id)initWithFrame: (NSRect)frameRect
    34 {
    35     if( [super initWithFrame: frameRect title: NS_("Paths")] == nil ) {
    36         return nil;
    37     } else {
    38         int i;
    39         int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;
    41         for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
    42             const struct lxdream_config_entry *entry = lxdream_get_config_entry(i);
    43             if( entry->label != NULL ) {
    44                 NSRect frame = NSMakeRect( TEXT_GAP, height -((TEXT_HEIGHT+TEXT_GAP)*i - 2), 
    45                                            150, LABEL_HEIGHT );
    46                 NSTextField *label = cocoa_gui_add_label(self, NS_(entry->label), frame);
    47                 [label setAlignment: NSRightTextAlignment];
    49                 frame = NSMakeRect( 150 + (TEXT_GAP*2), 
    50                                     height -((TEXT_HEIGHT+TEXT_GAP)*i), 
    51                                     360, TEXT_HEIGHT ); 
    52                 NSTextField *field = [[NSTextField alloc] initWithFrame: frame];
    53                 [field setTag: i];
    54                 [field setStringValue: [NSString stringWithCString: entry->value]]; 
    55                 [field setDelegate: self];
    56                 [field setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];
    57                 [self addSubview: label];
    58                 [self addSubview: field];
    59             }
    60         }
    61     }
    62     return self;
    63 }
    64 - (void)controlTextDidEndEditing:(NSNotification *)notify
    65 {
    66     int tag = [[notify object] tag];
    67     const char *str = [[[notify object] stringValue] UTF8String];
    68     const char *oldval = lxdream_get_config_value(tag);
    69     if( str[0] == '\0' )
    70         str = NULL;
    71     if( oldval == NULL ? str != NULL : (str == NULL || strcmp(oldval,str) != 0 ) ) {   
    72         lxdream_set_global_config_value(tag, str);
    73         lxdream_save_config();
    74     }
    75 }
    76 @end
    79 NSView *cocoa_gui_create_prefs_path_pane()
    80 {
    81     return [LxdreamPrefsPathPane new];
    82 }
.