From f2a055ef978e441d0415db4f890ffca0492b53ce Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Fri, 27 Mar 2009 07:01:11 +0000 Subject: [PATCH] * Framework/PCProject.m: Implement openWrapperAtPath: * Framework/PCProjectManager.m: Change method call to use openWrapperAtPath: * Headers/ProjectCenter/PCProject.h: Add wrapperPath ivar. * Modules/Projects/Application/PCAppProject.m: Change method to call super. * Modules/Projects/Tool/PCToolProject.m: Change method to call super. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28138 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 +++ Framework/PCProject.m | 77 ++++++++++++++++++--- Framework/PCProjectManager.m | 4 +- Headers/ProjectCenter/PCProject.h | 4 +- Modules/Projects/Application/PCAppProject.m | 7 +- Modules/Projects/Tool/PCToolProject.m | 7 +- 6 files changed, 86 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f7a594..9ffe305 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-03-27 03:00-EDT Gregory John Casamento + + * Framework/PCProject.m: Implement openWrapperAtPath: + * Framework/PCProjectManager.m: Change method call to use + openWrapperAtPath: + * Headers/ProjectCenter/PCProject.h: Add wrapperPath ivar. + * Modules/Projects/Application/PCAppProject.m: + Change method to call super. + * Modules/Projects/Tool/PCToolProject.m: Change method to + call super. + 2009-03-27 01:18-EDT Gregory John Casamento * Framework/English.lproj/Builder.gorm: Update icons for stop and diff --git a/Framework/PCProject.m b/Framework/PCProject.m index 53ddc93..25e3136 100644 --- a/Framework/PCProject.m +++ b/Framework/PCProject.m @@ -84,11 +84,55 @@ NSString return self; } -- (PCProject *)openWithDictionaryAt:(NSString *)path +- (PCProject *)openWithWrapperAt:(NSString *)path { - NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; + NSString *aPath = path; - [self assignProjectDict:dict atPath:path]; + if([[aPath lastPathComponent] isEqual: @"PC.project"]) + { + 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 + { + aPath = newPath; + } + } + + projectFileWrapper = [[NSFileWrapper alloc] initWithPath: aPath]; + if(projectFileWrapper != nil) + { + 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; + } return self; } @@ -151,7 +195,8 @@ NSString projectDict = [[NSMutableDictionary alloc] initWithDictionary:pDict]; // Project path - if ([[pPath lastPathComponent] isEqualToString:@"PC.project"]) + if ([[pPath lastPathComponent] isEqualToString:@"PC.project"] || + [[[pPath lastPathComponent] pathExtension] isEqualToString:@"pcproj"]) { [self setProjectPath:[pPath stringByDeletingLastPathComponent]]; } @@ -337,7 +382,7 @@ NSString NSString *projectFile = nil; NSMutableDictionary *projectFileDict = nil; - projectFile = [projectPath stringByAppendingPathComponent:[NSUserName() stringByAppendingPathExtension:@"project"]]; + projectFile = [NSUserName() stringByAppendingPathExtension:@"project"]; projectFileDict = [[NSMutableDictionary alloc] initWithCapacity:4]; // Project Window @@ -407,8 +452,16 @@ NSString // Now save it directly to username.project file [projectFileDict setObject:windows forKey:@"PC_WINDOWS"]; - [projectFileDict writeToFile:projectFile atomically:YES]; + // add the file and write the wrapper. + [projectFileWrapper addRegularFileWithContents: + [NSData dataWithBytes: [[projectFileDict description] cString] + length: [[projectFileDict description] length]] + preferredFilename: projectFile]; + [projectFileWrapper writeToFile: wrapperPath + atomically: YES + updateFilenames: YES]; + // release [projectFileDict release]; return YES; @@ -420,13 +473,17 @@ NSString int spCount = [loadedSubprojects count]; int i; NSString *wrapperFile = [projectName stringByAppendingPathExtension: @"pcproj"]; - NSString *wrapperPath = [projectPath stringByAppendingPathComponent: wrapperFile]; NSString *file = @"PC.project"; NSString *backup = [wrapperPath stringByAppendingPathExtension:@"backup"]; - + NSMutableDictionary *dict = [projectDict mutableCopy]; + + // remove key.. + [dict removeObjectForKey: @"PC_WINDOWS"]; + // initialize the wrapper... projectFileWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers: [NSMutableDictionary dictionaryWithCapacity: 3]]; + wrapperPath = [projectPath stringByAppendingPathComponent: wrapperFile]; // load subprojects... for (i = 0; i < spCount; i++) @@ -461,8 +518,8 @@ NSString [projectDict setObject: [[NSCalendarDate date] description] forKey: PCLastEditing]; [projectFileWrapper addRegularFileWithContents: - [NSData dataWithBytes: [[projectDict description] cString] - length: [[projectDict description] length]] + [NSData dataWithBytes: [[dict description] cString] + length: [[dict description] length]] preferredFilename: file]; if ([projectFileWrapper writeToFile:wrapperPath diff --git a/Framework/PCProjectManager.m b/Framework/PCProjectManager.m index 5ed5eb8..49e86f9 100644 --- a/Framework/PCProjectManager.m +++ b/Framework/PCProjectManager.m @@ -572,7 +572,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; protocol:@protocol(ProjectType)]; } - if (!project || ![project openWithDictionaryAt:aPath]) + if (!project || ![project openWithWrapperAt:aPath]) { NSRunAlertPanel(@"Open Project", @"Unable to open project '%@'.\nReport bug, please!", @@ -648,7 +648,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; { NSArray *files = nil; NSString *filePath = nil; - NSArray *fileTypes = [NSArray arrayWithObjects:@"project",@"pcproj",nil]; + NSArray *fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil]; files = [fileManager filesOfTypes:fileTypes operation:PCOpenProjectOperation diff --git a/Headers/ProjectCenter/PCProject.h b/Headers/ProjectCenter/PCProject.h index f6cab0d..326ecfc 100644 --- a/Headers/ProjectCenter/PCProject.h +++ b/Headers/ProjectCenter/PCProject.h @@ -74,6 +74,7 @@ extern NSString *PCProjectBreakpointNotification; PCProject *rootProject; PCProject *superProject; NSFileWrapper *projectFileWrapper; + NSString *wrapperPath; } // ============================================================================ @@ -81,8 +82,7 @@ extern NSString *PCProjectBreakpointNotification; // ============================================================================ - (id)init; -//- (id)initWithProjectDictionary:(NSDictionary *)dict path:(NSString *)path; -- (PCProject *)openWithDictionaryAt:(NSString *)path; +- (PCProject *)openWithWrapperAt:(NSString *)path; - (void)dealloc; - (void)loadPreferences:(NSNotification *)aNotification; diff --git a/Modules/Projects/Application/PCAppProject.m b/Modules/Projects/Application/PCAppProject.m index 9d16531..a48679c 100644 --- a/Modules/Projects/Application/PCAppProject.m +++ b/Modules/Projects/Application/PCAppProject.m @@ -256,13 +256,10 @@ // --- PCProject overridings // ---------------------------------------------------------------------------- -- (PCProject *)openWithDictionaryAt:(NSString *)path +- (PCProject *)openWithWrapperAt:(NSString *)path { - NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; - - [self assignProjectDict:dict atPath:path]; + [super openWithWrapperAt: path]; [self loadInfoFile]; - return self; } diff --git a/Modules/Projects/Tool/PCToolProject.m b/Modules/Projects/Tool/PCToolProject.m index 91c3778..b2ca7cd 100644 --- a/Modules/Projects/Tool/PCToolProject.m +++ b/Modules/Projects/Tool/PCToolProject.m @@ -205,13 +205,10 @@ // --- PCProject overridings //---------------------------------------------------------------------------- -- (PCProject *)openWithDictionaryAt:(NSString *)path +- (PCProject *)openWithWrapperAt:(NSString *)path { - NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; - - [self assignProjectDict:dict atPath:path]; + [super openWithWrapperAt: path]; [self loadInfoFile]; - return self; }