Add macOS default file loader, windows WIP

This commit is contained in:
scawful
2023-11-24 13:33:46 -05:00
parent 72151c4b43
commit 11b6af94ff
2 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
#include <string>
#ifdef _WIN32
// Include Windows-specific headers
#include <shobjidl.h>
#include <windows.h>
std::string ShowOpenFileDialog() {
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
IFileDialog *pfd = NULL;
HRESULT hr =
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileDialog,
reinterpret_cast<void **>(&pfd));
if (SUCCEEDED(hr)) {
// Show the dialog
hr = pfd->Show(NULL);
if (SUCCEEDED(hr)) {
IShellItem *psiResult;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr)) {
// Get the file path
PWSTR pszFilePath;
psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
psiResult->Release();
CoTaskMemFree(pszFilePath);
}
}
pfd->Release();
}
CoUninitialize();
return L""; // Return an empty string if no file was selected or an error
}
#elif defined(__APPLE__)
#include <string>
class FileDialogWrapper {
public:
static std::string ShowOpenFileDialog();
};
#elif defined(__linux__)
#include <gtk/gtk.h>
std::string ShowOpenFileDialog() {
// Linux-specific file dialog implementation using GTK
// ...
return "file_path_linux";
}
#else
#error "Unsupported platform."
#endif

View File

@@ -0,0 +1,17 @@
#import <Cocoa/Cocoa.h>
#include "app/core/platform/file_dialog.h"
std::string FileDialogWrapper::ShowOpenFileDialog() {
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseFiles:YES];
[openPanel setCanChooseDirectories:NO];
[openPanel setAllowsMultipleSelection:NO];
if ([openPanel runModal] == NSModalResponseOK) {
NSURL* url = [[openPanel URLs] objectAtIndex:0];
NSString* path = [url path];
return std::string([path UTF8String]);
}
return "";
}