
/*
	Copyright 1993  Jeremy Slade.

	You are free to use all or any parts of the Locus project
	however you wish, just give credit where credit is due.
	The author (Jeremy Slade) shall not be held responsible
	for any damages that result out of use or misuse of any
	part of this project.

*/

/*
	Project: Locus
	
	Class: FolderInsPane
	
	Description: See FolderInsPane.h
	
	Original Author: Jeremy Slade
	
	Revision History:
		Created
			V.101	JGS Thu Dec 17 21:58:31 MST 1992
			
*/


#import "FolderInsPane.h"

#import "Folder.h"
#import "Globals.h"
#import "Inspector.h"


@implementation FolderInsPane


// -------------------------------------------------------------------------
//   Creating, Initializing
// -------------------------------------------------------------------------


+ initialize
{
	[self setVersion:FolderInsPane_VERSION];
	return ( self );
}



- initContent:(const NXRect *)contentRect
	style:(int)aStyle
	backing:(int)bufferingType
	buttonMask:(int)mask
	defer:(BOOL)flag
{
	[super initContent:contentRect
		style:aStyle
		backing:bufferingType
		buttonMask:mask
		defer:flag];

	return ( self );
}



- awakeFromNib
/*
	Perform final initializations
*/
{
	[browser setDoubleAction:@selector(inspectSelectedGroup:)];
	return ( self );
}



- free
{
	// browser, countField, inspectButton are subviews -- freed automatically
	return ( [super free] );
}



// -------------------------------------------------------------------------
//   Folder Inspector stuff
// -------------------------------------------------------------------------


- inspect:anObject
{
	if ( ![anObject isKindOf:[Folder class]] ) {
		NXRunAlertPanel ( "Inspector Error",
			"The Folder inspector can't inspect objects of class %s!",
			NULL, NULL, NULL, [[anObject class] name] );
		return ( nil );
	} else {
		target = anObject;
		return ( self );
	}
}



- showCurrent:sender
{
	[[browser window] disableFlushWindow];
	
	[browser loadColumnZero]; // Load the browser with the list of Groups
	[inspectButton setEnabled:NO];
	
	[[[browser window] reenableFlushWindow] flushWindow];
	return ( [super showCurrent:sender] );
}



- groupSelected:sender
/*
	This method is the action called when the user selects a group in the browser.  Simply enables the inspectButton so they can click on it.
*/
{
	[inspectButton setEnabled:YES];
	return ( self );
}



- inspectSelectedGroup:sender
/*
	This action is called when the inspect button is clicked, or when a group in the browser is double-clicked.
*/
{
	const char *groupName = NULL;
	id group = nil;
	
	groupName = [[browser selectedCell] stringValue];
	if ( group = [target groupCalled:groupName] ) {
		[inspector setInspectorMode:INSPECT_GROUP];
		[inspector inspect:group];
	}
	
	return ( self );
}



// -------------------------------------------------------------------------
//   Browser Delegate Methods
// -------------------------------------------------------------------------


- (int)browser:sender fillMatrix:matrix inColumn:(int)col
{
	int i, count;
	id group;
	id cell;
	char buf[31];
	
	count = [target count];
	for ( i=0; i<count; i++ ) {
		group = [target objectAt:i];
		[matrix addRow];
		cell = [matrix cellAt:[matrix cellCount]-1 :0];
		[cell initTextCell:[group groupName]];
		[[cell setLoaded:YES] setLeaf:YES];
	}
	
	sprintf ( buf, "Contains %d groups", count );
	[countField setStringValue:buf];
	return ( count );
}



@end
