diff --git a/ChangeLog b/ChangeLog index 42148f5d8..c434d641f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-05-31 Wolfgang Lux + + * 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 * Source/NSViewController.m * Headers/AppKit/NSViewController.h diff --git a/Source/NSDocument.m b/Source/NSDocument.m index 363462da5..136707398 100644 --- a/Source/NSDocument.m +++ b/Source/NSDocument.m @@ -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 @""; diff --git a/Source/NSDocumentController.m b/Source/NSDocumentController.m index 1b17d68b9..8bccaa84d 100644 --- a/Source/NSDocumentController.m +++ b/Source/NSDocumentController.m @@ -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; }