зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1321321 - Ensure that we always save files with the given extension / Work-around NSSavePanel limitations when saving files with multiple extensions. r=mstange.
This commit is contained in:
Родитель
071e150be8
Коммит
4db4fecd9e
|
@ -458,23 +458,38 @@ nsFilePicker::PutLocalFile(const nsString& inTitle, const nsString& inDefaultNam
|
||||||
// set up default file name
|
// set up default file name
|
||||||
NSString* defaultFilename = [NSString stringWithCharacters:(const unichar*)inDefaultName.get() length:inDefaultName.Length()];
|
NSString* defaultFilename = [NSString stringWithCharacters:(const unichar*)inDefaultName.get() length:inDefaultName.Length()];
|
||||||
|
|
||||||
// set up allowed types; this prevents the extension from being selected
|
// Set up the allowed type. This prevents the extension from being selected.
|
||||||
// use the UTI for the file type to allow alternate extensions (e.g., jpg vs. jpeg)
|
|
||||||
NSString* extension = defaultFilename.pathExtension;
|
NSString* extension = defaultFilename.pathExtension;
|
||||||
if (extension.length != 0) {
|
if (extension.length != 0) {
|
||||||
CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)extension, NULL);
|
thePanel.allowedFileTypes = @[extension];
|
||||||
|
|
||||||
if (type) {
|
|
||||||
thePanel.allowedFileTypes = @[(NSString*)type];
|
|
||||||
CFRelease(type);
|
|
||||||
} else {
|
|
||||||
// if there's no UTI for the file extension, use the extension itself.
|
|
||||||
thePanel.allowedFileTypes = @[extension];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Allow users to change the extension.
|
// Allow users to change the extension.
|
||||||
thePanel.allowsOtherFileTypes = YES;
|
thePanel.allowsOtherFileTypes = YES;
|
||||||
|
|
||||||
|
// If extensions are hidden and we’re saving a file with multiple extensions,
|
||||||
|
// only the last extension will be hidden in the panel (".tar.gz" will become
|
||||||
|
// ".tar"). If the remaining extension is known, the OS will think that we're
|
||||||
|
// trying to add a non-default extension. To avoid the confusion, we ensure
|
||||||
|
// that all extensions are shown in the panel if the remaining extension is
|
||||||
|
// known by the OS.
|
||||||
|
NSString* fileName =
|
||||||
|
[[defaultFilename lastPathComponent] stringByDeletingPathExtension];
|
||||||
|
NSString* otherExtension = fileName.pathExtension;
|
||||||
|
if (otherExtension.length != 0) {
|
||||||
|
// There's another extension here. Get the UTI.
|
||||||
|
CFStringRef type =
|
||||||
|
UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
|
||||||
|
(CFStringRef)otherExtension, NULL);
|
||||||
|
if (type) {
|
||||||
|
if (!CFStringHasPrefix(type, CFSTR("dyn."))) {
|
||||||
|
// We have a UTI, otherwise the type would have a "dyn." prefix. Ensure
|
||||||
|
// extensions are shown in the panel.
|
||||||
|
[thePanel setExtensionHidden:NO];
|
||||||
|
}
|
||||||
|
CFRelease(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set up default directory
|
// set up default directory
|
||||||
NSString *theDir = PanelDefaultDirectory();
|
NSString *theDir = PanelDefaultDirectory();
|
||||||
if (theDir) {
|
if (theDir) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче