OXYGENHUB
◆ main openmsx / src / imgui / FileListWidget.hh
1.8 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef FILE_LIST_WIDGET_HH
2
#define FILE_LIST_WIDGET_HH
3
4
#include "ImGuiUtils.hh"
5
6
#include <ctime>
7
#include <functional>
8
#include <string>
9
#include <string_view>
10
11
namespace openmsx {
12
13
class FileListWidget {
14
public:
15
	FileListWidget(std::string_view fileType_, std::string_view extension_, std::string_view directory_);
16
	// returns whether the menu is open
17
	bool menu(const char* text);
18
	// returns whether the menu is open
19
	bool menu(const char* text, bool enabled);
20
	void drawTable();
21
22
public:
23
	struct Entry {
24
		std::string fullName;
25
		std::time_t ftime;
26
		// this just returns the file name without path and extension
27
		std::string_view getDefaultDisplayName() const;
28
	};
29
30
	// calls FileOperations::unlink(entry.fullName);
31
	static void defaultDeleteAction(const Entry& entry);
32
	// shows tooltip with display name of entry (for long names)
33
	void defaultHoverAction(const Entry& entry) const;
34
	// returns the given filename without its extension
35
36
	std::function<void()> drawAction; // default (only) calls drawTable()
37
	std::function<void(const Entry&)> singleClickAction; // MUST be overwritten
38
	std::function<void(const Entry&)> hoverAction; // default calls defaultHoverAction
39
	std::function<void(const Entry&)> doubleClickAction; // default: nothing
40
	std::function<void(const Entry&)> deleteAction; // default calls defaultDeleteAction
41
	std::function<imColor(const Entry&)> displayColor; // default: normal color
42
	std::function<std::string(const Entry&)> displayName; // default: Entry::getDefaultDisplayName()
43
44
private:
45
	void draw();
46
	void scanDirectory();
47
48
private:
49
	std::string_view fileType;
50
	std::string_view extension;
51
	std::string_view directory;
52
	ConfirmDialog confirmDelete;
53
	std::vector<Entry> entries;
54
	bool menuOpen = false;
55
	bool needSort = false;
56
};
57
58
} // namespace openmsx
59
60
#endif