diff --git a/PCLib/PCProject.m b/PCLib/PCProject.m index 9dc5bba..1059c88 100644 --- a/PCLib/PCProject.m +++ b/PCLib/PCProject.m @@ -559,7 +559,17 @@ - (BOOL)writeMakefile { - return [projectDict writeToFile:[projectPath stringByAppendingPathComponent:@"PC.project"] atomically:YES]; + NSString *mf = [projectPath stringByAppendingPathComponent:@"GNUmakefile"]; + NSString *bu = [projectPath stringByAppendingPathComponent:@"GNUmakefile~"]; + NSFileManager *fm = [NSFileManager defaultManager]; + + if (![fm movePath:mf toPath:bu handler:nil]) { + NSRunAlertPanel(@"Attention!", + @"Could not keep a backup of the GNUMakefile!", + @"OK",nil,nil); + } + + return [self save]; } - (BOOL)isValidDictionary:(NSDictionary *)aDict @@ -626,38 +636,44 @@ - (void)addFile:(NSString *)file forKey:(NSString *)type copy:(BOOL)yn { - NSMutableArray *files = [NSMutableArray arrayWithArray:[projectDict objectForKey:type]]; - NSMutableString *newFile = [NSMutableString stringWithString:[file lastPathComponent]]; + NSArray *types = [projectDict objectForKey:type]; + NSMutableArray *files = [NSMutableArray arrayWithArray:types]; + NSString *lpc = [file lastPathComponent]; + NSMutableString *newFile = [NSMutableString stringWithString:lpc]; - if ([type isEqualToString:PCLibraries]) { - [newFile deleteCharactersInRange:NSMakeRange(0,3)]; - newFile = [newFile stringByDeletingPathExtension]; - } + if ([type isEqualToString:PCLibraries]) { + [newFile deleteCharactersInRange:NSMakeRange(0,3)]; + newFile = [newFile stringByDeletingPathExtension]; + } - if ([files containsObject:newFile]) { - NSRunAlertPanel(@"Attention!",@"The file %@ is already part of this project!",@"OK",nil,nil,newFile); - return; - } + if ([files containsObject:newFile]) { + NSRunAlertPanel(@"Attention!", + @"The file %@ is already part of this project!", + @"OK",nil,nil,newFile); + return; + } #ifdef DEBUG - NSLog(@"<%@ %x>: adding file %@ for key %@",[self class],self,newFile,type); -#endif DEBUG + NSLog(@"<%@ %x>: adding file %@ for key %@",[self class],self,newFile,type); +#endif// DEBUG - // Add the new file - [files addObject:newFile]; - [projectDict setObject:files forKey:type]; + // Add the new file + [files addObject:newFile]; + [projectDict setObject:files forKey:type]; - // Synchronise the makefile! - [self writeMakefile]; + // Synchronise the makefile! + [self writeMakefile]; - if (yn) { - NSFileManager *manager = [NSFileManager defaultManager]; - NSString *destination = [[self projectPath] stringByAppendingPathComponent:newFile]; + if (yn) { + NSFileManager *manager = [NSFileManager defaultManager]; + NSString *destination = [[self projectPath] stringByAppendingPathComponent:newFile]; - if (![manager copyPath:file toPath:destination handler:nil]) { - NSRunAlertPanel(@"Attention!",@"The file %@ could not be copied to %@!",@"OK",nil,nil,newFile,destination); + if (![manager copyPath:file toPath:destination handler:nil]) { + NSRunAlertPanel(@"Attention!", + @"The file %@ could not be copied to %@!", + @"OK",nil,nil,newFile,destination); + } } - } } - (void)removeFile:(NSString *)file forKey:(NSString *)key @@ -783,22 +799,57 @@ - (BOOL)save { + BOOL ret = NO; + NSString *file = [projectPath stringByAppendingPathComponent:@"PC.project"]; + NSString *backup = [file stringByAppendingPathExtension:@"backup"]; + NSFileManager *fm = [NSFileManager defaultManager]; + NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; + NSString *keepBackup = [defs objectForKey:KeepBackup]; + BOOL shouldKeep = [keepBackup isEqualToString:@"YES"]; + + if ( shouldKeep == NO && [fm isWritableFileAtPath:backup] ) { + [fm removeFileAtPath:backup handler:nil]; + } + + if (shouldKeep && [fm isReadableFileAtPath:file]) { + ret = [fm copyPath:file toPath:backup handler:nil]; + + if( ret == NO ) { + NSString *name = [projectDict objectForKey:PCProjectName]; + + NSRunAlertPanel(@"Attention!", + @"Could not save the backup file for '%@'!", + @"OK",nil,nil,name); + } + } + + ret = [projectDict writeToFile:file atomically:YES]; + + return ret; } - (BOOL)saveAt:(NSString *)projPath { + return NO; } - (BOOL)saveFileNamed:(NSString *)file { + return NO; } - (BOOL)saveAllFiles { + BOOL ret = NO; + + return ret; } - (BOOL)saveAllFilesIfNeeded { + BOOL ret = YES; + + return ret; } //============================================================================= diff --git a/PCLib/PCProjectManager.h b/PCLib/PCProjectManager.h index b85217c..fdb0af0 100644 --- a/PCLib/PCProjectManager.h +++ b/PCLib/PCProjectManager.h @@ -43,8 +43,6 @@ NSString *rootBuildPath; - NSWindow *loadedProjectsWindow; - @private BOOL _needsReleasing; } @@ -111,9 +109,6 @@ - (void)showInspectorForProject:(PCProject *)aProject; // Opens the inspector for aProject -- (void)showLoadedProjects; - // Opens a panel containing all opened projects - - (void)saveFiles; // Saves all the edited files from the currently active project diff --git a/PCLib/PCProjectManager.m b/PCLib/PCProjectManager.m index bbc58dd..0c5a765 100644 --- a/PCLib/PCProjectManager.m +++ b/PCLib/PCProjectManager.m @@ -48,21 +48,6 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; NSRect _w_frame; NSBox *line; - /* - * Projects Window - * - */ - - _w_frame = NSMakeRect(200,300,560,384); - loadedProjectsWindow = [[NSWindow alloc] initWithContentRect:_w_frame - styleMask:style - backing:NSBackingStoreBuffered - defer:YES]; - [loadedProjectsWindow setMinSize:NSMakeSize(560,384)]; - [loadedProjectsWindow setTitle:@"Loaded Projects"]; - [loadedProjectsWindow setReleasedWhenClosed:NO]; - [loadedProjectsWindow setFrameAutosaveName:@"LoadedProjects"]; - /* * Inspector Window * @@ -139,7 +124,6 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; [inspector release]; [inspectorView release]; [inspectorPopup release]; - [loadedProjectsWindow release]; } [super dealloc]; @@ -193,6 +177,21 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; - (void)saveAllProjects { + NSEnumerator *enumerator = [loadedProjects keyEnumerator]; + NSString *key; + BOOL ret; + PCProject *project; + + while ( key = [enumerator nextObject] ) + { + project = [loadedProjects objectForKey:key]; + ret = [project save]; + if( ret == NO ) { + NSRunAlertPanel(@"Attention!", + @"Couldn't save project %@!", + @"OK",nil,nil,[project projectName]); + } + } } - (NSString *)rootBuildPath @@ -217,7 +216,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; #ifdef DEBUG NSLog([NSString stringWithFormat:@"Builders %@ for key %@",[builders description],builderKey]); -#endif DEBUG +#endif // DEBUG concretBuilder = [NSClassFromString([builders objectForKey:builderKey]) sharedCreator]; @@ -232,7 +231,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; else { NSLog(@"No project manager delegate available!"); } -#endif DEBUG +#endif // DEBUG return nil; } @@ -244,7 +243,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; if ([loadedProjects objectForKey:aPath]) { #ifdef DEBUG NSLog([NSString stringWithFormat:@"Project %@ is already loaded!",aPath]); -#endif DEBUG +#endif // DEBUG return NO; } @@ -254,7 +253,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; if (!project) { #ifdef DEBUG NSLog(@"Couldn't instantiate the project..."); -#endif DEBUG +#endif // DEBUG return NO; } @@ -294,13 +293,34 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; - (BOOL)saveProject { + BOOL ret; + + if (![self activeProject]) { + return; + } + // Save all files that need to be saved + ret = [activeProject saveAllFilesIfNeeded]; + if( ret == NO ) { + NSRunAlertPanel(@"Attention!", + @"Couldn't save the files for project %@!", + @"OK",nil,nil,[activeProject projectName]); + } // Save PC.project and the makefile! + ret = [activeProject save]; + if( ret == NO ) { + NSRunAlertPanel(@"Attention!", + @"Couldn't save project %@!", + @"OK",nil,nil,[activeProject projectName]); + } } - (BOOL)saveProjectAs:(NSString *)projName { + NSRunAlertPanel(@"Attention!", + @"This feature is not yet implemented!", + @"OK",nil,nil); } - (void)inspectorPopupDidChange:(id)sender @@ -345,14 +365,6 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; [inspector makeKeyAndOrderFront:self]; } -- (void)showLoadedProjects -{ - if (![loadedProjectsWindow isVisible]) { - [loadedProjectsWindow center]; - } - [loadedProjectsWindow makeKeyAndOrderFront:self]; -} - - (void)saveFiles { } @@ -451,7 +463,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; #ifdef DEBUG NSLog(@"%@ %x: will create file %@ for key %@.",[self class],self,aFile,key); - #endif DEBUG + #endif // DEBUG if ([activeProject doesAcceptFile:aFile forKey:key] ) { path = [[activeProject projectPath] stringByAppendingPathComponent:aFile]; @@ -464,7 +476,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; { #ifdef DEBUG NSLog(@"<%@ %x>: did create file %@ for key %@",[self class],self,aFile,key); -#endif DEBUG +#endif // DEBUG [activeProject addFile:aFile forKey:key]; } @@ -480,7 +492,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; #ifdef DEBUG NSLog(@"<%@ %x>: should add file %@ for key %@",[self class],self,file,key); -#endif DEBUG +#endif // DEBUG if ([key isEqualToString:PCLibraries]) { [fn deleteCharactersInRange:NSMakeRange(1,3)]; @@ -498,7 +510,7 @@ NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange"; { #ifdef DEBUG NSLog(@"<%@ %x>: did add file %@ for key %@",[self class],self,file,key); -#endif DEBUG +#endif // DEBUG [activeProject addFile:file forKey:key]; } diff --git a/PCLib/ProjectCenter.h b/PCLib/ProjectCenter.h index 047d68e..b5db806 100644 --- a/PCLib/ProjectCenter.h +++ b/PCLib/ProjectCenter.h @@ -32,10 +32,11 @@ #define Editor @"Editor" #define Debugger @"Debugger" #define Compiler @"Compiler" -#define PromtOnClean @"PromtOnClean" -#define PromtOnQuit @"PromtOnQuit" -#define AutoSave @"UAutoSaveRL" -#define RemoveBackup @"RemoveBackup" +#define PromptOnClean @"PromtOnClean" +#define PromptOnQuit @"PromtOnQuit" +#define SaveOnQuit @"SaveOnQuit" +#define AutoSave @"AutoSave" +#define KeepBackup @"KeepBackup" #define AutoSavePeriod @"AutoSavePeriod" #define RootBuildDirectory @"RootBuildDirectory" #define DeleteCacheWhenQuitting @"DeleteBuildCacheWhenQuitting"