/*
   Edit.m
   
   Copyright (C) 1996 Free Software Foundation, Inc.
   
   Author:  Felipe A. Rodriguez <far@pcmagic.net>
   Date:	July 1998
   
   This file is part of the mySTEP Library and is provided
   under the terms of the GNU Library General Public License.
*/

#import <AppKit/AppKit.h>
#import "Controller.h"
#import "Document.h"


@implementation Controller (AppDelegate)

- (void) createMenu
{
NSMenu *menu;
NSMenu *info;
NSMenu *file;
NSMenu *edit;
NSMenu *find;
NSMenu *util;
NSMenu *services;
NSMenu *windows;
SEL na = @selector(method:);

	menu = [[NSMenu alloc] initWithTitle:@"Edit"];		// Create the app menu
	[menu addItemWithTitle:@"Info" action:na keyEquivalent:@""];
	[menu addItemWithTitle:@"File" action:na keyEquivalent:@""];
	[menu addItemWithTitle:@"Edit" action:na keyEquivalent:@""];
	[menu addItemWithTitle:@"Format" action:na keyEquivalent:@""];
	[menu addItemWithTitle:@"Utilities" action:na keyEquivalent:@""];
	[menu addItemWithTitle:@"Windows" action:na keyEquivalent:@""];
	[menu addItemWithTitle:@"Print" action:na keyEquivalent:@"p"];
	[menu addItemWithTitle:@"Services" action:na keyEquivalent:@""];
	[menu addItemWithTitle:@"Hide" action:@selector(hide:) keyEquivalent:@"h"];
	[menu addItemWithTitle:@"Quit" action:@selector(terminate:)
		  keyEquivalent:@"q"];

	info = [NSMenu new];								// Create info submenu
	[menu setSubmenu:info forItem:[menu itemWithTitle:@"Info"]];
	[info addItemWithTitle:@"Info Panel..." action:na keyEquivalent:@""];
	[info addItemWithTitle:@"Preferences..." action:na keyEquivalent:@""];
	[info addItemWithTitle:@"Help" action:na keyEquivalent:@"?"];

	file = [NSMenu new];								// Create file submenu
	[file addItemWithTitle:@"Open..." action:@selector(open:) 
		  keyEquivalent:@"o"];
	[file addItemWithTitle:@"New" action:@selector(createNew:) 
		  keyEquivalent:@"n"];
	[file addItemWithTitle:@"Save" action:@selector(save:) keyEquivalent:@"s"];
	[file addItemWithTitle:@"Save As..." action:@selector(saveAs:) 
		  keyEquivalent:@"S"];
	[file addItemWithTitle:@"Save All" action:@selector(saveAll:) 
		  keyEquivalent:@""];
	[file addItemWithTitle:@"Revert to Saved" action:@selector(revert:) 
		  keyEquivalent:@"u"];
	[file addItemWithTitle:@"Close" action:na keyEquivalent:@""];
	[menu setSubmenu:file forItem:[menu itemWithTitle:@"File"]];

	edit = [NSMenu new];								// Create edit submenu
	[edit addItemWithTitle:@"Cut" action:@selector(cut:) keyEquivalent:@"x"];
	[edit addItemWithTitle:@"Copy" action:@selector(copy:) keyEquivalent:@"c"];
	[edit addItemWithTitle:@"Paste"
		  action:@selector(paste:) 
		  keyEquivalent:@"v"];
	[edit addItemWithTitle:@"Delete"
		  action:@selector(delete:) 
		  keyEquivalent:@""];
	[edit addItemWithTitle:@"Undelete" action:NULL keyEquivalent:@""];
	[edit addItemWithTitle:@"Find" action:na keyEquivalent:@""];
	[edit addItemWithTitle:@"Select All"
		  action:@selector(selectAll:) 
		  keyEquivalent:@"a"];
	[menu setSubmenu:edit forItem:[menu itemWithTitle:@"Edit"]];

	find = [NSMenu new];
	[find addItemWithTitle:@"Find Panel..." 
		  action:@selector(orderFrontFindPanel:) 
		  keyEquivalent:@"f"];
	[find addItemWithTitle:@"Find Next" 
		  action:@selector(findNext:) 
		  keyEquivalent:@"g"];
	[find addItemWithTitle:@"Find Previous" 
		  action:@selector(findPrevious:)  
		  keyEquivalent:@"d"];
	[find addItemWithTitle:@"Enter Selection"
		  action:@selector(enterSelection:)
		  keyEquivalent:@"e"];
	[find addItemWithTitle:@"Jump to Selection" action:na keyEquivalent:@"j"];
	[find addItemWithTitle:@"Line Range..." action:na keyEquivalent:@"l"];
	[edit setSubmenu:find forItem:[edit itemWithTitle:@"Find"]];

	util = [NSMenu new];								// Create util submenu
	[util addItemWithTitle:@"Inspector" action:@selector(showInspectorPanel:)
		  keyEquivalent:@""];
	[menu setSubmenu:util forItem:[menu itemWithTitle:@"Utilities"]];

	windows = [NSMenu new];								// Create windows sub
	[windows addItemWithTitle:@"Arrange" action:@selector(arrangeInFront:) 
										 keyEquivalent:@""];
	[windows addItemWithTitle:@"Miniaturize" action:na keyEquivalent:@"m"];
	[windows addItemWithTitle:@"Close" action:na keyEquivalent:@"w"];
	[menu setSubmenu:windows forItem:[menu itemWithTitle:@"Windows"]];

	services = [NSMenu new];							// Create svcs submenu
	[menu setSubmenu:services forItem:[menu itemWithTitle:@"Services"]];

	[NSApp setMainMenu:menu];								// set main menu
	[NSApp setServicesMenu: services];
}

- (id) init
{
	[[NSApplication sharedApplication] setDelegate: self];	
	[self createMenu];
}

@end


int
main(int argc, char **argv, char** env)
{
    return NSApplicationMain(argc, argv);
}
