Skip to content

Commit

Permalink
#5127: Add option to prepend custom menu items without having to deri…
Browse files Browse the repository at this point in the history
…ve from ResourceTreeView right away.
  • Loading branch information
codereader committed Jan 2, 2021
1 parent 07ee110 commit 742890e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libs/wxutil/dataview/ResourceTreeView.cpp
Expand Up @@ -134,6 +134,19 @@ void ResourceTreeView::SetTreeMode(ResourceTreeView::TreeMode mode)

void ResourceTreeView::PopulateContextMenu(wxutil::PopupMenu& popupMenu)
{
// Add the pre-registered items first (with an auto-separator)
if (popupMenu.GetMenuItemCount() > 0)
{
popupMenu.addSeparator();
}

for (const auto& customItem : _customMenuItems)
{
popupMenu.addItem(customItem);
}

_customMenuItems.clear();

if (popupMenu.GetMenuItemCount() > 0)
{
popupMenu.addSeparator();
Expand Down Expand Up @@ -239,6 +252,11 @@ void ResourceTreeView::SetExpandTopLevelItemsAfterPopulation(bool expand)
_expandTopLevelItemsAfterPopulation = expand;
}

void ResourceTreeView::AddCustomMenuItem(const ui::IMenuItemPtr& item)
{
_customMenuItems.push_back(item);
}

void ResourceTreeView::_onTreeStorePopulationFinished(TreeModel::PopulationFinishedEvent& ev)
{
UnselectAll();
Expand Down
7 changes: 7 additions & 0 deletions libs/wxutil/dataview/ResourceTreeView.h
Expand Up @@ -70,6 +70,8 @@ class ResourceTreeView :
bool _expandTopLevelItemsAfterPopulation;
std::string _fullNameToSelectAfterPopulation;

std::vector<ui::IMenuItemPtr> _customMenuItems;

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);
Expand Down Expand Up @@ -97,6 +99,11 @@ class ResourceTreeView :

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);

Expand Down

0 comments on commit 742890e

Please sign in to comment.