diff --git a/Frameworks/OakFileBrowser/src/io/FSDataSource.mm b/Frameworks/OakFileBrowser/src/io/FSDataSource.mm index 839e8aff..f0e37faa 100644 --- a/Frameworks/OakFileBrowser/src/io/FSDataSource.mm +++ b/Frameworks/OakFileBrowser/src/io/FSDataSource.mm @@ -10,6 +10,7 @@ #import #import #import +#import #import #import #import @@ -102,8 +103,24 @@ static ino_t inode (std::string const& path) std::string src = [[item.url path] fileSystemRepresentation]; std::string dst = path::join(path::parent(src), [[objectValue stringByReplacingOccurrencesOfString:@"/" withString:@":"] fileSystemRepresentation]); - if(path::info(src) & path::flag::hidden_extension) // FIXME files with multiple extenions have the “hidden_extension” flag ignored - dst += path::extension(src); // TODO replicate Finder’s heuristic for toggling “extension hidden” flag + + // “hidden extension” is ignored if Finder is set to show all file extensions, if there are multiple extensions, or if no application is assigned to the extension. + std::string const baseName = path::name(src); + std::string const displayName = to_s(item.name); + bool hiddenExtension = baseName != displayName && (path::info(src) & path::flag::hidden_extension); + + if(src == dst && hiddenExtension) + { + NSURL* dstURL = [NSURL fileURLWithPath:[NSString stringWithCxxString:dst]]; + NSError* error; + if(![dstURL setResourceValue:@NO forKey:NSURLHasHiddenExtensionKey error:&error]) + NSLog(@"%s %@", sel_getName(_cmd), error); + + return; + } + + if(hiddenExtension) + dst += path::extension(src); if(src != dst) {