51 lines
No EOL
1.3 KiB
C++
51 lines
No EOL
1.3 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#ifdef PORTALS
|
|
#include <libportal/portal.h>
|
|
#include <libportal/filechooser.h>
|
|
#endif
|
|
#include "imgui.h"
|
|
#include "imfilebrowser.h"
|
|
|
|
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);
|
|
bool open = false;
|
|
#endif
|
|
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();
|
|
FileBrowser(bool save);
|
|
~FileBrowser();
|
|
}; |