mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -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;
|
cocos2d::CCDictionary* getAllLevelsInDict() = mac 0x35e3d0, win 0x18d7c0;
|
||||||
|
|
||||||
PAD = mac 0x10, win 0x1C;
|
PAD = mac 0x4, win 0x1C;
|
||||||
cocos2d::CCDictionary* m_loadData;
|
cocos2d::CCDictionary* m_loadData;
|
||||||
cocos2d::CCDictionary* m_levelData;
|
cocos2d::CCDictionary* m_levelData;
|
||||||
cocos2d::CCArray* m_localLevels;
|
cocos2d::CCArray* m_localLevels;
|
||||||
|
|
|
@ -75,25 +75,14 @@ void utils::web::openLinkInBrowser(std::string const& url) {
|
||||||
|
|
||||||
@implementation FileDialog
|
@implementation FileDialog
|
||||||
+(Result<std::vector<ghc::filesystem::path>>) filePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult {
|
+(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
|
[panel setCanCreateDirectories: TRUE];
|
||||||
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];
|
|
||||||
|
|
||||||
// multiple
|
|
||||||
[panel setAllowsMultipleSelection: mult];
|
|
||||||
|
|
||||||
// default path
|
// default path
|
||||||
if (options.defaultPath) {
|
if (options.defaultPath) {
|
||||||
|
@ -102,8 +91,36 @@ void utils::web::openLinkInBrowser(std::string const& url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// other
|
// other
|
||||||
[panel setCanChooseDirectories: NO];
|
if (mode != file::PickMode::SaveFile) {
|
||||||
[panel setCanChooseFiles: YES];
|
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
|
// run thing
|
||||||
|
|
||||||
|
@ -111,11 +128,16 @@ void utils::web::openLinkInBrowser(std::string const& url) {
|
||||||
|
|
||||||
if (result == NSModalResponseOK) {
|
if (result == NSModalResponseOK) {
|
||||||
std::vector<ghc::filesystem::path> fileURLs;
|
std::vector<ghc::filesystem::path> fileURLs;
|
||||||
|
if (mode == file::PickMode::SaveFile) {
|
||||||
for (NSURL* i in panel.URLs) {
|
fileURLs.push_back(std::string([[[panel URL] path] UTF8String]));
|
||||||
fileURLs.push_back(std::string(i.path.UTF8String));
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
auto openPanel = (NSOpenPanel*)panel;
|
||||||
|
|
||||||
|
for (NSURL* i in openPanel.URLs) {
|
||||||
|
fileURLs.push_back(std::string(i.path.UTF8String));
|
||||||
|
}
|
||||||
|
}
|
||||||
return Ok(fileURLs);
|
return Ok(fileURLs);
|
||||||
} else {
|
} else {
|
||||||
return Err("File picker cancelled");
|
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_searchObject, 0x1d8);
|
||||||
GEODE_MEMBER_CHECK(LevelBrowserLayer, m_itemCount, 0x208);
|
GEODE_MEMBER_CHECK(LevelBrowserLayer, m_itemCount, 0x208);
|
||||||
|
|
||||||
|
// LocalLevelManager
|
||||||
|
GEODE_MEMBER_CHECK(LocalLevelManager, m_localLevels, 0x140);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue