
/* MiscInspectorController.m created by todd on Sun 05-May-1996 */

#import <AppKit/AppKit.h>
#import "MiscInspectorController.h"

@implementation MiscInspectorController

/*"
	MiscInspectorController is just a simple experiment on how to do
	some inspecting without the inspected objects knowing that they are
	being inspected.
"*/


//-------------------------------------------------------------------
// 	Accessor methods
//-------------------------------------------------------------------

- (MiscController*) inspectedController
/*"
   Returns the inspector we are currently inspecting or nil if
   we aren't currently inspecting.
"*/
{
    return _inspectedController;
}


//-------------------------------------------------------------------
// 	Inspected controller notification
//-------------------------------------------------------------------

- (void) controllerDidEdit:(NSNotification*)notification
/*"
   The controller we are inspecting did edit, so we call #update
   to update our inspector.
"*/
{
    // May want to check if [notification object] and our
    // inspected controller are the same.
    [self update];
}


//-------------------------------------------------------------------
// 	Starting/stopping
//-------------------------------------------------------------------

- (void) startInspectingController:(MiscController*)controller
/*"
   This method is called from an instance of MiscInspectorMediator
   letting us know the controller we should be inspecting. NOTE TO ME:
   Some of this code should be moved into #setInspectedController:.
"*/
{
    MiscController* oldController = [self inspectedController];
    
    [self setInspectedController:controller];
    if (controller != nil) {
        // Register so we get controllerDidEdit notifications.
        [self _registerForControllerDidEditNotification:controller];

        // We'd like immediate feedback on what we are now inspecting.
        [self update];
    }
    else {
        [self _nothingToInspect];
    }

    // Unregister for edit notifications from our old inspected
    // controller.
    if (oldController != nil) {
        [self _unregisterForControllerDidEditNotification:oldController];

		// A previous call to stopInspectingController may have
		// started a delayed perform so cancel it.
		[NSObject cancelPreviousPerformRequestsWithTarget:self
			selector:@selector(_nothingToInspect) object:nil];
		
    }
}


- (void) stopInspectingController:(MiscController*)controller;
/*"
   Sent from an instance of MiscInspectorMediator letting us know
   that we should stop inspecting controller.
"*/
{
    // Might want to check that controller is the same as _inspectedController.
    // Also what about supporting inspecting multiple things? We should then
    // keep an array of inspected controllers instead of setting our single
    // one to nil.
    [self setInspectedController:nil];

    [self _unregisterForControllerDidEditNotification:controller];
    
    // Send this on a delay because we may get a startInpectingController 
	// message right away from another object. The startInspectingController
	// will cancel any of these messages if another object comes along 
	// that wants inspection.
	[self performSelector:@selector(_nothingToInspect)
               withObject:nil afterDelay:0.0];
}

- (void) update
/*"
   Called from #startInspectingController: and controllerDidEdit:.
   For InspectorController subclasses to use. We do nothing.
*/
{
}

@end

