diff --git a/ChangeLog b/ChangeLog index da73561..4b9f8bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-06-23 18:22-EDT Gregory John Casamento + + * 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 * Resources/Info-gnustep.plist: Added PCProjectFileType to the diff --git a/Framework/PCProject.m b/Framework/PCProject.m index a6a7da7..10be611 100644 --- a/Framework/PCProject.m +++ b/Framework/PCProject.m @@ -84,56 +84,46 @@ NSString return self; } -- (PCProject *)openWithWrapperAt:(NSString *)path +- (PCProject *)openWithWrapperAt:(NSString *)aPath { - NSString *aPath = path; - - if([[aPath lastPathComponent] isEqual: @"PC.project"]) + BOOL isDir = NO; + BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath: aPath + isDirectory: &isDir]; + if(isDir && exists) { - NSString *newPath = [aPath stringByDeletingLastPathComponent]; - if([[[newPath lastPathComponent] pathExtension] - isEqual: @"pcproj"] == NO) - { - NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile: aPath]; - - projectFileWrapper = [[NSFileWrapper alloc] - initDirectoryWithFileWrappers: - [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 + projectFileWrapper = [[NSFileWrapper alloc] initWithPath: aPath]; + if(projectFileWrapper != nil) { - aPath = newPath; + 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]; + + [dict addEntriesFromDictionary: udict]; + [self assignProjectDict:dict atPath: aPath]; } } - - projectFileWrapper = [[NSFileWrapper alloc] initWithPath: aPath]; - if(projectFileWrapper != nil) + else { - 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]; - - [dict addEntriesFromDictionary: udict]; - [self assignProjectDict:dict atPath: aPath]; - - return self; + NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile: aPath]; + + projectFileWrapper = [[NSFileWrapper alloc] + initDirectoryWithFileWrappers: + [NSMutableDictionary dictionaryWithCapacity: 3]]; + [projectFileWrapper addRegularFileWithContents: + [NSData dataWithBytes: [[dict description] cString] + length: [[dict description] length]] + preferredFilename: @"PC.project"]; + [self assignProjectDict: dict + atPath: aPath]; } - + return self; } @@ -1560,7 +1550,7 @@ NSString spFile = [spFile stringByAppendingPathComponent: @"PC.project"]; /* PCLogInfo(self, @"Not found! Load subproject: %@ at path: %@", name, spFile);*/ - sp = [projectManager loadProjectAt:spFile]; + sp = [projectManager openProjectAt:spFile makeActive:NO]; if (sp) { [sp setIsSubproject:YES]; diff --git a/Framework/PCProjectManager.m b/Framework/PCProjectManager.m index a930b8b..9e68d9c 100644 --- a/Framework/PCProjectManager.m +++ b/Framework/PCProjectManager.m @@ -417,6 +417,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; // ==== Project actions // ============================================================================ + - (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict atPath:(NSString *)aPath { @@ -432,7 +433,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; NSString *_2file = nil; NSString *_resFile = nil; unsigned i = 0; - PCProject *project = nil; + PCProject *project = nil; NSMutableArray *otherResArray = nil; NSString *plistFile = nil; @@ -539,94 +540,88 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; return project; } -- (PCProject *)loadProjectAt:(NSString *)aPath +- (PCProject *)openProjectAt:(NSString *)aPath makeActive: (BOOL)flag { - NSMutableDictionary *projectFile = nil; - NSString *projectTypeName = nil; - NSString *projectClassName = nil; - PCProject *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; NSDictionary *wap = nil; - BOOL isDir = NO; - - projectName = [pDict objectForKey:PCProjectName]; - - if ((project = [loadedProjects objectForKey:projectName]) != nil) - { - [[project projectWindow] makeKeyAndOrderFront:self]; - return YES; - } - - if ([[NSFileManager defaultManager] fileExistsAtPath:aPath - isDirectory:&isDir] && !isDir) - { - project = [self loadProjectAt:aPath]; - + + if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) == nil) + { + NSMutableDictionary *projectFile = nil; + NSString *projectTypeName = nil; + NSString *projectClassName = nil; + BOOL isDir = NO; + BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:aPath + isDirectory: &isDir]; + if (!exists) + { + return nil; + } + + if (!isDir) + { + projectFile = [NSMutableDictionary dictionaryWithContentsOfFile: 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) { - return NO; + return nil; } - - [loadedProjects setObject:project forKey:projectName]; + + [loadedProjects setObject:project forKey: [project projectPath]]; [project setProjectManager:self]; - + // Windows and panels - wap = [pDict objectForKey:PCWindows]; + wap = [projectFile objectForKey:PCWindows]; if ([[wap allKeys] containsObject:@"ProjectBuild"]) { [[project projectWindow] showProjectBuild:self]; @@ -639,33 +634,43 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; { [[project projectWindow] showProjectLoadedFiles:self]; } - - [[project projectWindow] makeKeyAndOrderFront:self]; - - [self setActiveProject:project]; - - return YES; + + if (flag) + { + [[project projectWindow] makeKeyAndOrderFront:self]; + [self setActiveProject: project]; + } } - - return NO; + + return project; } - (void)openProject { NSArray *files = nil; - NSString *filePath = nil; + NSString *filePath = nil, *temp = nil; NSArray *fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil]; + NSEnumerator *en = nil; files = [fileManager filesOfTypes:fileTypes operation:PCOpenProjectOperation multiple:NO title:@"Open Project" accView:nil]; + filePath = [files objectAtIndex:0]; + en = [files objectEnumerator]; + while((temp = [en nextObject]) != nil) + { + if([[temp pathExtension] isEqual: @"pcproj"]) + { + filePath = temp; + } + } if (filePath != nil) { - [self openProjectAt:filePath]; + [self openProjectAt:filePath makeActive: YES]; } } @@ -675,9 +680,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; NSString *className = [projectTypes objectForKey:projectType]; PCProject *projectCreator; PCProject *project = nil; - NSString *projectName = [aPath lastPathComponent]; - if ((project = [loadedProjects objectForKey:projectName]) != nil) + if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) != nil) { [[project projectWindow] makeKeyAndOrderFront:self]; return project; @@ -749,7 +753,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; return; } - [loadedProjects setObject:project forKey:[project projectName]]; + [loadedProjects setObject:project forKey: [project projectPath]]; [self setActiveProject:project]; [[project projectWindow] orderFront:self]; } @@ -937,16 +941,15 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; - (void)closeProject:(PCProject *)aProject { PCProject *currentProject = nil; - NSString *projectName = [aProject projectName]; - currentProject = [loadedProjects objectForKey:projectName]; + currentProject = [loadedProjects objectForKey: [aProject projectPath]]; if (!currentProject) { return; } // Remove it from the loaded projects! - [loadedProjects removeObjectForKey:projectName]; + [loadedProjects removeObjectForKey: [aProject projectPath]]; if ([loadedProjects count] == 0) { diff --git a/Headers/ProjectCenter/PCProjectManager.h b/Headers/ProjectCenter/PCProjectManager.h index ccc5d83..12021f3 100644 --- a/Headers/ProjectCenter/PCProjectManager.h +++ b/Headers/ProjectCenter/PCProjectManager.h @@ -138,10 +138,7 @@ extern NSString *PCActiveProjectDidChangeNotification; - (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict atPath:(NSString *)aPath; -// Returns the loaded project if the builder class is known, nil else. -- (PCProject *)loadProjectAt:(NSString *)aPath; -// Invokes loadProjectAt to load the project properly. -- (BOOL)openProjectAt:(NSString *)aPath; +- (PCProject *)openProjectAt:(NSString *)aPath makeActive: (BOOL)flag; - (void)openProject; - (PCProject *)createProjectOfType:(NSString *)projectType path:(NSString *)aPath; diff --git a/PCAppController.m b/PCAppController.m index e51d1ab..9bbb0b2 100644 --- a/PCAppController.m +++ b/PCAppController.m @@ -112,7 +112,7 @@ if ([[fileName pathExtension] isEqualToString:@"pcproj"] == YES || [[fileName pathExtension] isEqualToString:@"project"] == YES) { - [projectManager openProjectAt:fileName]; + [projectManager openProjectAt: fileName makeActive: YES]; [[[projectManager activeProject] projectWindow] makeKeyAndOrderFront:self]; } @@ -120,7 +120,7 @@ { [projectManager openFileAtPath:fileName]; } - + return YES; }