2003-05-06 21:23:57 +00:00
|
|
|
/*
|
|
|
|
GNUstep ProjectCenter - http://www.gnustep.org
|
|
|
|
|
|
|
|
Copyright (C) 2001 Free Software Foundation
|
|
|
|
|
2003-10-13 18:13:25 +00:00
|
|
|
Author: Philippe C.D. Robert <probert@siggraph.org>
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
|
|
|
This application 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 application 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
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PCAppController.h"
|
|
|
|
#include "PCMenuController.h"
|
|
|
|
|
|
|
|
#include <ProjectCenter/ProjectCenter.h>
|
|
|
|
|
2003-07-04 07:43:33 +00:00
|
|
|
#define REL_LIB_PC @"Library/ApplicationSupport/ProjectCenter"
|
|
|
|
#define ABS_LIB_PC @"/usr/GNUstep/System/Library/ApplicationSupport/ProjectCenter"
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
@implementation PCAppController
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//==== Intialization & deallocation
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
2003-07-04 07:43:33 +00:00
|
|
|
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
|
|
|
|
NSDictionary *env = [[NSProcessInfo processInfo] environment];
|
|
|
|
NSString *prefix = [env objectForKey:@"GNUSTEP_SYSTEM_ROOT"];
|
|
|
|
NSString *_bundlePath;
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
if (prefix && ![prefix isEqualToString:@""])
|
|
|
|
{
|
|
|
|
_bundlePath = [prefix stringByAppendingPathComponent:REL_LIB_PC];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_bundlePath = [NSString stringWithString:ABS_LIB_PC];
|
|
|
|
}
|
|
|
|
|
|
|
|
[defaults setObject:_bundlePath forKey:BundlePaths];
|
|
|
|
|
|
|
|
[defaults setObject:@"/usr/bin/vim" forKey:Editor];
|
|
|
|
[defaults setObject:@"/usr/bin/gdb" forKey:PDebugger];
|
|
|
|
[defaults setObject:@"/usr/bin/gcc" forKey:Compiler];
|
|
|
|
|
|
|
|
[defaults setObject:@"YES" forKey:ExternalEditor];
|
2003-10-13 18:13:25 +00:00
|
|
|
[defaults setObject:@"YES" forKey:ExternalDebugger];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
[defaults setObject:[NSString stringWithFormat:@"%@/ProjectCenterBuildDir",NSTemporaryDirectory()] forKey:RootBuildDirectory];
|
|
|
|
|
|
|
|
[defaults setObject:@"YES" forKey:SaveOnQuit];
|
|
|
|
[defaults setObject:@"YES" forKey:PromptOnClean];
|
|
|
|
[defaults setObject:@"YES" forKey:PromptOnQuit];
|
|
|
|
[defaults setObject:@"YES" forKey:AutoSave];
|
|
|
|
[defaults setObject:@"YES" forKey:KeepBackup];
|
|
|
|
[defaults setObject:@"120" forKey:AutoSavePeriod];
|
|
|
|
[defaults setObject:@"NO" forKey:DeleteCacheWhenQuitting];
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2004-01-13 06:37:05 +00:00
|
|
|
infoController = [[PCInfoController alloc] init];
|
2003-05-06 21:23:57 +00:00
|
|
|
prefController = [[PCPrefController alloc] init];
|
2003-10-13 18:13:25 +00:00
|
|
|
finder = [[PCFindController alloc] init];
|
|
|
|
logger = [[PCLogController alloc] init];
|
2004-01-13 06:37:05 +00:00
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
projectManager = [[PCProjectManager alloc] init];
|
2004-01-13 06:37:05 +00:00
|
|
|
[projectManager setDelegate:self];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-01-13 06:37:05 +00:00
|
|
|
menuController = [[PCMenuController alloc] init];
|
2003-05-06 21:23:57 +00:00
|
|
|
[menuController setAppController:self];
|
|
|
|
[menuController setProjectManager:projectManager];
|
|
|
|
}
|
2003-07-04 07:43:33 +00:00
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//==== Delegate
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
- (id)delegate
|
|
|
|
{
|
|
|
|
return delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDelegate:(id)aDelegate
|
|
|
|
{
|
|
|
|
delegate = aDelegate;
|
|
|
|
}
|
|
|
|
|
2003-10-13 18:13:25 +00:00
|
|
|
- (BOOL)respondsToSelector:(SEL)aSelector
|
2003-05-16 14:06:51 +00:00
|
|
|
{
|
2003-10-13 18:13:25 +00:00
|
|
|
if (![super respondsToSelector:aSelector])
|
2004-04-02 15:40:43 +00:00
|
|
|
{
|
|
|
|
return [menuController respondsToSelector:aSelector];
|
|
|
|
}
|
2003-05-16 14:06:51 +00:00
|
|
|
else
|
2004-04-02 15:40:43 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2003-05-16 14:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)forwardInvocation:(NSInvocation *)anInvocation
|
|
|
|
{
|
|
|
|
SEL aSelector = [anInvocation selector];
|
|
|
|
|
2004-04-02 15:40:43 +00:00
|
|
|
if ([menuController respondsToSelector:aSelector])
|
2003-05-16 14:06:51 +00:00
|
|
|
{
|
2004-04-02 15:40:43 +00:00
|
|
|
[anInvocation invokeWithTarget:menuController];
|
2003-05-16 14:06:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-04-02 15:40:43 +00:00
|
|
|
[super forwardInvocation:anInvocation];
|
2003-05-16 14:06:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-13 18:13:25 +00:00
|
|
|
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
|
|
|
|
{
|
|
|
|
NSMethodSignature *sig;
|
|
|
|
|
|
|
|
sig = [super methodSignatureForSelector:aSelector];
|
|
|
|
if (sig == nil)
|
2004-04-02 15:40:43 +00:00
|
|
|
{
|
|
|
|
sig = [menuController methodSignatureForSelector:aSelector];
|
|
|
|
}
|
2003-10-13 18:13:25 +00:00
|
|
|
|
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
//============================================================================
|
|
|
|
//==== Bundle Management
|
|
|
|
//============================================================================
|
|
|
|
|
2003-05-16 14:06:51 +00:00
|
|
|
- (PCInfoController *)infoController
|
|
|
|
{
|
|
|
|
return infoController;
|
|
|
|
}
|
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
- (PCPrefController *)prefController
|
|
|
|
{
|
|
|
|
return prefController;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCServer *)doServer
|
|
|
|
{
|
|
|
|
return doServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCFindController *)finder
|
|
|
|
{
|
|
|
|
return finder;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCLogController *)logger
|
|
|
|
{
|
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
|
2004-04-02 15:40:43 +00:00
|
|
|
- (PCProjectManager *)projectManager
|
2003-05-06 21:23:57 +00:00
|
|
|
{
|
2004-04-02 15:40:43 +00:00
|
|
|
return projectManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCMenuController *)menuController
|
|
|
|
{
|
|
|
|
return menuController;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//==== Misc...
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
- (BOOL)application:(NSApplication *)application openFile:(NSString *)fileName
|
|
|
|
{
|
2003-11-16 22:57:50 +00:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
|
|
|
|
if ([[fileName pathExtension] isEqualToString:@"pcproj"] == YES
|
2004-01-13 06:37:05 +00:00
|
|
|
|| [[fileName pathExtension] isEqualToString:@"project"] == YES)
|
|
|
|
{
|
|
|
|
[projectManager openProjectAt:fileName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[projectManager openFileWithEditor:fileName];
|
|
|
|
}
|
2003-11-16 22:57:50 +00:00
|
|
|
|
|
|
|
return YES;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillFinishLaunching:(NSNotification *)notification
|
|
|
|
{
|
2004-04-02 15:40:43 +00:00
|
|
|
// [bundleLoader loadBundles];
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSString *h = [[NSProcessInfo processInfo] hostName];
|
|
|
|
NSString *connectionName = [NSString stringWithFormat:@"ProjectCenter:%@",h];
|
2003-10-13 18:13:25 +00:00
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
[logger logMessage:@"Loading additional subsystems..." tag:INFORMATION];
|
|
|
|
|
|
|
|
doServer = [[PCServer alloc] init];
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
|
|
|
|
doConnection = [[NSConnection alloc] init];
|
|
|
|
[doConnection registerName:connectionName];
|
|
|
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
2003-10-13 18:13:25 +00:00
|
|
|
NSRunAlertPanel(@"Warning!",@"Could not register the DO connection %@",
|
|
|
|
@"OK",nil,nil,nil,connectionName);
|
2003-05-06 21:23:57 +00:00
|
|
|
NS_ENDHANDLER
|
|
|
|
|
2003-10-13 18:13:25 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:doServer
|
|
|
|
selector:@selector(connectionDidDie:)
|
|
|
|
name:NSConnectionDidDieNotification
|
|
|
|
object:doConnection];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
[doConnection setDelegate:doServer];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:PCAppDidInitNotification object:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldTerminate:(id)sender
|
|
|
|
{
|
2004-01-13 06:37:05 +00:00
|
|
|
NSString *poq;
|
|
|
|
NSString *soq;
|
|
|
|
BOOL quit;
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-01-13 06:37:05 +00:00
|
|
|
poq = [[NSUserDefaults standardUserDefaults] objectForKey:PromptOnQuit];
|
|
|
|
soq = [[NSUserDefaults standardUserDefaults] objectForKey:SaveOnQuit];
|
|
|
|
if ([poq isEqualToString:@"YES"])
|
2003-05-06 21:23:57 +00:00
|
|
|
{
|
2004-01-13 06:37:05 +00:00
|
|
|
if (NSRunAlertPanel(@"Quit!",
|
|
|
|
@"Do you really want to quit ProjectCenter?",
|
|
|
|
@"No", @"Yes", nil))
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-01-13 06:37:05 +00:00
|
|
|
// Save projects if preferences tells that
|
|
|
|
if ([soq isEqualToString:@"YES"])
|
|
|
|
{
|
|
|
|
quit = [projectManager saveAllProjects];
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2004-01-13 06:37:05 +00:00
|
|
|
// Close all loaded projects
|
|
|
|
quit = [projectManager closeAllProjects];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-01-13 06:37:05 +00:00
|
|
|
if (quit == NO)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName:PCAppWillTerminateNotification
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
return YES;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)notification
|
|
|
|
{
|
2004-03-30 07:14:07 +00:00
|
|
|
NSLog (@"--- Application WILL terminate");
|
2003-10-13 18:13:25 +00:00
|
|
|
if ([[[NSUserDefaults standardUserDefaults]
|
|
|
|
stringForKey:DeleteCacheWhenQuitting] isEqualToString:@"YES"])
|
|
|
|
{
|
|
|
|
[[NSFileManager defaultManager]
|
|
|
|
removeFileAtPath:[projectManager rootBuildPath]
|
|
|
|
handler:nil];
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2003-10-13 18:13:25 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
|
|
|
//--- Cleanup
|
|
|
|
if (doConnection)
|
2004-01-13 06:37:05 +00:00
|
|
|
{
|
|
|
|
[doConnection invalidate];
|
|
|
|
RELEASE(doConnection);
|
|
|
|
}
|
2003-10-13 18:13:25 +00:00
|
|
|
|
|
|
|
RELEASE(prefController);
|
|
|
|
RELEASE(finder);
|
|
|
|
RELEASE(infoController);
|
|
|
|
RELEASE(logger);
|
|
|
|
RELEASE(projectManager);
|
|
|
|
RELEASE(menuController);
|
2004-01-13 06:37:05 +00:00
|
|
|
|
2003-10-13 18:13:25 +00:00
|
|
|
RELEASE(doServer);
|
2004-01-13 06:37:05 +00:00
|
|
|
|
2004-03-30 07:14:07 +00:00
|
|
|
NSLog (@"--- Application WILL terminate.END");
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|