home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / ManPagesFromHeaders / Source / Preferences.m < prev    next >
Encoding:
Text File  |  1993-05-09  |  2.2 KB  |  103 lines

  1. /*
  2.  * Written by Guy Roberts of Object Skills Ltd, drifting
  3.  * in cyberspace without a domain or email address right 
  4.  * now. 
  5.  * May 7 1993. You can use this as a base for a better application
  6.  * as long as it is made publically available.
  7.  */
  8.  
  9. #import "Preferences.h"
  10. #define TITLE "Choose a directory" /* Should be in a string table */
  11. #define IS_DIR(m)      (((m)&S_IFMT) == S_IFDIR)
  12.  
  13. @implementation Preferences
  14.  
  15. - init
  16. {
  17.     const char    *buffer = NXReadDefault(OWNER, "automaticallyLaunchEdit");
  18.     
  19.     [super init];
  20.  
  21.     if (buffer) {
  22.         if (strcmp(buffer, "NO") == 0)
  23.             launchEditAutomatically = NO;
  24.         else if (strcmp(buffer, "YES") == 0)
  25.             launchEditAutomatically = YES;
  26.     }
  27.     else
  28.         launchEditAutomatically = YES;
  29.  
  30.     return self;
  31. }
  32.  
  33. - showPreferencePanel: sender
  34. {
  35.     const char    *dir = NXReadDefault(OWNER, "defaultDirectory");
  36.  
  37.     [inspectorPanel makeKeyAndOrderFront: self];
  38.     
  39.     if (launchEditAutomatically)
  40.         [[autoEditLaunchSwitch    setState: 1] display];
  41.     else
  42.         [[autoEditLaunchSwitch    setState: 0] display];
  43.  
  44.     if (dir)
  45.         [directoryForm    setStringValue: dir at:0];
  46.         
  47.     return self;
  48. }
  49.  
  50. - setManPageDirectory: sender
  51. {
  52.     const char    *dir = [sender stringValueAt:0];
  53.     BOOL        isGoodDir = NO;
  54.     char        badNews[1024];
  55.  
  56.     /* Check that this place is a directory and is writable */    
  57.     {
  58.         struct    stat    buffer;
  59.         
  60.         if (stat(dir, &buffer) == -1) {
  61.             /* If it does not exist, try to fopen it */
  62.             if (mkdir(dir, 0777) == -1) {
  63.                 sprintf(badNews, "Could not make the directory %s (errno %d)",
  64.                     dir, errno);
  65.             }
  66.             else
  67.                 isGoodDir = YES;
  68.         }
  69.         else {
  70.             if (!IS_DIR(buffer.st_mode))
  71.                 sprintf(badNews, "%s is not a directory\n", dir);
  72.             else if (access(dir, W_OK) != 0)
  73.                 sprintf(badNews, "Cannot access %s", dir);
  74.             else
  75.                 isGoodDir = YES;
  76.         }
  77.     }
  78.     
  79.     if( !isGoodDir )
  80.         NXRunAlertPanel(NULL, badNews, NULL, NULL, NULL, "me");
  81.     else {
  82.         /* Set the default value */
  83.         NXWriteDefault(OWNER, "defaultDirectory", dir);
  84.     }
  85.  
  86.     return self;
  87. }
  88.  
  89. - toggleEditDefault: sender
  90. {
  91.     if ([sender    state] == 0) {
  92.         launchEditAutomatically = NO;
  93.         NXWriteDefault(OWNER, "automaticallyLaunchEdit", "NO");
  94.     }
  95.     else if ([sender    state] == 1) {
  96.         launchEditAutomatically = YES;
  97.         NXWriteDefault(OWNER, "automaticallyLaunchEdit", "YES");
  98.     }
  99.  
  100.     return self;
  101. }
  102.  
  103.