home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio-DSP / NU / Source / PrefsManager.m < prev    next >
Encoding:
Text File  |  1993-02-27  |  8.7 KB  |  269 lines

  1. #import "PrefsManager.h"
  2. #import "NuString.h"
  3. #import <appkit/appkit.h>
  4. #import <defaults/defaults.h>
  5. #import <objc/List.h>
  6. #import <strings.h>
  7. #import <ctype.h>
  8. #import "MenuManager.h"
  9.  
  10. // set to YES iff we are setting the NuPath
  11. // var via a modal loop
  12. BOOL modalSetup = NO ;
  13.  
  14. // defaults to use if none in database
  15. static NXDefaultsVector nuDefaults = 
  16. { {"NuPath",""},
  17.   {"NXFont","Ohlfs"},
  18.   {"NXFontSize","11.0"},
  19.   {"HeightInChars","25"},
  20.   {"WidthInChars","25"},
  21.   {"Flags","101"},
  22.   {"CompilerOptions","-w -g"},
  23.   {"Libraries","/usr/local/lib/libmusickit.a /usr/local/lib/libsynthpatches.a "
  24.      "/usr/local/lib/libunitgenerators.a /usr/local/lib/libdsp.a "
  25.      "/usr/lib/libNeXT_p.a"},
  26.   // importText,atText,methodText,commentText,otherText
  27.   {"classText0",  "Courier \\fs28  \\red0\\green0\\blue0 \\b0 \\i0 \\ul0"},
  28.   {"classText1",  "Courier \\fs28 \\red0\\green0\\blue0  \\b0 \\i0 \\ul0"},
  29.   {"classText2",  "Ohlfs \\fs22 \\red0\\green0\\blue0  \\b \\i \\ul"},
  30.   {"classText3",  "Courier \\fs22 \\red0\\green0\\blue0  \\b0 \\i0 \\ul0"},
  31.   {"classText4",  "Courier \\fs22 \\red0\\green0\\blue0  \\b0 \\i1 \\ul0 "},
  32.   {NULL} 
  33. } ;
  34.  
  35. // archive (library) extension 
  36. const char *libTypes[] = 
  37. { "a",
  38.   NULL 
  39. } ;
  40.  
  41.  
  42. @implementation PrefsManager: Object
  43. {  id // the preferences view
  44.      prefView,
  45.      // default path
  46.      NuPath,
  47.      // default font and size
  48.      NXFont, NXFontSize,
  49.      // classmanager and workspace behavior
  50.      manyOne, backupRTF, 
  51.      // classmanager formatting:
  52.      // importText, atText, methodText,
  53.      // commentText, otherText     
  54.      classText0, classText1,
  55.      classText2, classText3, classText4,
  56.      // compile and link parameters
  57.      compilerOptions, linkBrowser,
  58.      linkList, debugFile,
  59.     // need to change behavior of class text scroll object
  60.      classTextScroller ;
  61. }
  62. - (int)browser:sender fillMatrix:matrix inColumn:(int)column ;
  63. { // delegate method for browser object 
  64.   return [linkList count] ;
  65. }
  66.  
  67. - browser:sender loadCell:cell atRow:(int)row inColumn:(int)column ;
  68. { [cell setStringValue: [[linkList objectAt: row] cString]] ;
  69.   [cell setLeaf: YES] ;
  70.   return self ;
  71. }
  72.  
  73. - changePref: sender ;
  74. { // move the prefView to the "correct" location.
  75.   // prefView panels are 400 points wide.
  76.   [prefView moveTo:[[sender selectedCell] tag] * -400.0 :0.0] ;
  77.   [[prefView window] display] ;
  78.   return self ;
  79. }
  80.  
  81.  
  82.  
  83. - linkAdd: sender ;
  84. { // add a library file's name to the list
  85.   // of libraries to be searched
  86.   id openPanel ;
  87.   char **theList, buf[256] ;
  88.  
  89.   openPanel = [OpenPanel new] ;
  90.   if([openPanel runModalForTypes: libTypes])
  91.   { theList = (char **) [openPanel filenames] ;
  92.     { sprintf(buf,"%s/%s",[openPanel directory],
  93.         *theList++) ;
  94.       [linkList addObject: [NuString new:buf]] ;
  95.     }
  96.     [linkBrowser loadColumnZero] ;
  97.     [self setDefaults: self] ;
  98.   }  
  99.   return self ;   
  100. }
  101.  
  102. - linkList ;
  103. { return linkList ;
  104. }
  105.  
  106. - linkRemove: sender ;
  107. { // remove a library file's name to the list
  108.   // of libraries to be searched
  109.   int theRow ;
  110.   theRow = [[linkBrowser matrixInColumn: 0] selectedRow] ;
  111.   if(theRow >= 0)
  112.   { [[linkList removeObjectAt: theRow] free] ;
  113.     [linkBrowser loadColumnZero] ;
  114.     [self setDefaults: self] ;
  115.   }
  116.   return self ;
  117. }
  118.  
  119. - setDefaults: sender ;
  120. { // write info from defaults panel to defaults
  121.   // database and to objects as needed
  122.   char flags[10], ivar[12], theText[5][256], libString[2048] ;
  123.   id theIvar ;
  124.   int i, knt ;
  125.   NXColor aColor ;
  126.   float red,green,blue ;
  127.   NXDefaultsVector theDefaults =
  128.   { {"NuPath",NULL},
  129.     {"NXFont",NULL},
  130.     {"NXFontSize",NULL},
  131.     {"Flags",NULL} ,
  132.     {"Libraries",NULL},
  133.     {"CompilerOptions",NULL},
  134.     {"classText0",NULL},
  135.     {"classText1", NULL},
  136.     {"classText2",NULL},
  137.     {"classText3",NULL},
  138.     {"classText4",NULL},
  139.     {NULL}
  140.   } ;
  141.   // if we are setting the NuPath for the first time, then
  142.   // we are running modally, and must abort the modal loop
  143.   if(modalSetup && ([sender cell] == NuPath))
  144.   { [NXApp stopModal] ;
  145.     [[prefView window] orderOut: self] ;
  146.   }
  147.   // fetch the current values
  148.   theDefaults[0].value = (char *) [NuPath stringValue] ;
  149.   theDefaults[1].value = (char *) [NXFont stringValue] ;
  150.   theDefaults[2].value = (char *) [NXFontSize stringValue] ;
  151.   // set flag values
  152.   flags[BACKUPRTF] = (char) [backupRTF selectedCol] + '0' ;
  153.   flags[DEBUGFILES] = (char) [debugFile selectedCol] + '0' ;
  154.   flags[MULTIPLECLASSWINDOWS] = (char) [manyOne selectedCol] + '0' ;
  155.   flags[3] = '\0' ;
  156.   theDefaults[3].value = flags ;
  157.   // set the Libraries preference
  158.   knt = [linkList count] ;
  159.   libString[0] = '\0' ;
  160.   for(i = 0 ; i < knt ; i++)
  161.   { strcat(libString,[[linkList objectAt: i] cString]) ;
  162.     strcat(libString," ") ;
  163.   }
  164.   theDefaults[4].value = libString ;
  165.   // set the compiler options
  166.   theDefaults[5].value = (char *) [compilerOptions stringValue] ;
  167.   // set the classText prefs
  168.   for(i = 0 ; i < 5 ; i++)
  169.   { // "manufacture" the instance vars classText0, classText1, ...
  170.     sprintf(ivar,"classText%1d",i) ;
  171.     object_getInstanceVariable(self,ivar,(void **) &theIvar) ;
  172.     // grab the color...
  173.     aColor = [[theIvar findViewWithTag: 2] color] ;
  174.     NXConvertColorToRGBA (aColor, &red, &green, &blue, NULL);
  175.     sprintf(theText[i],"%s \\fs%d \\red%d\\green%d\\blue%d \\b%s \\i%s \\ul%s", 
  176.       [[theIvar findViewWithTag: 0] stringValue] ,
  177.       (int) ([[theIvar findViewWithTag: 1] floatValue] * 2),
  178.       (int)(red * 256), (int) (green * 256), (int) (blue * 256),
  179.       [[theIvar findViewWithTag: 3] state] ? "" : "0",
  180.       [[theIvar findViewWithTag: 4] state] ? "" : "0",
  181.       [[theIvar findViewWithTag: 5] state] ? "" : "0") ;
  182. [Nu printf: "theText[%d] = %s\n",i,theText[i]] ;
  183.     theDefaults[i + 6].value = (char *) theText[i] ;
  184.   }
  185.   NXWriteDefaults([NXApp appName], theDefaults) ; 
  186.   return self ;
  187. }
  188.  
  189. - setClassTextScroller: anObject ;
  190. { // need to change behavior of scroller to
  191.   // workaround appkit bug with scrollers
  192.   classTextScroller = anObject ;
  193.   [anObject setCopyOnScroll: NO] ;
  194.   [anObject setDynamicScrolling: NO] ;
  195.   return self ;
  196. }
  197.  
  198. - setup ;
  199. { // perform initialization
  200.   const char *appName, *flags, *defaults ;
  201.   char ivar[12],fontName[12],fontBold[12], 
  202.        fontItalic[12], fontUnderline[12] ;
  203.   int i, fontSize, red, green, blue ;
  204.   id theIvar ;
  205.     
  206.   appName = [NXApp appName] ;
  207.   NXRegisterDefaults([NXApp appName], nuDefaults) ;
  208.   [NXFont setStringValue: NXGetDefaultValue(appName,"NXFont")] ;
  209.   [NXFontSize setStringValue: NXGetDefaultValue(appName,"NXFontSize")] ;
  210.   [NuPath setStringValue: NXGetDefaultValue(appName,"NuPath")] ;
  211.   flags = NXGetDefaultValue(appName,"Flags") ;
  212.   [backupRTF selectCellAt: 0 :flags[BACKUPRTF] - '0'] ;
  213.   [debugFile selectCellAt: 0 :flags[DEBUGFILES] - '0'] ; 
  214.   [manyOne selectCellAt: 0 :flags[MULTIPLECLASSWINDOWS] - '0'] ; 
  215.   for(i = 0 ; i < 5 ; i++)
  216.   { // "manufacture" the dread, ivar names classText0, classText1, ...    
  217.     sprintf(ivar,"classText%1d",i) ;
  218.     object_getInstanceVariable(self,ivar,(void **) &theIvar) ;
  219.     defaults = NXGetDefaultValue(appName,ivar) ;
  220.     sscanf(defaults,"%s \\fs%d \\red%d\\green%d\\blue%d %s %s %s ",
  221.        fontName, &fontSize, &red, &green, &blue, fontBold, fontItalic, fontUnderline) ;
  222.     [[theIvar findViewWithTag: 0] setStringValue: fontName] ;
  223.     [[theIvar findViewWithTag: 1] setIntValue: fontSize / 2.0] ;
  224.     [[theIvar findViewWithTag: 2] setColor:
  225.       NXConvertRGBAToColor(red * 256.0, green * 256.0 , 
  226.        blue * 256.0, NX_NOALPHA)];
  227.     [[theIvar findViewWithTag: 3] setState: !strcmp(fontBold,"\\b") ? 1 : 0] ;
  228.     [[theIvar findViewWithTag: 4] setState: !strcmp(fontItalic,"\\i") ? 1 : 0] ;
  229.     [[theIvar findViewWithTag: 5] setState: !strcmp(fontUnderline,"\\ul") ? 1 : 0] ;
  230.   }
  231.  
  232.   // init the linkList
  233.   { char libPath[512] ;
  234.     const char *libraries ;
  235.     int i = 0, rval ;
  236.     linkList = [[List alloc] init] ;
  237.     libraries = NXGetDefaultValue(appName,"Libraries") ;
  238.     rval = sscanf(libraries,"%s",libPath) ;
  239.     while(rval == 1)
  240.     { [linkList addObject: [NuString new: libPath]] ;
  241.       while(libraries[i] &&
  242.         !isspace(libraries[i++])) ; // find next library
  243.       rval = sscanf(&libraries[i],"%s",libPath) ;
  244.     }
  245.     [linkBrowser loadColumnZero] ;
  246.   }  
  247.   // init the compiler options
  248.   [compilerOptions setStringValue: 
  249.          NXGetDefaultValue(appName,"CompilerOptions")] ;
  250.   // download postscript to server
  251.   return self ;
  252. }
  253.  
  254. - setNuPath ;
  255. { // the first time a user runs Nu, the NuPath pref will not
  256.   // be set, so this code will be invoked to force them to set it
  257.   int rval = NXRunAlertPanel("Nu",
  258.     "The Glyph Path is incorrect or has never been set.\n"
  259.       "Please use the preferences panel to set it now.",
  260.     "Set","Quit Without Setting",NULL) ;
  261.   if(rval == NX_ALERTALTERNATE)
  262.        [NXApp terminate: self] ;
  263.   modalSetup = YES ;
  264.   [NXApp runModalFor: [prefView window]] ;
  265.   modalSetup = NO ;
  266.   return self ;
  267. }
  268.  
  269. @end