apps-projectcenter/PCLibProj/PCLibProj.m
Philippe C.D. Robert fa7bda8926 ProjectCenter now stores the project files under PROJECTNAME.pcproj to avoid
name clashes.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@12017 72102866-910b-0410-8b05-ffd578937521
2002-01-07 09:37:19 +00:00

141 lines
4.7 KiB
Objective-C

/*
GNUstep ProjectCenter - http://www.gnustep.org
Copyright (C) 2001 Free Software Foundation
Author: Philippe C.D. Robert <phr@3dkit.org>
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.
$Id$
*/
/*
Description:
PCLibProj creates new project of the type Application!
*/
#import "PCLibProj.h"
#import "PCLibProject.h"
@implementation PCLibProj
static NSString *_projTypeName = @"Library";
static PCLibProj *_creator = nil;
//----------------------------------------------------------------------------
// ProjectType
//----------------------------------------------------------------------------
+ (id)sharedCreator
{
if (!_creator) {
_creator = [[[self class] alloc] init];
}
return _creator;
}
- (Class)projectClass
{
return [PCLibProject class];
}
- (NSString *)projectTypeName
{
return _projTypeName;
}
- (NSDictionary *)typeTable
{
NSString *_path = [[NSBundle bundleForClass:[self class]] pathForResource:@"Info" ofType:@"table"];
return [NSDictionary dictionaryWithContentsOfFile:_path];
}
- (PCProject *)createProjectAt:(NSString *)path
{
PCLibProject *project = nil;
NSFileManager *fm = [NSFileManager defaultManager];
NSAssert(path,@"No valid project path provided!");
if ([fm createDirectoryAtPath:path attributes:nil]) {
NSString *_file;
NSString *_resourcePath;
NSMutableDictionary *dict;
NSString *projectFile;
project = [[[PCLibProject alloc] init] autorelease];
_file = [[NSBundle bundleForClass:[self class]] pathForResource:@"PC" ofType:@"proj"];
dict = [NSMutableDictionary dictionaryWithContentsOfFile:_file];
// Customise the project
[dict setObject:[path lastPathComponent] forKey:PCProjectName];
[dict setObject:[project principalClass] forKey:PCProjType];
// Save the project to disc
projectFile = [NSString stringWithString:[path lastPathComponent]];
projectFile = [projectFile stringByAppendingPathExtension:@"pcproj"];
[dict writeToFile:[path stringByAppendingPathComponent:projectFile]
atomically:YES];
// Copy the project files to the provided path
_file = [[NSBundle bundleForClass:[self class]] pathForResource:@"GNUmakefile" ofType:@"postamble"];
[fm copyPath:_file toPath:[path stringByAppendingPathComponent:@"GNUmakefile.postamble"] handler:nil];
_file = [[NSBundle bundleForClass:[self class]] pathForResource:@"GNUmakefile" ofType:@"preamble"];
[fm copyPath:_file toPath:[path stringByAppendingPathComponent:@"GNUmakefile.preamble"] handler:nil];
_file = [[NSBundle bundleForClass:[self class]] pathForResource:@"main" ofType:@"m"];
[fm copyPath:_file toPath:[path stringByAppendingPathComponent:@"main.m"] handler:nil];
// Resources
/*
_resourcePath = [path stringByAppendingPathComponent:@"English.lproj"];
[fm createDirectoryAtPath:_resourcePath attributes:nil];
*/
[fm createDirectoryAtPath:[path stringByAppendingPathComponent:@"Documentation"] attributes:nil];
_file = [[NSBundle bundleForClass:[self class]] pathForResource:@"Version" ofType:@""];
[fm copyPath:_file toPath:[path stringByAppendingPathComponent:@"Version"] handler:nil];
// The path cannot be in the PC.project file!
[project setProjectPath:path];
// Set the new dictionary - this causes the GNUmakefile to be written to disc
if(![project assignProjectDict:dict]) {
NSRunAlertPanel(@"Attention!",@"Could not load %@!",@"OK",nil,nil,path);
return nil;
}
}
return project;
}
- (PCProject *)openProjectAt:(NSString *)path
{
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
if ([[dict objectForKey:PCProjectBuilderClass] isEqualToString:@"PCLibProj"]) {
return [[[PCLibProject alloc] initWithProjectDictionary:dict path:[path stringByDeletingLastPathComponent]] autorelease];
}
return nil;
}
@end