mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 20:50:38 +00:00
* 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:
parent
4efb00ae4c
commit
0bf9693431
3 changed files with 108 additions and 43 deletions
|
@ -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>
|
2012-02-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSPasteboard.m: ([+pasteboardByFilteringFile:]) fixed to
|
* Source/NSPasteboard.m: ([+pasteboardByFilteringFile:]) fixed to
|
||||||
|
|
|
@ -203,6 +203,7 @@ implement, so we can't do that. */
|
||||||
{
|
{
|
||||||
NSString *ext;
|
NSString *ext;
|
||||||
Class rep;
|
Class rep;
|
||||||
|
NSData* data;
|
||||||
|
|
||||||
// Is the file extension already the file type?
|
// Is the file extension already the file type?
|
||||||
ext = [filename pathExtension];
|
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.
|
/* With no extension, we can't tell the type from the file name.
|
||||||
Use the data instead. */
|
Use the data instead. */
|
||||||
NSData *data;
|
|
||||||
data = [NSData dataWithContentsOfFile: filename];
|
data = [NSData dataWithContentsOfFile: filename];
|
||||||
return [self _imageRepsWithData: data];
|
return [self _imageRepsWithData: data];
|
||||||
}
|
}
|
||||||
|
@ -227,20 +227,45 @@ implement, so we can't do that. */
|
||||||
else
|
else
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
{
|
// filter non-native types to native format
|
||||||
NSData* data;
|
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];
|
// Convert the native types to pasteboard types
|
||||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
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];
|
return [rep imageRepsWithData: data];
|
||||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
}
|
||||||
{
|
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||||
NSImageRep *imageRep = [rep imageRepWithData: data];
|
{
|
||||||
|
NSImageRep *imageRep = [rep imageRepWithData: data];
|
||||||
if (imageRep != nil)
|
|
||||||
return [NSArray arrayWithObject: imageRep];
|
if (imageRep != nil)
|
||||||
}
|
return [NSArray arrayWithObject: imageRep];
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -339,8 +364,35 @@ implement, so we can't do that. */
|
||||||
|
|
||||||
+ (NSArray *) imageFileTypes
|
+ (NSArray *) imageFileTypes
|
||||||
{
|
{
|
||||||
// FIXME: We should check what conversions are defined by services.
|
NSArray *nativeTypes = [self imageUnfilteredFileTypes];
|
||||||
return [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
|
+ (NSArray *) imagePasteboardTypes
|
||||||
|
|
|
@ -747,36 +747,40 @@ static NSString *namePrefix = @"NSTypedFilenamesPboardType:";
|
||||||
[sender setData: [NSData data] forType: type];
|
[sender setData: [NSData data] forType: type];
|
||||||
return; // Not the name of a file to filter.
|
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
|
if (file != nil)
|
||||||
mutableContainers: NO];
|
|
||||||
if ([o isKindOfClass: [NSString class]] == YES)
|
|
||||||
{
|
{
|
||||||
filename = o;
|
filename = file;
|
||||||
}
|
|
||||||
else if ([o isKindOfClass: [NSArray class]] == YES
|
|
||||||
&& [o count] > 0
|
|
||||||
&& [[o objectAtIndex: 0] isKindOfClass: [NSString class]] == YES)
|
|
||||||
{
|
|
||||||
filename = [o objectAtIndex: 0];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[sender setData: [NSData data] forType: type];
|
if (data != nil)
|
||||||
return; // Not the name of a file to filter.
|
{
|
||||||
}
|
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.
|
* Set up and launch task to filter the named file.
|
||||||
|
@ -1139,12 +1143,12 @@ static NSMapTable *mimeMap = NULL;
|
||||||
{
|
{
|
||||||
originalTypes = [NSArray arrayWithObjects:
|
originalTypes = [NSArray arrayWithObjects:
|
||||||
NSCreateFilenamePboardType(ext),
|
NSCreateFilenamePboardType(ext),
|
||||||
NSFilenamePboardType,
|
NSFilenamesPboardType,
|
||||||
nil];
|
nil];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
originalTypes = [NSArray arrayWithObject: NSFilenamePboardType];
|
originalTypes = [NSArray arrayWithObject: NSFilenamesPboardType];
|
||||||
}
|
}
|
||||||
types = [GSFiltered _typesFilterableFrom: originalTypes];
|
types = [GSFiltered _typesFilterableFrom: originalTypes];
|
||||||
p = (GSFiltered*)[GSFiltered pasteboardWithUniqueName];
|
p = (GSFiltered*)[GSFiltered pasteboardWithUniqueName];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue