home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / MiscKit1.2.6 / Source / MiscInspectorKit / MiscInspectorManager.m < prev    next >
Encoding:
Text File  |  1994-03-08  |  7.4 KB  |  333 lines

  1. /* MiscInspectorManager.m                 
  2.  *
  3.  * This is a general class that should make it easy to implement Inspectors
  4.  * as we know them from the WM or IB...but more general purpose.
  5.  * Anyway. It's not a real inspector. It's the class the manages the selection
  6.  * and all the different inspectors.
  7.  *
  8.  * For interface-info see the header file. The comments in this file mostly
  9.  * cover only the real implementation details.
  10.  *
  11.  * Written by:         Thomas Engel
  12.  * Created:            08.02.1994 (Copyleft)
  13.  * Last modified:     25.02.1994
  14.  */
  15.  
  16. //#import "MiscInspectorManager.h"
  17. //#import "MiscInspector.h"
  18. //#import "MiscInspectorWrapper.h"
  19. //#import "MiscSwapView.h"
  20. #import <misckit/misckit.h>
  21.  
  22. @implementation MiscInspectorManager
  23.  
  24. - init
  25. {
  26.     self = [super init];
  27.     if( !self ) return self;
  28.  
  29.     // OK. We really are an object...just load the NIB and get the
  30.     // default inspectors.
  31.     // And we'll initialize the swap Controllers to have some kind of startup
  32.     // config.
  33.     
  34.     [[self loadNibSection] addDefaultInspectors];
  35.     [self updateInspectors];
  36.     return self;
  37. }
  38.  
  39. - loadNibSection
  40. {
  41.     if( [NXApp loadNibSection:"Inspector.nib" owner:self] == nil )
  42.         NXRunAlertPanel( NULL, "Couldn't load Inspector.nib",
  43.                          "OK" ,NULL, NULL );
  44.                          
  45.     return self;
  46. }
  47.  
  48. - makeKeyAndOrderFront:sender
  49. {
  50.     // If the window is visible we will make it key. We don't have to take 
  51.     // care about the selection because [inspect] does it if the window IS
  52.     // visible.
  53.     // Otherwise we will updateInspectors and cause the swapView to swap.
  54.         
  55.     if( [window isVisible] ) 
  56.         [window makeKeyAndOrderFront:sender];
  57.     else
  58.     {
  59.         [self updateInspectors];
  60.         [swapView swapContentView:self];
  61.     }
  62.     return self;
  63. }
  64.  
  65. - inspect:anObject
  66. {
  67.     selection = anObject;
  68.     if( selection == nil ) 
  69.             selectionCount = 0;
  70.     else    selectionCount = 1;
  71.  
  72.     if( [window isVisible] )
  73.     {
  74.         [self updateInspectors];
  75.         [swapView swapContentView:self];
  76.     }
  77.     return self;
  78. }
  79.  
  80. - inspectList:aList
  81. {
  82.     // If there is not really a List of object to inspect then lets handle it
  83.     // as a simple inspection.
  84.     
  85.     if( [aList count] < 2 )
  86.         return [self inspect:[aList objectAt:0]];
  87.     
  88.     // ...ok its a true list.
  89.     
  90.     selection = aList;
  91.     selectionCount = [aList count];
  92.     if( [window isVisible] )
  93.     {
  94.         [self updateInspectors];
  95.         [swapView swapContentView:self];
  96.     }
  97.     return self;
  98. }
  99.  
  100. - selection
  101. {
  102.     return selection;
  103. }
  104.  
  105. - (unsigned)selectionCount
  106. {
  107.     return selectionCount;
  108. }
  109.  
  110. - addInspector:anInspector
  111. {
  112.     // Here we add inspectors to our list. We do NOT check if they are unique.
  113.     // Anyway.It will not make any problems.
  114.     
  115.     if( !inspectors ) inspectors = [List new];
  116.     [inspectors addObject:anInspector];
  117.     return self;
  118. }
  119.  
  120. - addDefaultInspectors
  121. {
  122.     // Here we will add the 3 default inspectors for our default NIB.
  123.     // We don't add them by setting the direct connection to the manager (self)
  124.     // becuase we couln't tell in which order they will be added. And that's
  125.     // a problem because order is very importat here.
  126.     
  127.     [notApplInspector setManager:self];
  128.     [noSelInspector setManager:self];
  129.     [multiSelInspector setManager:self];
  130.     
  131.     return self;
  132. }
  133.  
  134. - updateInspectors
  135. {
  136.     // Let's find the inspector that want to deal with our current selection.
  137.     // We will add everyone to the swapViews controller list.
  138.     // If there are many different inspectors for the same trigger only the
  139.     // last will remain in the controller list!
  140.     //
  141.     // Attention: This does not cause the swapView to update its display!!!!
  142.     //                 You might need to trigger a swap on your own.
  143.     //              Anyway. You should use this method directly. Use [inspect:].
  144.     //
  145.     // Note: Remember. If you change the controllers of a swapView you should
  146.     //         be sure that there will be a new controller 
  147.     
  148.     id        anInspector;
  149.     int        i;
  150.     
  151.     for( i=0; i<[inspectors count]; i++ )
  152.     {
  153.         anInspector = [inspectors objectAt:i];
  154.         if( [anInspector doesHandleSelection] )
  155.         {
  156.             if( [anInspector respondsTo:@selector(addWrappedControllers)] )
  157.                     [anInspector addWrappedControllers];
  158.             else    [swapView addController:anInspector];
  159.         }
  160.     }
  161.     return self;
  162. }
  163.  
  164. - setSwapView:anObject
  165. {
  166.     swapView = anObject;
  167.     [swapView setDelegate:self];
  168.     
  169.     return self;
  170. }
  171.  
  172. - swapView
  173. {
  174.     return swapView;
  175. }
  176.  
  177. - window
  178. {
  179.     return window;
  180. }
  181.  
  182. - setOkButton:aButton
  183. {
  184.     // To keep up with the state and superview stuff.
  185.  
  186.     okButton = aButton;
  187.     if( buttonsSuperview == nil ) buttonsSuperview = [okButton superview];
  188.     buttonsVisible = YES;
  189.         
  190.     return self;
  191. }
  192.  
  193. - okButton
  194. {
  195.     return okButton;
  196. }
  197.  
  198. - setRevertButton:aButton
  199. {
  200.     // To keep up with the state and superview stuff.
  201.     
  202.     revertButton = aButton;
  203.     if( buttonsSuperview == nil ) buttonsSuperview = [revertButton superview];
  204.     buttonsVisible = YES;
  205.     
  206.     return self;
  207. }
  208.  
  209. - revertButton
  210. {
  211.     return revertButton;
  212. }
  213.  
  214. - setShowButtons:(BOOL)flag
  215. {
  216.     // Here we will hide/undhide ok/revert buttons.
  217.     // By default they are disabled.
  218.  
  219.     [[okButton cell] setEnabled:NO];
  220.     [[revertButton cell] setEnabled:NO];    
  221.  
  222.     if( flag == YES )
  223.     {
  224.         if( !buttonsVisible )
  225.         {
  226.             [buttonsSuperview addSubview:okButton];
  227.             [buttonsSuperview addSubview:revertButton];
  228.             buttonsVisible = YES;
  229.         }
  230.     }
  231.     else
  232.     {
  233.         if( buttonsVisible )
  234.         {
  235.             [okButton removeFromSuperview];
  236.             [revertButton removeFromSuperview];
  237.             buttonsVisible = NO;
  238.         }
  239.     }
  240.  
  241.     return self;
  242. }
  243.  
  244. - ok:sender
  245. {
  246.     return [[swapView contentsController] ok:sender];
  247. }
  248.  
  249. - revert:sender
  250. {
  251.     return [[swapView contentsController] revert:sender];
  252. }
  253.  
  254. - touch:sender
  255. {
  256.     // This methode should be invoked when the contens of the inspector
  257.     // has changed and should be confirmed. We just change some Buttons here.
  258.  
  259.     [[okButton cell] setEnabled:YES];
  260.     [[revertButton cell] setEnabled:YES];    
  261.     [window setDocEdited:YES];
  262.     
  263.     return self;
  264. }
  265.  
  266. - textDidChange:sender
  267. {
  268.     // If we are a text-objects delegate we get an easy touch-handling.
  269.     // Well normally we will never be e texts delegate but the single
  270.     // inspectors use this method when they are delegates.
  271.  
  272.     [self touch:self];
  273.     return self;
  274. }
  275.  
  276. /*
  277.  * These are the delegate-methods we provide for our swapView. This is were
  278.  * we make our view come to front after command-key actions. We do them after
  279.  * the swap to make it nicer. Only if the window was not visible up to then.
  280.  */
  281.  
  282. - viewWillSwap:sender
  283. {
  284.     // Befor the swap we have to ensure that the controllerList is up to date.
  285.     // Otherwise the swapView would choose a wrong controller and display
  286.     // the wrong one.
  287.     
  288.     if( ![window isVisible] ) [self updateInspectors];
  289.  
  290.     return self;
  291. }
  292.  
  293. - viewDidSwap:sender
  294. {
  295.     if( ![window isVisible] ) [window makeKeyAndOrderFront:self];
  296.  
  297.     return self;
  298. }
  299.  
  300. @end
  301.  
  302. /*
  303.  * History: 25.02.94 Seems like I forgot the ok,revert here ... hmm
  304.  *
  305.  *            22.02.94 Made it new-swapView-conform.
  306.  *
  307.  *            11.02.94 Remove some little 'feature-bugs'
  308.  *
  309.  *            08.02.94 A complete redesign for the MiscKit. Only the basic idea
  310.  *                     remains the same as in earlier versins.
  311.  *
  312.  *            15.01.94 Added automatich window title setting to -revert.
  313.  *
  314.  *            11.01.94 Did make the ok and revert method more firendly.
  315.  *                     They know let the viewController know whats going on. 
  316.  *
  317.  *            08.01.94 Updated to our new swapController.
  318.  *
  319.  *            18.12.93 Many methods get their first code. It all should end up
  320.  *                     with easy new-inspectors just a click away...
  321.  *
  322.  *            14.12.93 Just added some code for object inspection. Well some
  323.  *                     pieces of the code should be moved to the MultipagePanel
  324.  *
  325.  *            25.11.93 Created a copy of the pref-manager.
  326.  *
  327.  *
  328.  * Bugs: - inspect(List):
  329.  *           does check only [window isVisilbe] this is not what I really want.
  330.  *           I should aviod updating inside miniwindows ! Saves some drawing time
  331.  *           But Inspectors are seldom minimizable so this might not be too 
  332.  *         serious.
  333.  */