Add support for document types with a wild card extension to

NSDocumentController and NSDocument.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30512 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2010-05-31 21:40:13 +00:00
parent 79ac03cdf1
commit fc76fad1a0
3 changed files with 38 additions and 4 deletions

View file

@ -1,3 +1,11 @@
2010-05-31 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSDocumentController.m (-_openableFileExtensions,
-typeFromFileExtension:):
* Source/NSDocument.m (-_runSavePanelForSaveOperation:,
-changeSaveType:, -fileNameExtensionForType:saveOperation:):
Implement support for document types with a wild card extension.
2010-05-31 David Wetzel <dave@turbocat.de>
* Source/NSViewController.m
* Headers/AppKit/NSViewController.h

View file

@ -1052,6 +1052,8 @@ originalContentsURL: (NSURL *)orig
ASSIGN(_save_type, [[sender selectedItem] representedObject]);
extensions = [controller fileExtensionsFromType: _save_type];
if ([extensions containsObject: @"*"])
extensions = nil;
[(NSSavePanel *)[sender window] setAllowedFileTypes: extensions];
}
@ -1157,6 +1159,8 @@ originalContentsURL: (NSURL *)orig
if ([types count] > 0)
{
NSArray *extensions = [controller fileExtensionsFromType: [self fileType]];
if ([extensions containsObject: @"*"])
extensions = nil;
[savePanel setAllowedFileTypes: extensions];
}
@ -1272,7 +1276,7 @@ originalContentsURL: (NSURL *)orig
NSArray *exts = [[NSDocumentController sharedDocumentController]
fileExtensionsFromType: typeName];
if ([exts count])
if ([exts count] && ![exts containsObject: @"*"])
return (NSString *)[exts objectAtIndex: 0];
return @"";

View file

@ -769,7 +769,7 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
[array addObjectsFromArray: [typeInfo objectForKey: CFBundleTypeExtensions]];
}
return array;
return [array containsObject: @"*"] == NO ? (NSArray *)array : (NSArray *)nil;
}
/** Uses -runModalOpenPanel:forTypes: to allow the user to select
@ -1215,7 +1215,8 @@ static BOOL _shouldClose = YES;
- (NSString *) typeFromFileExtension: (NSString *)fileExtension
{
int i, count = [_types count];
// Check for a document type with the supplied extension
for (i = 0; i < count; i++)
{
NSDictionary *typeInfo = [_types objectAtIndex: i];
@ -1236,7 +1237,28 @@ static BOOL _shouldClose = YES;
return type;
}
}
// No exact match; check for a document type that supports any extension
for (i = 0; i < count; i++)
{
NSDictionary *typeInfo = [_types objectAtIndex: i];
if ([[typeInfo objectForKey: NSUnixExtensionsKey] containsObject: @"*"]
|| [[typeInfo objectForKey: NSDOSExtensionsKey] containsObject: @"*"]
|| [[typeInfo objectForKey: CFBundleTypeExtensions]
containsObject: @"*"])
{
NSString *type = [typeInfo objectForKey: NSNameKey];
if (type == nil)
{
type = [typeInfo objectForKey: CFBundleTypeName];
}
return type;
}
}
// No luck
return nil;
}