openMSX
ImGuiOpenFile.hh
Go to the documentation of this file.
1#ifndef IMGUI_OPEN_FILE_HH
2#define IMGUI_OPEN_FILE_HH
3
4#include "ImGuiPart.hh"
5
6#include <functional>
7#include <map>
8#include <string>
9
10namespace openmsx {
11
12class ImGuiOpenFile final : public ImGuiPart
13{
14public:
15 enum class Painter {
16 MANAGER,
18 };
19
21
22 void selectFile(const std::string& title, std::string filters,
23 const std::function<void(const std::string&)>& callback,
24 zstring_view lastLocationHint = {},
25 Painter painter = Painter::MANAGER);
26 void selectNewFile(const std::string& title, std::string filters,
27 const std::function<void(const std::string&)>& callback,
28 zstring_view lastLocationHint = {},
29 Painter painter = Painter::MANAGER);
30 void selectDirectory(const std::string& title,
31 const std::function<void(const std::string&)>& callback,
32 zstring_view lastLocationHint = {},
33 Painter painter = Painter::MANAGER);
34
35 // should be called from within a callback of the methods above
36 static std::string getLastFilter();
37
38 [[nodiscard]] zstring_view iniName() const override { return "open file dialog"; }
39 void save(ImGuiTextBuffer& buf) override;
40 void loadLine(std::string_view name, zstring_view value) override;
41
42 [[nodiscard]] bool mustPaint(Painter p) const { return p == activePainter; }
43 void doPaint();
44
45private:
46 void common(const std::string& title, const char* filters,
47 const std::function<void(const std::string&)>& callback,
48 zstring_view lastLocationHint,
49 Painter painter,
50 int extraFlags);
51 void setBookmarks();
52 [[nodiscard]] std::string getStartPath(zstring_view lastLocationHint);
53
54private:
55 std::map<std::string, std::string, std::less<>> lastPath;
56 std::string lastTitle;
57 std::function<void(const std::string&)> openFileCallback;
58 Painter activePainter = Painter::MANAGER;
59 bool chooseDirectory = false;
60};
61
62} // namespace openmsx
63
64#endif
zstring_view iniName() const override
void loadLine(std::string_view name, zstring_view value) override
void selectNewFile(const std::string &title, std::string filters, const std::function< void(const std::string &)> &callback, zstring_view lastLocationHint={}, Painter painter=Painter::MANAGER)
void selectFile(const std::string &title, std::string filters, const std::function< void(const std::string &)> &callback, zstring_view lastLocationHint={}, Painter painter=Painter::MANAGER)
bool mustPaint(Painter p) const
static std::string getLastFilter()
void selectDirectory(const std::string &title, const std::function< void(const std::string &)> &callback, zstring_view lastLocationHint={}, Painter painter=Painter::MANAGER)
void save(ImGuiTextBuffer &buf) override
ImGuiPart(ImGuiManager &manager_)
Definition ImGuiPart.hh:12
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
Definition Autofire.cc:11