home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / OOP_Course / Examples / ExtendDraw / Controller.m < prev    next >
Encoding:
Text File  |  1993-01-19  |  2.0 KB  |  71 lines

  1. #import <appkit/appkit.h>
  2. #import "Controller.h"
  3.  
  4. @implementation Controller
  5.  
  6. -loadNewTool:sender
  7. {
  8.     OpenPanel  *openPanel;
  9.     id newClass, newItem, newCell, newIcon;
  10.     id newBundle;
  11.     const char *fileTypes[2] = {"bundle",NULL};
  12.     char fullName[MAXPATHLEN+1];
  13.     int newTag;
  14.     const char *bundleName;
  15.     NXRect r;
  16.     
  17.     /* Get an OpenPanel and get the filename of the desired bundle. */
  18.     openPanel = [OpenPanel new];
  19.     if( ![openPanel runModalForTypes:fileTypes] ) return self;          //leave if Cancel or none
  20.     bundleName = [openPanel filename];
  21.  
  22.     /* Get new bundle and the class object in it. */
  23.     newBundle = [[NXBundle alloc] initForDirectory:bundleName];
  24.     if( (newClass = [newBundle principalClass]) == nil) return self;    //leave if no class
  25.     
  26.     /* Give the new class to the draw view as a new draw class. */
  27.     newTag = [drawView addShapeClass:newClass];
  28.  
  29.     /* Add corresponding item to Tools menu, and set action, target, tag. */
  30.     newItem = [toolsMenu    addItem:[newClass name]
  31.                             action:@selector(takeDrawTypeFrom:)
  32.                             keyEquivalent:0]; 
  33.     [newItem setTarget:self];
  34.     [newItem setTag:newTag];
  35.     [toolsMenu display];
  36.     
  37.     /* Add button with icon to the Tools palette, and set tag. */
  38.     /* First, get path to the tiff file with the palette icon. */
  39.     if( [newBundle        getPath:fullName
  40.                     forResource:[newClass name]
  41.                     ofType:"tiff"]) {
  42.     
  43.         /* Now get the icon and stick on a new buttoncell in the matrix. */
  44.         if(newIcon=[[NXImage alloc] initFromFile:fullName]){
  45.             [toolPalette addCol];
  46.             newCell=[toolPalette cellAt:0 :([toolPalette cellCount]-1)];
  47.             [[newCell    setTag:newTag]
  48.                         setImage:newIcon];
  49.  
  50.             /* Finally, resize matrix and window to hold new cell. */
  51.             [toolPalette sizeToCells];
  52.             [toolPalette getFrame:&r];
  53.             [[toolPalette window] sizeWindow:r.size.width :r.size.height];
  54.             [toolPalette moveTo:0.0 :0.0];
  55.             [[toolPalette window] display];
  56.         }
  57.     }
  58.         
  59.     return self; 
  60. }
  61.  
  62. -takeDrawTypeFrom:sender
  63. {
  64.     int tag=[sender selectedTag];
  65.     [drawView setDrawType:tag];
  66.     [toolPalette selectCellWithTag:tag];     //in case from menu, select also in palette
  67.     return self;
  68. }
  69.  
  70. @end 
  71.