2003-05-06 21:23:57 +00:00
|
|
|
/*
|
|
|
|
GNUstep ProjectCenter - http://www.gnustep.org
|
|
|
|
|
|
|
|
Copyright (C) 2001 Free Software Foundation
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
Authors: Philippe C.D. Robert <probert@siggraph.org>
|
|
|
|
Serg Stoyan <stoyan@on.com.ua>
|
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"
|
2004-06-11 13:43:02 +00:00
|
|
|
#include "PCInfoController.h"
|
|
|
|
#include "PCPrefController.h"
|
|
|
|
#include "PCLogController.h"
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
#include <ProjectCenter/ProjectCenter.h>
|
|
|
|
|
|
|
|
@implementation PCAppController
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//==== Intialization & deallocation
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
infoController = [[PCInfoController alloc] init];
|
2004-06-11 13:43:02 +00:00
|
|
|
prefController = [PCPrefController sharedPCPreferences];
|
|
|
|
logController = [PCLogController sharedLogController];
|
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
projectManager = [[PCProjectManager alloc] init];
|
|
|
|
[projectManager setDelegate:self];
|
2004-06-11 13:43:02 +00:00
|
|
|
[projectManager setPrefController:prefController];
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
2003-07-04 07:43:33 +00:00
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
- (void)awakeFromNib
|
2003-08-01 14:32:31 +00:00
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
[menuController setAppController:self];
|
|
|
|
[menuController setProjectManager:projectManager];
|
2003-08-01 14:32:31 +00:00
|
|
|
}
|
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
//============================================================================
|
2004-06-11 13:43:02 +00:00
|
|
|
//==== Accessory methods
|
2003-05-06 21:23:57 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
- (PCProjectManager *)projectManager
|
2003-05-06 21:23:57 +00:00
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
return projectManager;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
- (PCMenuController *)menuController
|
2003-05-06 21:23:57 +00:00
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
return menuController;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2003-05-16 14:06:51 +00:00
|
|
|
- (PCInfoController *)infoController
|
|
|
|
{
|
|
|
|
return infoController;
|
|
|
|
}
|
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
- (PCPrefController *)prefController
|
|
|
|
{
|
|
|
|
return prefController;
|
|
|
|
}
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
- (PCLogController *)logController
|
2003-05-16 14:06:51 +00:00
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
return logController;
|
2003-05-16 14:06:51 +00:00
|
|
|
}
|
|
|
|
|
2003-05-06 21:23:57 +00:00
|
|
|
- (PCServer *)doServer
|
|
|
|
{
|
|
|
|
return doServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//==== Misc...
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
- (BOOL)application:(NSApplication *)application openFile:(NSString *)fileName
|
|
|
|
{
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2004-06-11 13:43:02 +00:00
|
|
|
|
|
|
|
if ([[fileName pathExtension] isEqualToString:@"pcproj"] == YES
|
|
|
|
|| [[fileName pathExtension] isEqualToString:@"project"] == YES)
|
|
|
|
{
|
|
|
|
[projectManager openProjectAt:fileName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[projectManager openFileWithEditor:fileName];
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillFinishLaunching:(NSNotification *)notification
|
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
// [bundleLoader loadBundles];
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification
|
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
NSString *connectionName = [NSString stringWithFormat:@"ProjectCenter"];
|
|
|
|
|
|
|
|
if ([[prefController objectForKey:DisplayLog] isEqualToString:@"YES"])
|
|
|
|
{
|
|
|
|
[logController showPanel];
|
|
|
|
}
|
2003-07-10 16:00:49 +00:00
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
[logController
|
|
|
|
logMessage:@"Loading additional subsystems..." withTag:INFO sender:self];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
doServer = [[PCServer alloc] init];
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
|
|
|
|
doConnection = [[NSConnection alloc] init];
|
|
|
|
[doConnection registerName:connectionName];
|
|
|
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
2004-06-11 13:43:02 +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-07-10 16:00:49 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:doServer
|
|
|
|
selector:@selector(connectionDidDie:)
|
|
|
|
name:NSConnectionDidDieNotification
|
|
|
|
object:doConnection];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
|
|
|
[doConnection setDelegate:doServer];
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName:PCAppDidInitNotification
|
|
|
|
object:nil];
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)applicationShouldTerminate:(id)sender
|
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
NSString *poq;
|
|
|
|
NSString *soq;
|
|
|
|
BOOL quit;
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-06-11 13:43:02 +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-06-11 13:43:02 +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-06-11 13:43:02 +00:00
|
|
|
// Save projects if preferences tells that
|
|
|
|
if ([soq isEqualToString:@"YES"])
|
|
|
|
{
|
|
|
|
quit = [projectManager saveAllProjects];
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
// Close all loaded projects
|
|
|
|
quit = [projectManager closeAllProjects];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
if (quit == NO)
|
2003-07-10 16:00:49 +00:00
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
return NO;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName:PCAppWillTerminateNotification
|
|
|
|
object:nil];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
return YES;
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
- (void)applicationWillTerminate:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSLog (@"--- Application WILL terminate");
|
|
|
|
if ([[[NSUserDefaults standardUserDefaults]
|
|
|
|
stringForKey:DeleteCacheWhenQuitting] isEqualToString:@"YES"])
|
|
|
|
{
|
|
|
|
[[NSFileManager defaultManager]
|
|
|
|
removeFileAtPath:[projectManager rootBuildPath]
|
|
|
|
handler:nil];
|
|
|
|
}
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
//--- Cleanup
|
|
|
|
if (doConnection)
|
2003-07-10 16:00:49 +00:00
|
|
|
{
|
2004-06-11 13:43:02 +00:00
|
|
|
[doConnection invalidate];
|
|
|
|
RELEASE(doConnection);
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
RELEASE(infoController);
|
|
|
|
RELEASE(prefController);
|
|
|
|
RELEASE(logController);
|
|
|
|
RELEASE(menuController);
|
|
|
|
RELEASE(projectManager);
|
|
|
|
|
|
|
|
RELEASE(doServer);
|
2003-05-06 21:23:57 +00:00
|
|
|
|
2004-06-11 13:43:02 +00:00
|
|
|
NSLog (@"--- Application WILL terminate.END");
|
2003-05-06 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2004-06-11 13:43:02 +00:00
|
|
|
|