/
Populator.h
83 lines (61 loc) · 1.99 KB
/
Populator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include <wx/thread.h>
#include "ifilesystem.h"
#include "wxutil/VFSTreePopulator.h"
namespace wxutil
{
namespace fsview
{
// Treemodel definition
struct TreeColumns :
public TreeModel::ColumnRecord
{
TreeColumns() :
filename(add(TreeModel::Column::IconText)),
vfspath(add(TreeModel::Column::String)),
isFolder(add(TreeModel::Column::Boolean)),
size(add(TreeModel::Column::String))
{}
TreeModel::Column filename; // e.g. "chair1.pfb"
TreeModel::Column vfspath; // e.g. "prefabs/chair1.pfb"
TreeModel::Column isFolder; // whether this is a folder
TreeModel::Column size; // file size string
};
class Populator :
public wxutil::VFSTreePopulator::Visitor,
public wxThread
{
private:
const TreeColumns& _columns;
// The tree store to populate
wxutil::TreeModel::Ptr _treeStore;
// The event handler to notify on completion
wxEvtHandler* _finishedHandler;
// The helper class, doing the tedious treeview insertion for us.
wxutil::VFSTreePopulator _treePopulator;
wxIcon _fileIcon;
wxIcon _folderIcon;
std::map<std::string, wxIcon> _iconsPerExtension;
std::string _basePath;
std::set<std::string> _fileExtensions;
public:
Populator(const TreeColumns& columns,
wxEvtHandler* finishedHandler,
const std::string& basePath,
const std::set<std::string>& fileExtensions);
~Populator(); // waits for thread to finish
// Returns the base path as used in the constructor
const std::string& GetBasePath() const;
void Populate();
void visit(wxutil::TreeModel& store, wxutil::TreeModel::Row& row,
const std::string& path, bool isExplicit);
void SetDefaultFileIcon(const std::string& fileIcon);
protected:
// Thread entry point
ExitCode Entry();
void visitFile(const vfs::FileInfo& fileInfo);
void SearchForFilesMatchingExtension(const std::string& extension);
const wxIcon& GetIconForFile(const std::string& path);
};
}
}