* Source/NSPasteboard.m (+pasteboardByFilteringFile:): Correct

typo in Richard's change.
* Source/NSPasteboard.m (-pasteboard:provideDataForType:): Use
 the file name directly instead of reading the file contents.
* Source/NSImageRep.m (+imageRepsWithContentsOfFile:,
+imageFileTypes):
Start working on filter service support for images.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@34741 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2012-02-08 09:42:46 +00:00
parent 3f7774c17c
commit 486ffcb4bd
3 changed files with 108 additions and 43 deletions

View file

@ -1,3 +1,12 @@
2012-02-08 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSPasteboard.m (+pasteboardByFilteringFile:): Correct
typo in Richard's change.
* Source/NSPasteboard.m (-pasteboard:provideDataForType:): Use the
file name directly instead of reading the file contents.
* Source/NSImageRep.m (+imageRepsWithContentsOfFile:, +imageFileTypes):
Start working on filter service support for images.
2012-02-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPasteboard.m: ([+pasteboardByFilteringFile:]) fixed to

View file

@ -203,6 +203,7 @@ implement, so we can't do that. */
{
NSString *ext;
Class rep;
NSData* data;
// Is the file extension already the file type?
ext = [filename pathExtension];
@ -210,7 +211,6 @@ implement, so we can't do that. */
{
/* With no extension, we can't tell the type from the file name.
Use the data instead. */
NSData *data;
data = [NSData dataWithContentsOfFile: filename];
return [self _imageRepsWithData: data];
}
@ -227,20 +227,45 @@ implement, so we can't do that. */
else
return nil;
{
NSData* data;
// filter non-native types to native format
if (![[rep imageUnfilteredFileTypes] containsObject: ext])
{
NSPasteboard *p = [NSPasteboard pasteboardByFilteringFile: filename];
NSArray *nativeTypes = [rep imageUnfilteredFileTypes];
NSMutableArray *ptypes = [NSMutableArray arrayWithCapacity: [nativeTypes count]];
NSEnumerator *enumerator = [nativeTypes objectEnumerator];
NSString *type;
data = [NSData dataWithContentsOfFile: filename];
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
// Convert the native types to pasteboard types
while ((type = [enumerator nextObject]) != nil)
{
NSString *type2 = NSCreateFileContentsPboardType(type);
[ptypes addObject: type2];
}
type = [p availableTypeFromArray: ptypes];
data = [p dataForType: type];
NSDebugLLog(@"NSImage", @"Filtering data for %@ from %@ of type %@ to %@", filename, p, type, data);
}
else
{
data = [NSData dataWithContentsOfFile: filename];
}
if (nil == data)
return nil;
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
{
return [rep imageRepsWithData: data];
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
{
NSImageRep *imageRep = [rep imageRepWithData: data];
if (imageRep != nil)
return [NSArray arrayWithObject: imageRep];
}
}
}
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
{
NSImageRep *imageRep = [rep imageRepWithData: data];
if (imageRep != nil)
return [NSArray arrayWithObject: imageRep];
}
return nil;
}
@ -339,8 +364,35 @@ implement, so we can't do that. */
+ (NSArray *) imageFileTypes
{
// FIXME: We should check what conversions are defined by services.
return [self imageUnfilteredFileTypes];
NSArray *nativeTypes = [self imageUnfilteredFileTypes];
NSEnumerator *enumerator = [nativeTypes objectEnumerator];
NSMutableArray *filteredTypes = [[NSMutableArray alloc] initWithCapacity:
[nativeTypes count]];
NSString *type;
while ((type = [enumerator nextObject]) != nil)
{
NSEnumerator *enum2 = [[NSPasteboard typesFilterableTo:
NSCreateFileContentsPboardType(type)]
objectEnumerator];
NSString *type2;
while ((type2 = [enum2 nextObject]) != nil)
{
NSString *fileType = NSGetFileType(type2);
if (nil != fileType)
{
type2 = fileType;
}
if ([filteredTypes indexOfObject: type2] == NSNotFound)
{
[filteredTypes addObject: type2];
}
}
}
return AUTORELEASE(filteredTypes);
}
+ (NSArray *) imagePasteboardTypes

View file

@ -747,36 +747,40 @@ static NSString *namePrefix = @"NSTypedFilenamesPboardType:";
[sender setData: [NSData data] forType: type];
return; // Not the name of a file to filter.
}
if (data != nil)
{
d = data;
}
else if (file != nil)
{
d = [NSData dataWithContentsOfFile: file];
}
else
{
d = [pboard dataForType: fromType];
}
o = [NSDeserializer deserializePropertyListFromData: d
mutableContainers: NO];
if ([o isKindOfClass: [NSString class]] == YES)
if (file != nil)
{
filename = o;
}
else if ([o isKindOfClass: [NSArray class]] == YES
&& [o count] > 0
&& [[o objectAtIndex: 0] isKindOfClass: [NSString class]] == YES)
{
filename = [o objectAtIndex: 0];
filename = file;
}
else
{
[sender setData: [NSData data] forType: type];
return; // Not the name of a file to filter.
}
{
if (data != nil)
{
d = data;
}
else
{
d = [pboard dataForType: fromType];
}
o = [NSDeserializer deserializePropertyListFromData: d
mutableContainers: NO];
if ([o isKindOfClass: [NSString class]] == YES)
{
filename = o;
}
else if ([o isKindOfClass: [NSArray class]] == YES
&& [o count] > 0
&& [[o objectAtIndex: 0] isKindOfClass: [NSString class]] == YES)
{
filename = [o objectAtIndex: 0];
}
else
{
[sender setData: [NSData data] forType: type];
return; // Not the name of a file to filter.
}
}
/*
* Set up and launch task to filter the named file.
@ -1139,12 +1143,12 @@ static NSMapTable *mimeMap = NULL;
{
originalTypes = [NSArray arrayWithObjects:
NSCreateFilenamePboardType(ext),
NSFilenamePboardType,
NSFilenamesPboardType,
nil];
}
else
{
originalTypes = [NSArray arrayWithObject: NSFilenamePboardType];
originalTypes = [NSArray arrayWithObject: NSFilenamesPboardType];
}
types = [GSFiltered _typesFilterableFrom: originalTypes];
p = (GSFiltered*)[GSFiltered pasteboardWithUniqueName];