| 1 |
#ifndef IMGUI_OPEN_FILE_HH |
| 2 |
#define IMGUI_OPEN_FILE_HH |
| 3 |
|
| 4 |
#include "ImGuiPart.hh" |
| 5 |
|
| 6 |
#include <cstdint> |
| 7 |
#include <functional> |
| 8 |
#include <map> |
| 9 |
#include <string> |
| 10 |
|
| 11 |
namespace openmsx { |
| 12 |
|
| 13 |
class ImGuiOpenFile final : public ImGuiPart |
| 14 |
{ |
| 15 |
public: |
| 16 |
enum class Painter : uint8_t { |
| 17 |
MANAGER, |
| 18 |
DISKMANIPULATOR, |
| 19 |
}; |
| 20 |
|
| 21 |
using ImGuiPart::ImGuiPart; |
| 22 |
|
| 23 |
void selectFile(const std::string& title, std::string filters, |
| 24 |
const std::function<void(const std::string&)>& callback, |
| 25 |
zstring_view lastLocationHint = {}, |
| 26 |
Painter painter = Painter::MANAGER); |
| 27 |
void selectNewFile(const std::string& title, std::string filters, |
| 28 |
const std::function<void(const std::string&)>& callback, |
| 29 |
zstring_view lastLocationHint = {}, |
| 30 |
Painter painter = Painter::MANAGER); |
| 31 |
void selectDirectory(const std::string& title, |
| 32 |
const std::function<void(const std::string&)>& callback, |
| 33 |
zstring_view lastLocationHint = {}, |
| 34 |
Painter painter = Painter::MANAGER); |
| 35 |
|
| 36 |
|
| 37 |
static std::string getLastFilter(); |
| 38 |
|
| 39 |
[[nodiscard]] zstring_view iniName() const override { return "open file dialog"; } |
| 40 |
void save(ImGuiTextBuffer& buf) override; |
| 41 |
void loadLine(std::string_view name, zstring_view value) override; |
| 42 |
|
| 43 |
[[nodiscard]] bool mustPaint(Painter p) const { return p == activePainter; } |
| 44 |
void doPaint(); |
| 45 |
|
| 46 |
private: |
| 47 |
void common(const std::string& title, const char* filters, |
| 48 |
const std::function<void(const std::string&)>& callback, |
| 49 |
zstring_view lastLocationHint, |
| 50 |
Painter painter, |
| 51 |
int extraFlags); |
| 52 |
void setBookmarks(); |
| 53 |
[[nodiscard]] std::string getStartPath(zstring_view lastLocationHint); |
| 54 |
|
| 55 |
private: |
| 56 |
std::map<std::string, std::string, std::less<>> lastPath; |
| 57 |
std::string lastTitle; |
| 58 |
std::function<void(const std::string&)> openFileCallback; |
| 59 |
Painter activePainter = Painter::MANAGER; |
| 60 |
bool chooseDirectory = false; |
| 61 |
}; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
#endif |