/*

File AppDelegate.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.

*/


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


/*

The appDelegate is responsible for the high level control of the FileViewer application.  It can load a new viewer, and it can show the info panel, and that's about it.

*/

#import "AppDelegate.h"
#import "File.h"
#import "iconkit/iconkit.h"

@implementation AppDelegate


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


#define OFFSET	30
static int		viewers = 0;


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


/*

Here are the methods to unarchive new file viewers from the nib file.  The shelf and browser are set up so that double clicks open files in the workspace.  The shelf is configured to accept File objects and to send announcements to the File class about dragging events.

*/


- newViewer: sender
{
	[self  getNewViewer];
	[[fileManager  setRoot: [File  fileForPath: "/"]]  awake];
	[[shelf  cellAt: 0  : 0]  setDelegate:
				[File  fileForPath:  NXHomeDirectory()]];
	[window  makeKeyAndOrderFront: self];
	
	return self;
}


- newViewerAt: file
{
	[self  getNewViewer];
	[[fileManager  setRoot: file]  awake];
	[[shelf  cellAt: 0  : 0]  setDelegate: file];
	[[window  setTitleAsFilename: [file  path]]  makeKeyAndOrderFront: self];
	
	return self;
}


- getNewViewer
{
	NXRect
		frame;
	int
		dx = (viewers++ % 10) * OFFSET;
	
	[NXApp  loadNibSection: "IconBrowser.nib"  owner: self  withNames: NO];
	[[shelf  setClassToHold: "File"]  addListener: [File  class]];
	[shelf  setDoubleAction: @selector(openFile:)];
	[[[fileManager	browser]
					setDoubleAction: @selector(openFile:)]
					setBranchSelectionEnabled: YES];
	
	[window  getFrame: &frame];
	[window  moveTo: frame.origin.x + dx  : frame.origin.y - dx];
	
	return self;
}


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


/*

These take care of the basics.  The application creates a new viewer when it first starts out.

*/

- showInfo: sender
{
	if (infoPanel == nil)
			[NXApp  loadNibSection: "Info.nib"  owner: self  withNames: NO];
	[infoPanel  makeKeyAndOrderFront: self];
	
	return self;
}


- appDidInit: sender
{
	[self  newViewer: self];
	return self;
}


@end
