Skip to content

Commit

Permalink
#5231: Add SetFilterState command, accepting the filter name and the …
Browse files Browse the repository at this point in the history
…state as arguments.
  • Loading branch information
codereader committed May 4, 2020
1 parent a863304 commit 3b64551
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions radiant/filters/BasicFilterSystem.cpp
Expand Up @@ -68,6 +68,26 @@ void BasicFilterSystem::setAllFilterStatesCmd(const cmd::ArgumentList& args)
setAllFilterStates(args.front().getInt() != 0);
}

void BasicFilterSystem::setFilterStateCmd(const cmd::ArgumentList& args)
{
if (args.size() != 2)
{
rMessage() << "Usage: SetFilterState <FilterName> <1|0>" << std::endl;
rMessage() << " an argument value of 1 activates the named filters, 0 deactivates it." << std::endl;
return;
}

std::string filterName = args[0].getString();

if (_availableFilters.find(filterName) == _availableFilters.end())
{
rError() << "Unknown filter: " << filterName << std::endl;
return;
}

setFilterState(args[0].getString(), args[1].getInt() != 0);
}

void BasicFilterSystem::selectObjectsByFilterCmd(const cmd::ArgumentList& args)
{
if (args.size() != 1)
Expand Down Expand Up @@ -132,6 +152,11 @@ void BasicFilterSystem::initialiseModule(const ApplicationContext& ctx)
GlobalCommandSystem().addCommand("SetAllFilterStates",
std::bind(&BasicFilterSystem::setAllFilterStatesCmd, this, std::placeholders::_1), { cmd::ARGTYPE_INT });

// Command to activate/deactivate a named filter
GlobalCommandSystem().addCommand("SetFilterState",
std::bind(&BasicFilterSystem::setFilterStateCmd, this, std::placeholders::_1),
{ cmd::ARGTYPE_STRING, cmd::ARGTYPE_INT });

// Register two shortcuts
GlobalCommandSystem().addStatement("ActivateAllFilters", "SetAllFilterStates 1", false);
GlobalCommandSystem().addStatement("DeactivateAllFilters", "SetAllFilterStates 0", false);
Expand Down
1 change: 1 addition & 0 deletions radiant/filters/BasicFilterSystem.h
Expand Up @@ -56,6 +56,7 @@ class BasicFilterSystem :

XmlFilterEventAdapter::Ptr ensureEventAdapter(XMLFilter& filter);

void setFilterStateCmd(const cmd::ArgumentList& args);
void setAllFilterStatesCmd(const cmd::ArgumentList& args);

void selectObjectsByFilterCmd(const cmd::ArgumentList& args);
Expand Down

0 comments on commit 3b64551

Please sign in to comment.