Skip to content

Commit

Permalink
#5127: Add "Create Speaker" context menu options to favourites browser
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 24, 2021
1 parent 4518031 commit f19486d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions radiant/ui/favourites/FavouritesBrowser.cpp
Expand Up @@ -5,6 +5,7 @@
#include "igroupdialog.h"
#include "iuimanager.h"
#include "imainframe.h"
#include "icommandsystem.h"

#include <wx/artprov.h>
#include <wx/toolbar.h>
Expand Down Expand Up @@ -32,6 +33,9 @@ namespace
const char* const ADD_ENTITY_TEXT = N_("Create entity");
const char* const ADD_ENTITY_ICON = "cmenu_add_entity.png";

const char* const ADD_SPEAKER_TEXT = N_("Create speaker");
const char* const ADD_SPEAKER_ICON = "icon_sound.png";

const char* const REMOVE_FROM_FAVOURITES = N_("Remove from Favourites");
}

Expand Down Expand Up @@ -98,6 +102,12 @@ void FavouritesBrowser::constructPopupMenu()
std::bind(&FavouritesBrowser::testCreateEntity, this)
);

_popupMenu->addItem(
new wxutil::IconTextMenuItem(_(ADD_SPEAKER_TEXT), ADD_SPEAKER_ICON),
std::bind(&FavouritesBrowser::onCreateSpeaker, this),
std::bind(&FavouritesBrowser::testCreateSpeaker, this)
);

_popupMenu->addItem(
new wxutil::StockIconTextMenuItem(_(REMOVE_FROM_FAVOURITES), wxART_DEL_BOOKMARK),
std::bind(&FavouritesBrowser::onRemoveFromFavourite, this),
Expand Down Expand Up @@ -327,6 +337,9 @@ void FavouritesBrowser::onItemActivated(wxListEvent& ev)
case decl::Type::EntityDef:
onCreateEntity();
break;
case decl::Type::SoundShader:
onCreateSpeaker();
break;
}
}

Expand Down Expand Up @@ -416,6 +429,11 @@ bool FavouritesBrowser::testCreateEntity()
return false;
}

return selectionAllowsEntityCreation();
}

bool FavouritesBrowser::selectionAllowsEntityCreation()
{
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

bool anythingSelected = info.totalCount > 0;
Expand All @@ -426,6 +444,31 @@ bool FavouritesBrowser::testCreateEntity()
return !anythingSelected || onlyPrimitivesSelected;
}

void FavouritesBrowser::onCreateSpeaker()
{
if (!testCreateSpeaker()) return;

auto selection = getSelectedItems();

if (selection.size() != 1) return;

auto* data = reinterpret_cast<FavouriteItem*>(_listView->GetItemData(selection.front()));

GlobalCommandSystem().executeCommand("CreateSpeaker", {
cmd::Argument(data->fullPath), cmd::Argument(GlobalXYWndManager().getActiveViewOrigin())
});
}

bool FavouritesBrowser::testCreateSpeaker()
{
if (getSelectedDeclType() != decl::Type::SoundShader)
{
return false;
}

return selectionAllowsEntityCreation();
}

module::StaticModule<FavouritesBrowser> favouritesBrowserModule;

}
4 changes: 4 additions & 0 deletions radiant/ui/favourites/FavouritesBrowser.h
Expand Up @@ -86,6 +86,10 @@ class FavouritesBrowser :
bool testSingleTextureSelected();
void onCreateEntity();
bool testCreateEntity();
void onCreateSpeaker();
bool testCreateSpeaker();

bool selectionAllowsEntityCreation();
};

}

0 comments on commit f19486d

Please sign in to comment.