Improved resource handling.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20517 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2005-01-04 04:52:46 +00:00
parent b9e8478246
commit 452e9e9d0f
8 changed files with 124 additions and 9 deletions

View file

@ -1,3 +1,11 @@
2005-01-03 23:56 Gregory John Casamento <greg_casamento@yahoo.com>
* 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 <greg_casamento@yahoo.com> 2005-01-02 15:11 Gregory John Casamento <greg_casamento@yahoo.com>
* GormImageEditor.m * GormImageEditor.m

View file

@ -1955,7 +1955,7 @@ static NSImage *fileImage = nil;
NSDebugLog(@"Add the sound %@", file); NSDebugLog(@"Add the sound %@", file);
soundPath = [documentPath stringByAppendingPathComponent: 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); NSDebugLog(@"Add the image %@", file);
imagePath = [documentPath stringByAppendingPathComponent: 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]; 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) if (archiveResult)
{ {
NSArray *sounds = [soundsView objects]; NSArray *sounds = [soundsView objects];
@ -2813,11 +2819,17 @@ static NSImage *fileImage = nil;
copied = [mgr copyPath: path copied = [mgr copyPath: path
toPath: soundPath toPath: soundPath
handler: nil]; handler: nil];
if(copied)
{
[object setInWrapper: YES];
[object setSoundPath: soundPath];
}
} }
else else
{ {
// mark as copied if paths are equal... // mark as copied if paths are equal...
copied = YES; copied = YES;
[object setInWrapper: YES];
} }
if (!copied) if (!copied)
@ -2844,11 +2856,17 @@ static NSImage *fileImage = nil;
copied = [mgr copyPath: path copied = [mgr copyPath: path
toPath: imagePath toPath: imagePath
handler: nil]; handler: nil];
if(copied)
{
[object setInWrapper: YES];
[object setImagePath: imagePath];
}
} }
else else
{ {
// mark it as copied if paths are equal. // mark it as copied if paths are equal.
copied = YES; copied = YES;
[object setInWrapper: YES];
} }
if (!copied) if (!copied)

View file

@ -43,9 +43,15 @@
} }
+ (GormImage *) imageForPath: (NSString *)path; + (GormImage *) imageForPath: (NSString *)path;
+ (GormImage *) imageForPath: (NSString *)path inWrapper: (BOOL)flag;
- (id) initWithPath: (NSString *)aPath; - (id) initWithPath: (NSString *)aPath;
- (id) initWithPath: (NSString *)aPath
inWrapper: (BOOL)flag;
- (id) initWithName: (NSString *)aName - (id) initWithName: (NSString *)aName
path: (NSString *)aPath; path: (NSString *)aPath;
- (id) initWithName: (NSString *)aName
path: (NSString *)aPath
inWrapper: (BOOL)flag;
- (void) setImageName: (NSString *)aName; - (void) setImageName: (NSString *)aName;
- (NSString *) imageName; - (NSString *) imageName;
- (void) setImagePath: (NSString *)aPath; - (void) setImagePath: (NSString *)aPath;

View file

@ -50,21 +50,39 @@
@implementation GormImage @implementation GormImage
+ (GormImage*)imageForPath: (NSString *)aPath + (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 - (id) initWithPath: (NSString *)aPath
{
return [self initWithPath: aPath inWrapper: NO];
}
- (id) initWithPath: (NSString *)aPath inWrapper: (BOOL)flag
{ {
NSString *aName = [[aPath lastPathComponent] stringByDeletingPathExtension]; 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); RELEASE(self);
} }
return self; return self;
} }
- (id) initWithName: (NSString *)aName - (id) initWithName: (NSString *)aName
path: (NSString *)aPath 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) if((self = [super init]) != nil)
{ {
@ -103,7 +121,7 @@
} }
isSystemImage = NO; isSystemImage = NO;
isInWrapper = NO; isInWrapper = flag;
[image setArchiveByName: NO]; [image setArchiveByName: NO];
[smallImage setArchiveByName: NO]; [smallImage setArchiveByName: NO];
} }

View file

@ -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 - (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
{ {
return NSDragOperationCopy; return NSDragOperationCopy;

View file

@ -39,10 +39,17 @@
BOOL isSystemSound; BOOL isSystemSound;
BOOL isInWrapper; BOOL isInWrapper;
} }
+ (GormSound*) soundForPath: (NSString *)path; + (GormSound*) soundForPath: (NSString *)path;
+ (GormSound*) soundForPath: (NSString *)path inWrapper: (BOOL)flag;
- (id) initWithPath: (NSString *)aPath; - (id) initWithPath: (NSString *)aPath;
- (id) initWithPath: (NSString *)aPath
inWrapper: (BOOL)flag;
- (id) initWithName: (NSString *)aName - (id) initWithName: (NSString *)aName
path: (NSString *)aPath; path: (NSString *)aPath;
- (id) initWithName: (NSString *)aName
path: (NSString *)aPath
inWrapper: (BOOL)flag;
- (void) setSoundName: (NSString *)aName; - (void) setSoundName: (NSString *)aName;
- (NSString *) soundName; - (NSString *) soundName;
- (void) setSoundPath: (NSString *)aPath; - (void) setSoundPath: (NSString *)aPath;

View file

@ -30,13 +30,23 @@
@implementation GormSound @implementation GormSound
+ (GormSound*) soundForPath: (NSString *)aPath + (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 - (id) initWithPath: (NSString *)aPath
{
return [self initWithPath: aPath inWrapper: NO];
}
- (id) initWithPath: (NSString *)aPath inWrapper: (BOOL)flag
{ {
NSString *aName = [[aPath lastPathComponent] stringByDeletingPathExtension]; 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); RELEASE(self);
} }
@ -45,6 +55,14 @@
- (id) initWithName: (NSString *)aName - (id) initWithName: (NSString *)aName
path: (NSString *)aPath 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 NSSound *sound = [[NSSound alloc] initWithContentsOfFile: aPath
byReference: YES]; byReference: YES];
@ -55,7 +73,7 @@
//#warning "we want to store the sound somewhere" //#warning "we want to store the sound somewhere"
[(NSSound *)sound setName: aName]; [(NSSound *)sound setName: aName];
isSystemSound = NO; isSystemSound = NO;
isInWrapper = NO; isInWrapper = flag;
return self; return self;
} }

View file

@ -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<NSDraggingInfo>)sender - (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
{ {
if (dragType == IBObjectPboardType) if (dragType == IBObjectPboardType)