mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-30 03:15:38 -05:00
implement save and open panel
This commit is contained in:
parent
5b9e8a7467
commit
4ad8b486ff
3 changed files with 48 additions and 23 deletions
|
@ -4144,7 +4144,7 @@ class LocalLevelManager : GManager {
|
|||
|
||||
cocos2d::CCDictionary* getAllLevelsInDict() = mac 0x35e3d0, win 0x18d7c0;
|
||||
|
||||
PAD = mac 0x10, win 0x1C;
|
||||
PAD = mac 0x4, win 0x1C;
|
||||
cocos2d::CCDictionary* m_loadData;
|
||||
cocos2d::CCDictionary* m_levelData;
|
||||
cocos2d::CCArray* m_localLevels;
|
||||
|
|
|
@ -75,25 +75,14 @@ void utils::web::openLinkInBrowser(std::string const& url) {
|
|||
|
||||
@implementation FileDialog
|
||||
+(Result<std::vector<ghc::filesystem::path>>) filePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult {
|
||||
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
||||
NSSavePanel* panel;
|
||||
if (mode == file::PickMode::SaveFile)
|
||||
panel = [NSSavePanel savePanel];
|
||||
else
|
||||
panel = [NSOpenPanel openPanel];
|
||||
|
||||
// allowed files
|
||||
NSMutableArray* allowed = [NSMutableArray array];
|
||||
[panel setCanCreateDirectories: TRUE];
|
||||
|
||||
for (auto& f : options.filters) {
|
||||
for (auto& i : f.files) {
|
||||
auto nsstr = [NSString stringWithUTF8String: i.c_str()];
|
||||
|
||||
if (![allowed containsObject: nsstr])
|
||||
[allowed addObject: nsstr];
|
||||
}
|
||||
}
|
||||
|
||||
if (options.filters.size())
|
||||
[panel setAllowedFileTypes: allowed];
|
||||
|
||||
// multiple
|
||||
[panel setAllowsMultipleSelection: mult];
|
||||
|
||||
// default path
|
||||
if (options.defaultPath) {
|
||||
|
@ -102,8 +91,36 @@ void utils::web::openLinkInBrowser(std::string const& url) {
|
|||
}
|
||||
|
||||
// other
|
||||
[panel setCanChooseDirectories: NO];
|
||||
[panel setCanChooseFiles: YES];
|
||||
if (mode != file::PickMode::SaveFile) {
|
||||
auto openPanel = (NSOpenPanel*)panel;
|
||||
|
||||
if (mode == file::PickMode::OpenFile){
|
||||
[openPanel setCanChooseDirectories: NO];
|
||||
[openPanel setCanChooseFiles: YES];
|
||||
}
|
||||
else {
|
||||
[openPanel setCanChooseDirectories: YES];
|
||||
[openPanel setCanChooseFiles: NO];
|
||||
}
|
||||
|
||||
[openPanel setAllowsMultipleSelection: mult];
|
||||
|
||||
// allowed files
|
||||
// TODO: allowed files using the NSOpenSavePanelDelegate xd
|
||||
// NSMutableArray* allowed = [NSMutableArray array];
|
||||
|
||||
// for (auto& f : options.filters) {
|
||||
// for (auto& i : f.files) {
|
||||
// auto nsstr = [NSString stringWithUTF8String: i.c_str()];
|
||||
|
||||
// if (![allowed containsObject: nsstr])
|
||||
// [allowed addObject: nsstr];
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (options.filters.size())
|
||||
// [panel setAllowedFileTypes: allowed];
|
||||
}
|
||||
|
||||
// run thing
|
||||
|
||||
|
@ -111,11 +128,16 @@ void utils::web::openLinkInBrowser(std::string const& url) {
|
|||
|
||||
if (result == NSModalResponseOK) {
|
||||
std::vector<ghc::filesystem::path> fileURLs;
|
||||
|
||||
for (NSURL* i in panel.URLs) {
|
||||
fileURLs.push_back(std::string(i.path.UTF8String));
|
||||
if (mode == file::PickMode::SaveFile) {
|
||||
fileURLs.push_back(std::string([[[panel URL] path] UTF8String]));
|
||||
}
|
||||
else {
|
||||
auto openPanel = (NSOpenPanel*)panel;
|
||||
|
||||
for (NSURL* i in openPanel.URLs) {
|
||||
fileURLs.push_back(std::string(i.path.UTF8String));
|
||||
}
|
||||
}
|
||||
return Ok(fileURLs);
|
||||
} else {
|
||||
return Err("File picker cancelled");
|
||||
|
|
|
@ -72,4 +72,7 @@ GEODE_MEMBER_CHECK(LevelBrowserLayer, m_leftArrow, 0x1a8);
|
|||
GEODE_MEMBER_CHECK(LevelBrowserLayer, m_searchObject, 0x1d8);
|
||||
GEODE_MEMBER_CHECK(LevelBrowserLayer, m_itemCount, 0x208);
|
||||
|
||||
// LocalLevelManager
|
||||
GEODE_MEMBER_CHECK(LocalLevelManager, m_localLevels, 0x140);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue