2001-11-05 19:58:25 +00:00
|
|
|
/*
|
2002-07-06 03:00:28 +00:00
|
|
|
Controller.m
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2001-11-12 14:15:20 +00:00
|
|
|
Application controller class
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2001-11-12 14:15:20 +00:00
|
|
|
Copyright (C) 2001 Dusk to Dawn Computing, Inc.
|
|
|
|
|
|
|
|
Author: Jeff Teunissen <deek@d2dc.net>
|
|
|
|
Date: 5 Nov 2001
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2001-11-11 20:54:59 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
2001-11-05 19:58:25 +00:00
|
|
|
*/
|
2001-11-12 14:15:20 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "Config.h"
|
|
|
|
#endif
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2003-05-06 21:52:58 +00:00
|
|
|
#include <Foundation/NSDebug.h>
|
2002-05-26 11:24:00 +00:00
|
|
|
|
2003-05-06 21:52:58 +00:00
|
|
|
#include <AppKit/NSApplication.h>
|
|
|
|
#include <AppKit/NSNibLoading.h>
|
|
|
|
#include <AppKit/NSMenu.h>
|
|
|
|
#include <AppKit/NSWindow.h>
|
2002-05-26 11:24:00 +00:00
|
|
|
|
2003-05-06 21:52:58 +00:00
|
|
|
#include "Controller.h"
|
|
|
|
#include "PrefsController.h"
|
2001-11-05 19:58:25 +00:00
|
|
|
|
|
|
|
@implementation Controller
|
|
|
|
|
|
|
|
- (BOOL) application: (NSApplication *) app openFile: (NSString *) filename;
|
|
|
|
{
|
2002-07-06 03:00:28 +00:00
|
|
|
if (![[filename pathExtension] isEqualToString: @"forge"]) {
|
|
|
|
NSLog (@"File \"%@\" is not a project file!", filename);
|
|
|
|
return NO;
|
|
|
|
}
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
fileMode = COpenMode;
|
|
|
|
fileName = filename;
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
if (![NSBundle loadNibNamed: @"Project" owner: self]) {
|
|
|
|
NSLog (@"Could not load project manager for file \"%@\"", filename);
|
|
|
|
fileMode = CNoMode;
|
|
|
|
fileName = nil;
|
|
|
|
return NO;
|
|
|
|
}
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
fileMode = CNoMode;
|
|
|
|
fileName = nil;
|
|
|
|
return YES;
|
2001-11-05 19:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) applicationShouldTerminate: (NSApplication *) app;
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication *) app;
|
|
|
|
{
|
2002-05-29 11:21:25 +00:00
|
|
|
return NO;
|
2001-11-05 19:58:25 +00:00
|
|
|
}
|
|
|
|
|
2002-05-29 07:13:42 +00:00
|
|
|
/******
|
2001-11-05 19:58:25 +00:00
|
|
|
Action methods
|
2002-05-29 07:13:42 +00:00
|
|
|
******/
|
|
|
|
|
|
|
|
- (void) showPreferencesPanel: (id) sender;
|
|
|
|
{
|
|
|
|
NSDebugLog (@"Showing Preferences panel...");
|
|
|
|
[prefsController orderFrontPreferencesPanel: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Project management
|
2001-11-05 19:58:25 +00:00
|
|
|
*/
|
2002-05-29 07:13:42 +00:00
|
|
|
- (void) newProject: (id) sender;
|
2001-11-05 19:58:25 +00:00
|
|
|
{
|
2002-05-29 11:21:25 +00:00
|
|
|
fileMode = CCreateMode;
|
|
|
|
|
|
|
|
if (![NSBundle loadNibNamed: @"Project" owner: self])
|
|
|
|
NSLog (@"Could not create new Project window!");
|
|
|
|
|
|
|
|
fileMode = CNoMode;
|
|
|
|
return;
|
2001-11-05 19:58:25 +00:00
|
|
|
}
|
|
|
|
|
2002-05-29 07:13:42 +00:00
|
|
|
- (void) openProject: (id) sender;
|
2001-11-05 19:58:25 +00:00
|
|
|
{
|
2002-05-29 11:21:25 +00:00
|
|
|
fileMode = COpenMode;
|
|
|
|
|
|
|
|
if (![NSBundle loadNibNamed: @"Project" owner: self])
|
|
|
|
NSLog (@"Could not create new Project window!");
|
|
|
|
|
|
|
|
fileMode = CNoMode;
|
|
|
|
return;
|
2001-11-05 19:58:25 +00:00
|
|
|
}
|
|
|
|
|
2002-05-29 07:13:42 +00:00
|
|
|
/******
|
2001-11-05 19:58:25 +00:00
|
|
|
Notifications
|
2002-05-29 07:13:42 +00:00
|
|
|
******/
|
2001-11-05 19:58:25 +00:00
|
|
|
|
2001-11-06 13:20:23 +00:00
|
|
|
/*
|
|
|
|
applicationDidFinishLaunching:
|
|
|
|
|
|
|
|
Sent when the app has finished starting up
|
|
|
|
*/
|
2001-11-05 19:58:25 +00:00
|
|
|
- (void) applicationDidFinishLaunching: (NSNotification *) not;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-11-06 13:20:23 +00:00
|
|
|
/*
|
|
|
|
applicationWillFinishLaunching:
|
|
|
|
|
|
|
|
Sent when the app is just about to complete its startup
|
|
|
|
*/
|
2001-11-05 19:58:25 +00:00
|
|
|
- (void) applicationWillFinishLaunching: (NSNotification *) not;
|
|
|
|
{
|
2002-01-14 15:06:00 +00:00
|
|
|
NSMenu *menu = [NSApp mainMenu];
|
2001-11-06 13:20:23 +00:00
|
|
|
|
2001-11-05 19:58:25 +00:00
|
|
|
/*
|
|
|
|
Windows
|
|
|
|
*/
|
2002-01-14 15:06:00 +00:00
|
|
|
NSDebugLog (@"Windows");
|
2002-05-26 11:24:00 +00:00
|
|
|
[NSApp setWindowsMenu: [[menu itemWithTitle: _(@"Windows")] submenu]];
|
2001-11-05 19:58:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Services
|
|
|
|
*/
|
2002-01-14 15:06:00 +00:00
|
|
|
NSDebugLog (@"Services");
|
2002-05-26 11:24:00 +00:00
|
|
|
[NSApp setServicesMenu: [[menu itemWithTitle: _(@"Services")] submenu]];
|
2002-07-06 03:00:28 +00:00
|
|
|
|
|
|
|
[bundleController loadBundles];
|
2001-11-05 19:58:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-06 13:20:23 +00:00
|
|
|
/*
|
|
|
|
applicationWillTerminate:
|
|
|
|
|
2002-01-14 15:06:00 +00:00
|
|
|
We're about to die, but AppKit is giving us a chance to clean up
|
2001-11-06 13:20:23 +00:00
|
|
|
*/
|
2001-11-05 19:58:25 +00:00
|
|
|
- (void) applicationWillTerminate: (NSNotification *) not;
|
|
|
|
{
|
|
|
|
}
|
2001-11-22 07:28:01 +00:00
|
|
|
|
2002-05-26 11:24:00 +00:00
|
|
|
/******
|
|
|
|
Nib awakening
|
|
|
|
******/
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2002-05-29 11:21:25 +00:00
|
|
|
fileMode = CNoMode;
|
2002-07-06 03:00:28 +00:00
|
|
|
// [window setFrameAutosaveName: @"Project View"];
|
|
|
|
// [window setFrameUsingName: @"Project View"];
|
2002-05-26 11:24:00 +00:00
|
|
|
}
|
|
|
|
|
2001-11-22 07:28:01 +00:00
|
|
|
/******
|
|
|
|
Bundle Controller delegate methods
|
|
|
|
******/
|
|
|
|
|
|
|
|
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle
|
|
|
|
{
|
2001-11-28 23:46:37 +00:00
|
|
|
NSDictionary *info = nil;
|
|
|
|
|
2002-05-29 11:21:25 +00:00
|
|
|
/*
|
|
|
|
Let's get paranoid about stuff we load... :)
|
|
|
|
*/
|
2001-11-22 07:28:01 +00:00
|
|
|
if (!aBundle) {
|
|
|
|
NSLog (@"Controller -bundleController: sent nil bundle");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-05-29 11:21:25 +00:00
|
|
|
if (!(info = [aBundle infoDictionary])) {
|
|
|
|
NSLog (@"Bundle %@ has no info dictionary!", aBundle);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-22 07:28:01 +00:00
|
|
|
|
2002-05-29 11:21:25 +00:00
|
|
|
if (![info objectForKey: @"NSExecutable"]) {
|
|
|
|
NSLog (@"Bundle %@ has no executable!", aBundle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (![aBundle principalClass]) {
|
2001-11-28 23:46:37 +00:00
|
|
|
NSLog (@"Bundle `%@' has no principal class!", [[info objectForKey: @"NSExecutable"] lastPathComponent]);
|
2001-11-22 07:28:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-05-29 11:21:25 +00:00
|
|
|
|
2001-11-28 23:46:37 +00:00
|
|
|
if (![[aBundle principalClass] conformsToProtocol: @protocol(ForgeBundle)]) {
|
|
|
|
NSLog (@"Bundle %@'s principal class does not conform to the ForgeBundle protocol.", [[info objectForKey: @"NSExecutable"] lastPathComponent]);
|
|
|
|
return;
|
2002-05-29 11:21:25 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 04:42:12 +00:00
|
|
|
[(id <ForgeBundle>) [[aBundle principalClass] alloc] initWithOwner: self];
|
2001-11-22 07:28:01 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 11:24:00 +00:00
|
|
|
- (PrefsController *) prefsController;
|
|
|
|
{
|
|
|
|
return prefsController;
|
|
|
|
}
|
|
|
|
|
2001-11-22 07:28:01 +00:00
|
|
|
- (BOOL) registerPrefsController: (id <PrefsViewController>) aPrefsController
|
|
|
|
{
|
|
|
|
if (!aPrefsController)
|
|
|
|
return NO;
|
|
|
|
|
2002-05-26 11:24:00 +00:00
|
|
|
[prefsController addPrefsViewController: aPrefsController];
|
2001-11-22 07:28:01 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2002-05-29 11:21:25 +00:00
|
|
|
- (CMode) fileMode
|
|
|
|
{
|
|
|
|
return fileMode;
|
|
|
|
}
|
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
- (NSString *) fileName
|
|
|
|
{
|
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
2001-11-22 07:28:01 +00:00
|
|
|
@end
|