Skip to content

Commit

Permalink
#4791: Extend default ResourceTreeView context menu by a "Copy Resour…
Browse files Browse the repository at this point in the history
…ce Path" option, defaulting to fullPath, overridable by subclasses.
  • Loading branch information
codereader committed Jan 30, 2021
1 parent 24d0720 commit d82c943
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/version.h
Expand Up @@ -2,7 +2,7 @@
#include <config.h>
#define RADIANT_VERSION PACKAGE_VERSION
#else
#define RADIANT_VERSION "2.11.0"
#define RADIANT_VERSION "2.12.0pre1"
#endif

#define RADIANT_APPNAME "DarkRadiant"
Expand Down
48 changes: 48 additions & 0 deletions libs/wxutil/dataview/ResourceTreeView.cpp
@@ -1,6 +1,7 @@
#include "ResourceTreeView.h"

#include "i18n.h"
#include "iclipboard.h"
#include "iuimanager.h"
#include "ifavourites.h"
#include "../menu/IconTextMenuItem.h"
Expand Down Expand Up @@ -195,6 +196,15 @@ void ResourceTreeView::PopulateContextMenu(wxutil::PopupMenu& popupMenu)
std::bind(&ResourceTreeView::_testRemoveFromFavourites, this),
[this]() { return _declType != decl::Type::None; }
);

popupMenu.addSeparator();

popupMenu.addItem(
new wxutil::StockIconTextMenuItem(_("Copy Resource Path"), wxART_COPY),
std::bind(&ResourceTreeView::_onCopyResourcePath, this),
std::bind(&ResourceTreeView::_copyResourcePathEnabled, this),
std::bind(&ResourceTreeView::_copyResourcePathVisible, this)
);
}

bool ResourceTreeView::SetFilterText(const wxString& filterText)
Expand Down Expand Up @@ -514,6 +524,44 @@ void ResourceTreeView::_onSetFavourite(bool isFavourite)
SetFavouriteRecursively(row, isFavourite);
}

std::string ResourceTreeView::GetResourcePath(const TreeModel::Row& row)
{
return row[_columns.fullName];
}

std::string ResourceTreeView::GetResourcePathOfSelection()
{
wxDataViewItem item = GetSelection();

if (!item.IsOk() || IsDirectorySelected())
{
return std::string();
}

TreeModel::Row row(item, *GetModel());
return GetResourcePath(row);
}

void ResourceTreeView::_onCopyResourcePath()
{
auto resourcePath = GetResourcePathOfSelection();

if (!resourcePath.empty())
{
GlobalClipboard().setString(resourcePath);
}
}

bool ResourceTreeView::_copyResourcePathEnabled()
{
return !GetResourcePathOfSelection().empty();
}

bool ResourceTreeView::_copyResourcePathVisible()
{
return !IsDirectorySelected() && module::GlobalModuleRegistry().moduleExists(MODULE_CLIPBOARD);
}

bool ResourceTreeView::IsDirectorySelected()
{
wxDataViewItem item = GetSelection();
Expand Down
11 changes: 11 additions & 0 deletions libs/wxutil/dataview/ResourceTreeView.h
Expand Up @@ -157,6 +157,14 @@ class ResourceTreeView :

virtual void UpdateTreeVisibility();

// Get the resource path for the given item. Determines the availabilty
// and functionality of the "Copy resource path" context menu item
// The default implementation returns the value of the "fullPath" column.
virtual std::string GetResourcePath(const TreeModel::Row& row);

// Retrieve the resource path of the currently selected item
virtual std::string GetResourcePathOfSelection();

private:
// Returns true if the given row is visible according
// to the current view mode (show favourites vs. show all)
Expand All @@ -172,6 +180,9 @@ class ResourceTreeView :
bool _testAddToFavourites();
bool _testRemoveFromFavourites();
void _onSetFavourite(bool isFavourite);
void _onCopyResourcePath();
bool _copyResourcePathEnabled();
bool _copyResourcePathVisible();
};

// Emitted when the tree view is done populating
Expand Down

0 comments on commit d82c943

Please sign in to comment.