Fix file filters in Mac file-open dialogs

This commit is contained in:
Henrik Rydgård 2023-07-16 15:22:04 +02:00
parent de20a5692f
commit 0ae2f5ccbf
4 changed files with 44 additions and 20 deletions

View File

@ -244,7 +244,8 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
}
};
DarwinFileSystemServices services;
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false);
BrowseFileType fileType = (BrowseFileType)param3;
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false, fileType);
return true;
}
case SystemRequestType::BROWSE_FOR_FOLDER:

View File

@ -9,6 +9,7 @@
#include "ppsspp_config.h"
#include "Common/File/Path.h"
#include "Common/System/Request.h"
#define PreferredMemoryStickUserDefaultsKey "UserPreferredMemoryStickDirectoryPath"
@ -18,18 +19,20 @@ typedef std::function<void (bool, Path)> DarwinDirectoryPanelCallback;
/// on Darwin platforms.
class DarwinFileSystemServices {
public:
/// Present a pannel to choose the directory as the memory stick manager.
void presentDirectoryPanel(DarwinDirectoryPanelCallback,
bool allowFiles = false,
bool allowDirectories = true);
static Path appropriateMemoryStickDirectoryToUse();
static void setUserPreferredMemoryStickDirectory(Path);
/// Present a panel to choose a file or directory.
void presentDirectoryPanel(
DarwinDirectoryPanelCallback,
bool allowFiles = false,
bool allowDirectories = true,
BrowseFileType fileType = BrowseFileType::ANY);
static Path appropriateMemoryStickDirectoryToUse();
static void setUserPreferredMemoryStickDirectory(Path);
private:
static Path __defaultMemoryStickPath();
static Path __defaultMemoryStickPath();
#if PPSSPP_PLATFORM(IOS)
// iOS only, needed for UIDocumentPickerViewController
void *__pickerDelegate = NULL;
// iOS only, needed for UIDocumentPickerViewController
void *__pickerDelegate = NULL;
#endif // PPSSPP_PLATFORM(IOS)
};

View File

@ -44,15 +44,35 @@
#include <AppKit/AppKit.h>
#endif // __has_include(<UIKit/UIKit.h>)
void DarwinFileSystemServices::presentDirectoryPanel(DarwinDirectoryPanelCallback callback,
bool allowFiles,
bool allowDirectories) {
dispatch_async(dispatch_get_main_queue(), ^{
void DarwinFileSystemServices::presentDirectoryPanel(
DarwinDirectoryPanelCallback callback,
bool allowFiles, bool allowDirectories,
BrowseFileType fileType) {
dispatch_async(dispatch_get_main_queue(), ^{
#if PPSSPP_PLATFORM(MAC)
NSOpenPanel *panel = [[NSOpenPanel alloc] init];
panel.allowsMultipleSelection = NO;
panel.canChooseFiles = allowFiles;
panel.canChooseDirectories = allowDirectories;
NSOpenPanel *panel = [[NSOpenPanel alloc] init];
panel.allowsMultipleSelection = NO;
panel.canChooseFiles = allowFiles;
panel.canChooseDirectories = allowDirectories;
switch (fileType) {
case BrowseFileType::BOOTABLE:
[panel setAllowedFileTypes:[NSArray arrayWithObjects:@"iso", @"cso", @"pbp", @"elf", @"zip", @"ppdmp", nil]];
break;
case BrowseFileType::IMAGE:
[panel setAllowedFileTypes:[NSArray arrayWithObjects:@"jpg", @"png", nil]];
break;
case BrowseFileType::INI:
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"ini"]];
break;
case BrowseFileType::DB:
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"db"]];
break;
case BrowseFileType::SOUND_EFFECT:
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"wav"]];
break;
default:
break;
}
// if (!allowFiles && allowDirectories)
// panel.allowedFileTypes = @[(__bridge NSString *)kUTTypeFolder];

@ -1 +1 @@
Subproject commit 73f924f08d3c6ea9cc3ef27b29efaa152d3b3c15
Subproject commit 223df0761313c5c9d9f4d4dc4b5897cf41e7e036