/
ResourceTreeView.h
135 lines (104 loc) · 4.25 KB
/
ResourceTreeView.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#pragma once
#include "idecltypes.h"
#include "TreeView.h"
#include "TreeModel.h"
#include "TreeModelFilter.h"
#include "IResourceTreePopulator.h"
#include "../menu/PopupMenu.h"
namespace wxutil
{
/**
* A specialised tree view for display resources like materials,
* prefabs, sound shaders and the like. It defines the default Column set
* to use for any treestore that is associated to this view - this set can
* be derived from and extended to display more sophisticated models.
*
* This tree control supports two "modes", one showing all elements in the tree,
* and the other showing favourites only: see getTreeMode()/setTreeMode().
*
* It ships with a context menu that can be customised by subclasses,
* to extend the default actions aimed at managing favourites.
*/
class ResourceTreeView :
public TreeView
{
public:
// The base structure defining a few needed default column.
// Subclasses may derive from this struct to expand it
struct Columns :
public TreeModel::ColumnRecord
{
Columns() :
iconAndName(add(TreeModel::Column::IconText)),
leafName(add(TreeModel::Column::String)),
fullName(add(TreeModel::Column::String)),
isFolder(add(TreeModel::Column::Boolean)),
isFavourite(add(TreeModel::Column::Boolean))
{}
TreeModel::Column iconAndName;
TreeModel::Column leafName; // name without parent folders
TreeModel::Column fullName; // name including parent folders
TreeModel::Column isFolder;
TreeModel::Column isFavourite;
};
// Filter modes used by this tree view
enum class TreeMode
{
ShowAll,
ShowFavourites,
};
private:
// Context menu
PopupMenuPtr _popupMenu;
const Columns& _columns;
TreeMode _mode;
TreeModel::Ptr _treeStore;
TreeModelFilter::Ptr _treeModelFilter;
wxDataViewItem _emptyFavouritesLabel;
wxDataViewItem _progressItem;
// The currently active populator object
IResourceTreePopulator::Ptr _populator;
bool _expandTopLevelItemsAfterPopulation;
std::string _fullNameToSelectAfterPopulation;
std::vector<ui::IMenuItemPtr> _customMenuItems;
decl::Type _declType;
public:
ResourceTreeView(wxWindow* parent, const Columns& columns, long style = wxDV_SINGLE);
ResourceTreeView(wxWindow* parent, const TreeModel::Ptr& model, const Columns& columns, long style = wxDV_SINGLE);
virtual ~ResourceTreeView();
// Returns a reference to the model we're using
virtual const TreeModel::Ptr& GetTreeModel();
virtual void SetTreeModel(const TreeModel::Ptr& treeModel);
virtual TreeMode GetTreeMode() const;
virtual void SetTreeMode(TreeMode mode);
// Returns the full name of the selection (or an empty string)
virtual std::string GetSelectedFullname();
virtual void SetSelectedFullname(const std::string& fullName);
virtual void Clear();
// Enable favourite management for the given declaration type
virtual void EnableFavouriteManagement(decl::Type declType);
// Disable favourite management features
virtual void DisableFavouriteManagement();
virtual bool IsDirectorySelected();
virtual bool IsFavouriteSelected();
// Populate this tree using the given populator object
virtual void Populate(const IResourceTreePopulator::Ptr& populator);
void SetExpandTopLevelItemsAfterPopulation(bool expand);
// Add a custom menu item to this control's popup menu (will be added at the top)
// Client code that derive from this class can use the protected PopulateContextMenu
// hook as an alternative to this method.
void AddCustomMenuItem(const ui::IMenuItemPtr& item);
protected:
virtual void PopulateContextMenu(wxutil::PopupMenu& popupMenu);
virtual void SetFavouriteRecursively(TreeModel::Row& row, bool isFavourite);
virtual void SetupTreeModelFilter();
virtual bool IsTreeModelRowVisible(TreeModel::Row& row);
private:
void _onContextMenu(wxDataViewEvent& ev);
void _onTreeStorePopulationProgress(TreeModel::PopulationProgressEvent& ev);
void _onTreeStorePopulationFinished(TreeModel::PopulationFinishedEvent& ev);
bool _testAddToFavourites();
bool _testRemoveFromFavourites();
void _onSetFavourite(bool isFavourite);
};
}