From 452e9e9d0fa7e68bae5747b2d61defbc9737a38b Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 4 Jan 2005 04:52:46 +0000 Subject: [PATCH] Improved resource handling. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20517 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++++ GormDocument.m | 24 +++++++++++++++++++++--- GormImage.h | 6 ++++++ GormImage.m | 24 +++++++++++++++++++++--- GormImageEditor.m | 20 ++++++++++++++++++++ GormSound.h | 7 +++++++ GormSound.m | 24 +++++++++++++++++++++--- GormSoundEditor.m | 20 ++++++++++++++++++++ 8 files changed, 124 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index db6c5fb8..bd961006 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-01-03 23:56 Gregory John Casamento + + * GormDocument.m: Improved resource handling in saveGormDocument: + * GormImageEditor.m: Implemented deleteSelection + * GormImage.[hm]: Added new init methods. + * GormSoundEditor.m: Implemented deleteSelection + * GormSound.[hm]: Added new init methods. + 2005-01-02 15:11 Gregory John Casamento * GormImageEditor.m diff --git a/GormDocument.m b/GormDocument.m index ca5f87a4..4a01b854 100644 --- a/GormDocument.m +++ b/GormDocument.m @@ -1955,7 +1955,7 @@ static NSImage *fileImage = nil; NSDebugLog(@"Add the sound %@", file); soundPath = [documentPath stringByAppendingPathComponent: file]; - [soundsView addObject: [[GormSound alloc] initWithPath: soundPath]]; + [soundsView addObject: [GormSound soundForPath: soundPath inWrapper: YES]]; } } } @@ -1977,7 +1977,7 @@ static NSImage *fileImage = nil; NSDebugLog(@"Add the image %@", file); imagePath = [documentPath stringByAppendingPathComponent: file]; - [imagesView addObject: [GormImage imageForPath: imagePath]]; + [imagesView addObject: [GormImage imageForPath: imagePath inWrapper: YES]]; } } } @@ -2791,7 +2791,13 @@ static NSImage *fileImage = nil; archiveResult = [filePrefsManager saveToFile: infoPath]; } - // copy sounds into the new folder... + // + // Copy resources into the new folder... + // Gorm doesn't copy these into the folder right away since the folder may + // not yet exist. This allows the user to add/delete resources as they see fit + // but only those which they end up with will actually be put into the wrapper + // when the model/document is saved. + // if (archiveResult) { NSArray *sounds = [soundsView objects]; @@ -2813,11 +2819,17 @@ static NSImage *fileImage = nil; copied = [mgr copyPath: path toPath: soundPath handler: nil]; + if(copied) + { + [object setInWrapper: YES]; + [object setSoundPath: soundPath]; + } } else { // mark as copied if paths are equal... copied = YES; + [object setInWrapper: YES]; } if (!copied) @@ -2844,11 +2856,17 @@ static NSImage *fileImage = nil; copied = [mgr copyPath: path toPath: imagePath handler: nil]; + if(copied) + { + [object setInWrapper: YES]; + [object setImagePath: imagePath]; + } } else { // mark it as copied if paths are equal. copied = YES; + [object setInWrapper: YES]; } if (!copied) diff --git a/GormImage.h b/GormImage.h index 225de8df..8c09ed24 100644 --- a/GormImage.h +++ b/GormImage.h @@ -43,9 +43,15 @@ } + (GormImage *) imageForPath: (NSString *)path; ++ (GormImage *) imageForPath: (NSString *)path inWrapper: (BOOL)flag; - (id) initWithPath: (NSString *)aPath; +- (id) initWithPath: (NSString *)aPath + inWrapper: (BOOL)flag; - (id) initWithName: (NSString *)aName path: (NSString *)aPath; +- (id) initWithName: (NSString *)aName + path: (NSString *)aPath + inWrapper: (BOOL)flag; - (void) setImageName: (NSString *)aName; - (NSString *) imageName; - (void) setImagePath: (NSString *)aPath; diff --git a/GormImage.m b/GormImage.m index cce43251..153c21c0 100644 --- a/GormImage.m +++ b/GormImage.m @@ -50,21 +50,39 @@ @implementation GormImage + (GormImage*)imageForPath: (NSString *)aPath { - return AUTORELEASE([[GormImage alloc] initWithPath: aPath]); + return [GormImage imageForPath: aPath inWrapper: NO]; +} + ++ (GormImage*)imageForPath: (NSString *)aPath inWrapper: (BOOL)flag +{ + return AUTORELEASE([[GormImage alloc] initWithPath: aPath inWrapper: flag]); } - (id) initWithPath: (NSString *)aPath +{ + return [self initWithPath: aPath inWrapper: NO]; +} + +- (id) initWithPath: (NSString *)aPath inWrapper: (BOOL)flag { NSString *aName = [[aPath lastPathComponent] stringByDeletingPathExtension]; - if((self = [self initWithName: aName path: aPath]) == nil) + if((self = [self initWithName: aName path: aPath inWrapper: flag]) == nil) { RELEASE(self); } return self; } + - (id) initWithName: (NSString *)aName path: (NSString *)aPath +{ + return [self initWithName: aName path: aPath inWrapper: NO]; +} + +- (id) initWithName: (NSString *)aName + path: (NSString *)aPath + inWrapper: (BOOL)flag { if((self = [super init]) != nil) { @@ -103,7 +121,7 @@ } isSystemImage = NO; - isInWrapper = NO; + isInWrapper = flag; [image setArchiveByName: NO]; [smallImage setArchiveByName: NO]; } diff --git a/GormImageEditor.m b/GormImageEditor.m index c7525cae..e8f9f250 100644 --- a/GormImageEditor.m +++ b/GormImageEditor.m @@ -411,6 +411,26 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat { } +- (void) deleteSelection +{ + if(![selected isSystemImage]) + { + if([selected isInWrapper]) + { + NSFileManager *mgr = [NSFileManager defaultManager]; + NSString *path = [selected imagePath]; + BOOL removed = [mgr removeFileAtPath: path + handler: nil]; + if(!removed) + { + NSString *msg = [NSString stringWithFormat: @"Could not delete file %@", path]; + NSLog(msg); + } + } + [super deleteSelection]; + } +} + - (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag { return NSDragOperationCopy; diff --git a/GormSound.h b/GormSound.h index c6186f32..8c0587f6 100644 --- a/GormSound.h +++ b/GormSound.h @@ -39,10 +39,17 @@ BOOL isSystemSound; BOOL isInWrapper; } + + (GormSound*) soundForPath: (NSString *)path; ++ (GormSound*) soundForPath: (NSString *)path inWrapper: (BOOL)flag; - (id) initWithPath: (NSString *)aPath; +- (id) initWithPath: (NSString *)aPath + inWrapper: (BOOL)flag; - (id) initWithName: (NSString *)aName path: (NSString *)aPath; +- (id) initWithName: (NSString *)aName + path: (NSString *)aPath + inWrapper: (BOOL)flag; - (void) setSoundName: (NSString *)aName; - (NSString *) soundName; - (void) setSoundPath: (NSString *)aPath; diff --git a/GormSound.m b/GormSound.m index 14e16f6b..561656b5 100644 --- a/GormSound.m +++ b/GormSound.m @@ -30,13 +30,23 @@ @implementation GormSound + (GormSound*) soundForPath: (NSString *)aPath { - return AUTORELEASE([[GormSound alloc] initWithPath: aPath]); + return [GormSound soundForPath: aPath inWrapper: NO]; +} + ++ (GormSound*) soundForPath: (NSString *)aPath inWrapper: (BOOL)flag +{ + return AUTORELEASE([[GormSound alloc] initWithPath: aPath inWrapper: flag]); } - (id) initWithPath: (NSString *)aPath +{ + return [self initWithPath: aPath inWrapper: NO]; +} + +- (id) initWithPath: (NSString *)aPath inWrapper: (BOOL)flag { NSString *aName = [[aPath lastPathComponent] stringByDeletingPathExtension]; - if((self = [self initWithName: aName path: aPath]) == nil) + if((self = [self initWithName: aName path: aPath inWrapper: flag]) == nil) { RELEASE(self); } @@ -45,6 +55,14 @@ - (id) initWithName: (NSString *)aName path: (NSString *)aPath +{ + return [self initWithName: aName path: aPath inWrapper: NO]; +} + + +- (id) initWithName: (NSString *)aName + path: (NSString *)aPath + inWrapper: (BOOL)flag { NSSound *sound = [[NSSound alloc] initWithContentsOfFile: aPath byReference: YES]; @@ -55,7 +73,7 @@ //#warning "we want to store the sound somewhere" [(NSSound *)sound setName: aName]; isSystemSound = NO; - isInWrapper = NO; + isInWrapper = flag; return self; } diff --git a/GormSoundEditor.m b/GormSoundEditor.m index d8d5aba6..7eb7b0cb 100644 --- a/GormSoundEditor.m +++ b/GormSoundEditor.m @@ -402,6 +402,26 @@ static NSMapTable *docMap = 0; { } +- (void) deleteSelection +{ + if(![selected isSystemSound]) + { + if([selected isInWrapper]) + { + NSFileManager *mgr = [NSFileManager defaultManager]; + NSString *path = [selected soundPath]; + BOOL removed = [mgr removeFileAtPath: path + handler: nil]; + if(!removed) + { + NSString *msg = [NSString stringWithFormat: @"Could not delete file %@", path]; + NSLog(msg); + } + } + [super deleteSelection]; + } +} + - (BOOL) performDragOperation: (id)sender { if (dragType == IBObjectPboardType)