* Framework/PCProject.m

* Framework/PCProjectManager.m
	* Headers/ProjectCenter/PCProjectManager.h
	* PCAppController.m: Correct issues with project bundle loading.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28369 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2009-06-23 22:21:10 +00:00
parent 6e95a9a1e5
commit 2fc703c5de
5 changed files with 144 additions and 147 deletions

View file

@ -1,3 +1,10 @@
2009-06-23 18:22-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Framework/PCProject.m
* Framework/PCProjectManager.m
* Headers/ProjectCenter/PCProjectManager.h
* PCAppController.m: Correct issues with project bundle loading.
2009-05-19 17:13-EDT Gregory John Casamento <greg.casamento@gmail.com> 2009-05-19 17:13-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Resources/Info-gnustep.plist: Added PCProjectFileType to the * Resources/Info-gnustep.plist: Added PCProjectFileType to the

View file

@ -84,54 +84,44 @@ NSString
return self; return self;
} }
- (PCProject *)openWithWrapperAt:(NSString *)path - (PCProject *)openWithWrapperAt:(NSString *)aPath
{ {
NSString *aPath = path; BOOL isDir = NO;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath: aPath
if([[aPath lastPathComponent] isEqual: @"PC.project"]) isDirectory: &isDir];
if(isDir && exists)
{ {
NSString *newPath = [aPath stringByDeletingLastPathComponent]; projectFileWrapper = [[NSFileWrapper alloc] initWithPath: aPath];
if([[[newPath lastPathComponent] pathExtension] if(projectFileWrapper != nil)
isEqual: @"pcproj"] == NO)
{ {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile: aPath]; NSDictionary *wrappers = [projectFileWrapper fileWrappers];
NSData *data = [[wrappers objectForKey: @"PC.project"] regularFileContents];
NSData *userData = [[wrappers objectForKey: [NSUserName() stringByAppendingPathExtension: @"project"]]
regularFileContents];
NSMutableDictionary *dict = [[[[NSString alloc] initWithData: data
encoding: NSASCIIStringEncoding]
propertyList] mutableCopy];
NSDictionary *udict = [[[NSString alloc] initWithData: userData
encoding: NSASCIIStringEncoding]
propertyList];
projectFileWrapper = [[NSFileWrapper alloc] [dict addEntriesFromDictionary: udict];
initDirectoryWithFileWrappers: [self assignProjectDict:dict atPath: aPath];
[NSMutableDictionary dictionaryWithCapacity: 3]];
[projectFileWrapper addRegularFileWithContents:
[NSData dataWithBytes: [[dict description] cString]
length: [[dict description] length]]
preferredFilename: @"PC.project"];
[self assignProjectDict: dict
atPath: path];
return self;
}
else
{
aPath = newPath;
} }
} }
else
projectFileWrapper = [[NSFileWrapper alloc] initWithPath: aPath];
if(projectFileWrapper != nil)
{ {
NSDictionary *wrappers = [projectFileWrapper fileWrappers]; NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile: aPath];
NSData *data = [[wrappers objectForKey: @"PC.project"] regularFileContents];
NSData *userData = [[wrappers objectForKey: [NSUserName() stringByAppendingPathExtension: @"project"]]
regularFileContents];
NSMutableDictionary *dict = [[[[NSString alloc] initWithData: data
encoding: NSASCIIStringEncoding]
propertyList] mutableCopy];
NSDictionary *udict = [[[NSString alloc] initWithData: userData
encoding: NSASCIIStringEncoding]
propertyList];
[dict addEntriesFromDictionary: udict]; projectFileWrapper = [[NSFileWrapper alloc]
[self assignProjectDict:dict atPath: aPath]; initDirectoryWithFileWrappers:
[NSMutableDictionary dictionaryWithCapacity: 3]];
return self; [projectFileWrapper addRegularFileWithContents:
[NSData dataWithBytes: [[dict description] cString]
length: [[dict description] length]]
preferredFilename: @"PC.project"];
[self assignProjectDict: dict
atPath: aPath];
} }
return self; return self;
@ -1560,7 +1550,7 @@ NSString
spFile = [spFile stringByAppendingPathComponent: @"PC.project"]; spFile = [spFile stringByAppendingPathComponent: @"PC.project"];
/* PCLogInfo(self, @"Not found! Load subproject: %@ at path: %@", /* PCLogInfo(self, @"Not found! Load subproject: %@ at path: %@",
name, spFile);*/ name, spFile);*/
sp = [projectManager loadProjectAt:spFile]; sp = [projectManager openProjectAt:spFile makeActive:NO];
if (sp) if (sp)
{ {
[sp setIsSubproject:YES]; [sp setIsSubproject:YES];

View file

@ -417,6 +417,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
// ==== Project actions // ==== Project actions
// ============================================================================ // ============================================================================
- (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict - (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict
atPath:(NSString *)aPath atPath:(NSString *)aPath
{ {
@ -432,7 +433,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
NSString *_2file = nil; NSString *_2file = nil;
NSString *_resFile = nil; NSString *_resFile = nil;
unsigned i = 0; unsigned i = 0;
PCProject<ProjectType> *project = nil; PCProject *project = nil;
NSMutableArray *otherResArray = nil; NSMutableArray *otherResArray = nil;
NSString *plistFile = nil; NSString *plistFile = nil;
@ -539,94 +540,88 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
return project; return project;
} }
- (PCProject *)loadProjectAt:(NSString *)aPath - (PCProject *)openProjectAt:(NSString *)aPath makeActive: (BOOL)flag
{ {
NSMutableDictionary *projectFile = nil;
NSString *projectTypeName = nil;
NSString *projectClassName = nil;
PCProject<ProjectType> *project = nil;
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile: aPath];
if(projectFile == nil)
{
NSString *altPath = [[[aPath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]
stringByAppendingPathComponent: @"PC.project"];
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:altPath];
}
// For compatibility with 0.3.x projects
project = [self convertLegacyProject:projectFile atPath:aPath];
if (project)
{// Project was converted and created PC*Project with alloc&init
aPath = [[aPath stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"PC.project"];
}
else
{// No conversion were taken
projectTypeName = [projectFile objectForKey:PCProjectType];
projectClassName = [projectTypes objectForKey:projectTypeName];
if (projectClassName == nil)
{
NSRunAlertPanel(@"Open Project",
@"Project type '%@' is not supported!\n"
@"Report the bug, please!",
@"OK", nil, nil, projectTypeName);
return nil;
}
project = [bundleManager objectForClassName:projectClassName
bundleType:@"project"
protocol:@protocol(ProjectType)];
}
if (!project || ![project openWithWrapperAt:aPath])
{
NSRunAlertPanel(@"Open Project",
@"Unable to open project '%@'.\nReport bug, please!",
@"OK",nil,nil,aPath);
return nil;
}
PCLogStatus(self, @"Project %@ loaded as %@",
[project projectName], [project projectTypeName]);
// Started only if there's not save timer yet
[self startSaveTimer];
[project validateProjectDict];
return project;
}
- (BOOL)openProjectAt:(NSString *)aPath
{
NSDictionary *pDict = [NSDictionary dictionaryWithContentsOfFile:aPath];
NSString *projectName = nil;
PCProject *project = nil; PCProject *project = nil;
NSDictionary *wap = nil; NSDictionary *wap = nil;
BOOL isDir = NO;
projectName = [pDict objectForKey:PCProjectName]; if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) == nil)
if ((project = [loadedProjects objectForKey:projectName]) != nil)
{ {
[[project projectWindow] makeKeyAndOrderFront:self]; NSMutableDictionary *projectFile = nil;
return YES; NSString *projectTypeName = nil;
} NSString *projectClassName = nil;
BOOL isDir = NO;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:aPath
isDirectory: &isDir];
if (!exists)
{
return nil;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:aPath if (!isDir)
isDirectory:&isDir] && !isDir) {
{ projectFile = [NSMutableDictionary dictionaryWithContentsOfFile: aPath];
project = [self loadProjectAt:aPath]; }
else
{
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile: [aPath stringByAppendingPathComponent: @"PC.project"]];
}
if(projectFile == nil)
{
return nil;
}
// For compatibility with 0.3.x projects
project = [self convertLegacyProject: projectFile atPath: aPath];
if (project)
{// Project was converted and created PC*Project with alloc&init
aPath = [[aPath stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"PC.project"];
}
else
{// No conversion were taken
projectTypeName = [projectFile objectForKey:PCProjectType];
projectClassName = [projectTypes objectForKey:projectTypeName];
if (projectClassName == nil)
{
NSRunAlertPanel(@"Open Project",
@"Project type '%@' is not supported!\n"
@"Report the bug, please!",
@"OK", nil, nil, projectTypeName);
return nil;
}
}
project = [bundleManager objectForClassName:projectClassName
bundleType:@"project"
protocol:@protocol(ProjectType)];
if (!project || ![project openWithWrapperAt:aPath])
{
NSRunAlertPanel(@"Open Project",
@"Unable to open project '%@'.\nReport bug, please!",
@"OK",nil,nil,aPath);
return nil;
}
PCLogStatus(self, @"Project %@ loaded as %@",
[project projectName], [project projectTypeName]);
// Started only if there's not save timer yet
[self startSaveTimer];
[project validateProjectDict];
if (!project) if (!project)
{ {
return NO; return nil;
} }
[loadedProjects setObject:project forKey:projectName]; [loadedProjects setObject:project forKey: [project projectPath]];
[project setProjectManager:self]; [project setProjectManager:self];
// Windows and panels // Windows and panels
wap = [pDict objectForKey:PCWindows]; wap = [projectFile objectForKey:PCWindows];
if ([[wap allKeys] containsObject:@"ProjectBuild"]) if ([[wap allKeys] containsObject:@"ProjectBuild"])
{ {
[[project projectWindow] showProjectBuild:self]; [[project projectWindow] showProjectBuild:self];
@ -640,32 +635,42 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
[[project projectWindow] showProjectLoadedFiles:self]; [[project projectWindow] showProjectLoadedFiles:self];
} }
[[project projectWindow] makeKeyAndOrderFront:self]; if (flag)
{
[self setActiveProject:project]; [[project projectWindow] makeKeyAndOrderFront:self];
[self setActiveProject: project];
return YES; }
} }
return NO; return project;
} }
- (void)openProject - (void)openProject
{ {
NSArray *files = nil; NSArray *files = nil;
NSString *filePath = nil; NSString *filePath = nil, *temp = nil;
NSArray *fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil]; NSArray *fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil];
NSEnumerator *en = nil;
files = [fileManager filesOfTypes:fileTypes files = [fileManager filesOfTypes:fileTypes
operation:PCOpenProjectOperation operation:PCOpenProjectOperation
multiple:NO multiple:NO
title:@"Open Project" title:@"Open Project"
accView:nil]; accView:nil];
filePath = [files objectAtIndex:0]; filePath = [files objectAtIndex:0];
en = [files objectEnumerator];
while((temp = [en nextObject]) != nil)
{
if([[temp pathExtension] isEqual: @"pcproj"])
{
filePath = temp;
}
}
if (filePath != nil) if (filePath != nil)
{ {
[self openProjectAt:filePath]; [self openProjectAt:filePath makeActive: YES];
} }
} }
@ -675,9 +680,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
NSString *className = [projectTypes objectForKey:projectType]; NSString *className = [projectTypes objectForKey:projectType];
PCProject<ProjectType> *projectCreator; PCProject<ProjectType> *projectCreator;
PCProject *project = nil; PCProject *project = nil;
NSString *projectName = [aPath lastPathComponent];
if ((project = [loadedProjects objectForKey:projectName]) != nil) if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) != nil)
{ {
[[project projectWindow] makeKeyAndOrderFront:self]; [[project projectWindow] makeKeyAndOrderFront:self];
return project; return project;
@ -749,7 +753,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
return; return;
} }
[loadedProjects setObject:project forKey:[project projectName]]; [loadedProjects setObject:project forKey: [project projectPath]];
[self setActiveProject:project]; [self setActiveProject:project];
[[project projectWindow] orderFront:self]; [[project projectWindow] orderFront:self];
} }
@ -937,16 +941,15 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
- (void)closeProject:(PCProject *)aProject - (void)closeProject:(PCProject *)aProject
{ {
PCProject *currentProject = nil; PCProject *currentProject = nil;
NSString *projectName = [aProject projectName];
currentProject = [loadedProjects objectForKey:projectName]; currentProject = [loadedProjects objectForKey: [aProject projectPath]];
if (!currentProject) if (!currentProject)
{ {
return; return;
} }
// Remove it from the loaded projects! // Remove it from the loaded projects!
[loadedProjects removeObjectForKey:projectName]; [loadedProjects removeObjectForKey: [aProject projectPath]];
if ([loadedProjects count] == 0) if ([loadedProjects count] == 0)
{ {

View file

@ -138,10 +138,7 @@ extern NSString *PCActiveProjectDidChangeNotification;
- (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict - (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict
atPath:(NSString *)aPath; atPath:(NSString *)aPath;
// Returns the loaded project if the builder class is known, nil else. - (PCProject *)openProjectAt:(NSString *)aPath makeActive: (BOOL)flag;
- (PCProject *)loadProjectAt:(NSString *)aPath;
// Invokes loadProjectAt to load the project properly.
- (BOOL)openProjectAt:(NSString *)aPath;
- (void)openProject; - (void)openProject;
- (PCProject *)createProjectOfType:(NSString *)projectType - (PCProject *)createProjectOfType:(NSString *)projectType
path:(NSString *)aPath; path:(NSString *)aPath;

View file

@ -112,7 +112,7 @@
if ([[fileName pathExtension] isEqualToString:@"pcproj"] == YES if ([[fileName pathExtension] isEqualToString:@"pcproj"] == YES
|| [[fileName pathExtension] isEqualToString:@"project"] == YES) || [[fileName pathExtension] isEqualToString:@"project"] == YES)
{ {
[projectManager openProjectAt:fileName]; [projectManager openProjectAt: fileName makeActive: YES];
[[[projectManager activeProject] projectWindow] [[[projectManager activeProject] projectWindow]
makeKeyAndOrderFront:self]; makeKeyAndOrderFront:self];
} }