1/* main.m: Main Body of GNUstep Ink demo application
2
3   Copyright (C) 2000 Free Software Foundation, Inc.
4
5   Adaptation:  Marko Riedel <mriedel@neuearbeit.de>
6   Date: May 2002, June 2007
7
8   Author:  Fred Kiefer <fredkiefer@gmx.de>
9   Date: 2000
10
11   This file is part of GNUstep.
12
13   This program is free software; you can redistribute it and/or modify
14   it under the terms of the GNU General Public License as published by
15   the Free Software Foundation; either version 2 of the License, or
16   (at your option) any later version.
17
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program; if not, write to the Free Software
25   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27#import <Foundation/Foundation.h>
28#import <AppKit/AppKit.h>
29
30#import "Document.h"
31
32
33@interface Controller : NSObject
34
35- (void) applicationWillFinishLaunching: (NSNotification *)not;
36- (void) applicationDidFinishLaunching: (NSNotification *)not;
37@end
38
39@implementation Controller : NSObject
40
41- (void) applicationWillFinishLaunching: (NSNotification *)not
42{
43  CREATE_AUTORELEASE_POOL(pool);
44  NSMenu *menu;
45  NSMenu *info;
46  NSMenu *action;
47  NSMenu *file;
48  NSMenu *services;
49  NSMenu *windows;
50
51  //	Create the app menu
52  menu = [NSMenu new];
53
54  [menu addItemWithTitle: @"Info"
55		  action: NULL
56	   keyEquivalent: @""];
57
58  [menu addItemWithTitle: @"File"
59		  action: NULL
60	   keyEquivalent: @""];
61
62  [menu addItemWithTitle: @"Action"
63		  action: NULL
64	   keyEquivalent: @""];
65
66  [menu addItemWithTitle: @"Windows"
67		  action: NULL
68	   keyEquivalent: @""];
69
70  [menu addItemWithTitle: @"Services"
71		  action: NULL
72	   keyEquivalent: @""];
73
74  [menu addItemWithTitle: @"Hide"
75		  action: @selector(hide:)
76	   keyEquivalent: @"h"];
77
78  [menu addItemWithTitle: @"Quit"
79		  action: @selector(terminate:)
80	   keyEquivalent: @"q"];
81
82  // Create the info submenu
83  info = [NSMenu new];
84  [menu setSubmenu: info
85	   forItem: [menu itemWithTitle: @"Info"]];
86
87  [info addItemWithTitle: @"Info Panel..."
88	          action: @selector(orderFrontStandardInfoPanel:)
89	   keyEquivalent: @""];
90/*
91  [info addItemWithTitle: @"Preferences..."
92		  action: NULL
93	   keyEquivalent: @""];
94*/
95  [info addItemWithTitle: @"Help"
96		  action: @selector (orderFrontHelpPanel:)
97	   keyEquivalent: @"?"];
98  RELEASE(info);
99
100  // Create the action submenu
101  action = [[Document actionMenu] copy];
102  [menu setSubmenu: action
103	   forItem: [menu itemWithTitle: @"Action"]];
104
105  // Create the file submenu
106  file = [NSMenu new];
107  [menu setSubmenu: file
108	   forItem: [menu itemWithTitle: @"File"]];
109
110  [file addItemWithTitle: @"Open Document"
111		  action: @selector(openDocument:)
112	   keyEquivalent: @"o"];
113
114  [file addItemWithTitle: @"Save"
115	          action: @selector(saveDocument:)
116	   keyEquivalent: @"s"];
117
118  [file addItemWithTitle: @"Save To..."
119	          action: @selector(saveDocumentTo:)
120	   keyEquivalent: @"t"];
121
122  [file addItemWithTitle: @"Save All"
123	action: @selector(saveDocumentAll:)
124	   keyEquivalent: @""];
125
126  [file addItemWithTitle: @"Revert to Saved"
127		  action: @selector(revertDocumentToSaved:)
128	   keyEquivalent: @"u"];
129
130  [file addItemWithTitle: @"Close"
131		  action: @selector(close)
132	   keyEquivalent: @""];
133
134  RELEASE(file);
135
136  [menu setSubmenu: [[Document actionMenu] copy]
137	forItem: [menu itemWithTag: MENU_ACTION]];
138
139  // Create the windows submenu
140  windows = [NSMenu new];
141  [menu setSubmenu: windows
142	   forItem: [menu itemWithTitle: @"Windows"]];
143
144  [windows addItemWithTitle: @"Arrange"
145		     action: @selector(arrangeInFront:)
146	      keyEquivalent: @""];
147
148  [windows addItemWithTitle: @"Miniaturize"
149		     action: @selector(performMiniaturize:)
150	      keyEquivalent: @"m"];
151
152  [windows addItemWithTitle: @"Close"
153		     action: @selector(performClose:)
154	      keyEquivalent: @"w"];
155
156  [NSApp setWindowsMenu: windows];
157  RELEASE(windows);
158
159  // Create the service submenu
160  services = [NSMenu new];
161  [menu setSubmenu: services
162	   forItem: [menu itemWithTitle: @"Services"]];
163
164  [NSApp setServicesMenu: services];
165  RELEASE(services);
166
167  [NSApp setMainMenu: menu];
168  RELEASE(menu);
169
170  RELEASE(pool);
171}
172
173- (void) applicationDidFinishLaunching: (NSNotification *)not;
174{
175  NSDocumentController *dc =
176    [NSDocumentController sharedDocumentController];
177  NSFileManager *fm;
178  NSArray *procArgs;
179  int arg;
180  // Make the DocumentController the delegate of the application.
181  [NSApp setDelegate: dc];
182
183  fm = [NSFileManager defaultManager];
184  procArgs = [[NSProcessInfo processInfo] arguments];
185
186  for(arg=1; arg<[procArgs count]; arg++){  // skip program name
187    NSString *docFile = [procArgs objectAtIndex:arg];
188
189    if([fm isReadableFileAtPath:docFile]==NO){
190	NSLog(@"couldn't open %@ for reading", docFile);
191    }
192    else{
193	NSArray *comps = [docFile pathComponents];
194	if([[comps objectAtIndex:0] isEqualToString:@"/"]==NO){
195	    docFile =
196		[NSString stringWithFormat:@"%@/%@",
197			  [fm currentDirectoryPath], docFile];
198	}
199
200	[dc openDocumentWithContentsOfFile:docFile display:YES];
201    }
202  }
203}
204
205@end
206
207int main(int argc, const char **argv, char** env)
208{
209  [NSApplication sharedApplication];
210  [NSApp setDelegate: [Controller new]];
211
212  return NSApplicationMain (argc, argv);
213}
214