/*

File IKFolderInspector.m

Release 1.2, 7 June 1994
Copyright (C) 1994 by H. Scott Roy

This code is part of IconKit, a general toolbox for drag-and-drop applications.  IconKit is free for noncommercial use, but costs money for a commercial license.  You should have received a copy of the license agreement with this file.  If not, a copy of the license and the complete source of IconKit can be obtained from the author:

		H. Scott Roy
		2573 Stowe Ct.
		Northbrook, IL  60062-8103
		iconkit@cs.stanford.edu

For your editing convenience, this file is best viewed using an editor that automatically wraps long lines, in a fixed point font at 80 columns, with tabs every 4 spaces.

*/


/* ========================================================================== */


/*

This file implements a custom inspector for an IKCell.  The inspector lets one set the editing, dragging, shelf behavior, name, and icon.

*/

#import "IKFolderInspector.h"
#import "IKFolder.h"

@implementation IKFolderInspector


/* ========================================================================== */


/*

Here are the tags used to identify all the different cells.

*/

#define NAME				0
#define ICON				1
#define OPENICON			2

#define DRAGGABLE			0
#define DRAGACCEPTING		1
#define EDITABLE			2

#define HIDDEN				0
#define LEAF				1


/* ========================================================================== */


- init
{
    char	path [MAXPATHLEN + 1];
    id		bundle;
    
    [super init];
    
    bundle = [NXBundle  bundleForClass: [IKFolder class]];
    [bundle  getPath: path  forResource: "IKFolderInspector"  ofType: "nib"];
    [NXApp  loadNibFile: path  owner: self  withNames: NO
				fromZone: [self zone]];
    
	return self;
}


/* ========================================================================== */


/*

Reset the various options as needed.

*/


- updateLook: sender
{
	const char
		* name = [[look  findCellWithTag: NAME]  stringValue],
		* icon = [[look  findCellWithTag: ICON]  stringValue],
		* openIcon = [[look  findCellWithTag: OPENICON]  stringValue];
	
	[(IKFolder *) object  setName: name];
	[object  setImage: icon ? [NXImage  findImageNamed: icon] : nil];
	[object  setAcceptingDragImage: openIcon ?
					[NXImage  findImageNamed: openIcon] : nil];
	
	[self  ok: sender];
	
	return self;
}


- updateOptions: sender
{
	[object  setEditable: [[sender  findCellWithTag: EDITABLE]  state]];
	[object  setDraggable: [[sender  findCellWithTag: DRAGGABLE]  state]];
	[object  setDragAccepting: [[sender findCellWithTag: DRAGACCEPTING] state]];
	
	[self  ok: sender];

	return self;
}


- updateBrowserOptions: sender
{
	[object  setHidden: [[sender  findCellWithTag: HIDDEN]  state]];
	[object  setLeaf: [[sender  findCellWithTag: LEAF]  state]];
	[self  ok: sender];

	return self;
}


/* ========================================================================== */


/*

The ok: method does nothing.  The revert method needs to initialize itself from the current selection.

*/


- ok: sender
{
	[self  touch: self];
	return [super  ok: sender];
}


- revert: sender
{
	const char
		* name = [object  name],
		* icon = [[object  image]  name],
		* openIcon = [[object  acceptingDragImage]  name];
	
	[[look  findCellWithTag: NAME]  setStringValue: name];
	[[look  findCellWithTag: ICON]  setStringValue: icon];
	[[look  findCellWithTag: OPENICON]  setStringValue: openIcon];
	
	[[options  findCellWithTag: EDITABLE]  setIntValue: [object  isEditable]];
	[[options  findCellWithTag: DRAGGABLE]  setIntValue: [object  isDraggable]];
	[[options  findCellWithTag: DRAGACCEPTING]  setIntValue:
			[object  isDragAccepting]];
	
	[[browserOptions  findCellWithTag: HIDDEN]  setIntValue: [object isHidden]];
	[[browserOptions  findCellWithTag: LEAF]  setIntValue: [object isLeaf]];
	
	return [super revert: sender];
}


- (BOOL) wantsButtons
{
    return NO;
}


@end
