2023-07-17 12:21:38 -07:00
|
|
|
#pragma once
|
2023-07-20 14:45:35 -07:00
|
|
|
#include "config.h"
|
2023-07-17 12:21:38 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <optional>
|
2024-04-24 09:59:51 -07:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
#include <emscripten.h>
|
|
|
|
#endif
|
2023-07-17 12:21:38 -07:00
|
|
|
#ifdef PORTALS
|
|
|
|
#include <libportal/portal.h>
|
|
|
|
#include <libportal/filechooser.h>
|
|
|
|
#endif
|
2024-03-23 18:41:26 -07:00
|
|
|
#include "imgui/imgui.h"
|
|
|
|
#include "imgui-filebrowser/imfilebrowser.h"
|
2023-07-17 12:21:38 -07:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using std::optional;
|
|
|
|
using namespace std::filesystem;
|
|
|
|
|
|
|
|
class FileBrowser {
|
|
|
|
#ifdef PORTALS
|
|
|
|
XdpPortal *portal;
|
|
|
|
GVariant *variant = NULL;
|
|
|
|
GVariantType *type = NULL;
|
|
|
|
GVariantType *inner_filter_type = NULL;
|
|
|
|
GMainLoop *main_loop;
|
|
|
|
GMainContext *main_context;
|
|
|
|
static void FileBrowserOpenCallback(GObject *src, GAsyncResult *res, gpointer data);
|
|
|
|
static void FileBrowserSaveCallback(GObject *src, GAsyncResult *res, gpointer data);
|
|
|
|
#endif
|
2024-04-24 09:59:51 -07:00
|
|
|
ImGuiFileBrowserFlags flags;
|
2023-07-17 14:56:02 -07:00
|
|
|
optional<ImVec2> window_pos;
|
|
|
|
ImVec2 window_size;
|
|
|
|
bool open = false;
|
2023-07-17 12:21:38 -07:00
|
|
|
bool save;
|
|
|
|
ImGui::FileBrowser fallback;
|
|
|
|
path pwd;
|
|
|
|
string filter_name;
|
|
|
|
vector<string> filters;
|
|
|
|
string title;
|
|
|
|
optional<path> selected;
|
|
|
|
public:
|
|
|
|
void SetTitle(string title);
|
|
|
|
void SetTypeFilters(string name, vector<string> filters);
|
|
|
|
void SetPwd(path path);
|
|
|
|
bool HasSelected();
|
|
|
|
path GetSelected();
|
|
|
|
void SetWindowSize(int width, int height);
|
|
|
|
void SetWindowPos(int x, int y);
|
|
|
|
void Display();
|
|
|
|
void Open();
|
|
|
|
void ClearSelected();
|
|
|
|
bool IsOpened();
|
2023-07-17 14:56:02 -07:00
|
|
|
FileBrowser(bool save, ImGuiFileBrowserFlags extra_fallback_flags = 0);
|
2023-07-17 12:21:38 -07:00
|
|
|
~FileBrowser();
|
|
|
|
};
|