home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / Rhapsody / Graphics / Morph-2.0a / InspectorController.m < prev    next >
Encoding:
Text File  |  1998-01-06  |  1.8 KB  |  72 lines

  1. #import "InspectorController.h"
  2.  
  3. @implementation InspectorController
  4.  
  5. + (InspectorController *) sharedInspectorController
  6. {
  7.     static InspectorController *sharedObject = nil;
  8.  
  9.     if (sharedObject == nil)
  10.         sharedObject = [[self alloc] init];
  11.     return sharedObject;
  12. }
  13.  
  14. - init
  15. {
  16.     [super init];
  17.     inspectors = [[NSMutableArray alloc] initWithCapacity:2];
  18.  
  19.     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(revert:) name:NOTIFICATION_SELECTION_CHANGED object:nil];
  20.  
  21.     return self;
  22. }
  23.  
  24. - (NSWindow *) panel
  25. {
  26.     if ([inspectorBox window] == nil)
  27.         [NSBundle loadNibNamed:@"inspectorPanel.nib" owner:self];
  28.     return [inspectorBox window];
  29. }
  30.  
  31. - (void) registerInspector:(Inspector *)inspector
  32. {
  33.     [inspectors addObject:inspector];
  34. }
  35.  
  36. - (void)revert:(id)sender
  37. {
  38.     NSEnumerator    *inspectorEnumerator;
  39.     NSArray            *selection;
  40.     BOOL             found = NO;
  41.     NSView            *view, *oldView;
  42.     Inspector        *inspector = nil;
  43.  
  44.     if (![[self panel] isVisible])
  45.         return;
  46.  
  47.     selection = [[[NSApplication sharedApplication] targetForAction:@selector(currentSelection)] currentSelection];
  48.     inspectorEnumerator = [inspectors objectEnumerator];
  49.  
  50.     while (!found && (inspector = [inspectorEnumerator nextObject]))
  51.         found = [inspector isValidInspectorForTargets:selection];
  52.  
  53.     if (found)
  54.     {
  55.         [inspector setTargets:selection];
  56.         [inspector revert:nil];
  57.         oldView = [inspectorBox contentView];
  58.         view = [inspector view];
  59.         if (oldView != view)
  60.         {
  61.             [inspectorBox setContentView:view];
  62.             [[offWin contentView] addSubview:oldView];
  63.         }
  64.     }
  65.     else if ([selection count] == 0)
  66.         [inspectorBox setContentView:emptySelectionInspectorView];
  67.     else
  68.         NSLog (@"Unknown selection:%@", [selection description]);
  69. }
  70.  
  71. @end
  72.