Skip to content

Commit

Permalink
#401: Brush/Clipper menu items require selected brush
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Aug 2, 2022
1 parent fc7807d commit 01b22c1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
6 changes: 6 additions & 0 deletions include/icommandsystem.h
Expand Up @@ -213,6 +213,12 @@ typedef std::vector<Argument> ArgumentList;
*/
typedef std::function<void (const ArgumentList&)> Function;

/// Convert a zero-argument function into a Function by discarding the ArgumentList
template <typename F> Function noArgs(F f)
{
return [f](const ArgumentList&) { f(); };
}

/**
* @brief Signature for a function which can test if a particular command should
* be enabled.
Expand Down
7 changes: 3 additions & 4 deletions radiantcore/brush/BrushModule.cpp
Expand Up @@ -146,10 +146,9 @@ void BrushModuleImpl::registerBrushCommands()
GlobalCommandSystem().addCommand("BrushMakeSided", selection::algorithm::brushMakeSided, { cmd::ARGTYPE_INT });

GlobalCommandSystem().addCommand("TextureNatural", selection::algorithm::naturalTexture);
GlobalCommandSystem().addWithCheck(
"MakeVisportal", [](const cmd::ArgumentList&) { selection::algorithm::makeVisportal(); },
selection::pred::haveSelectedBrush
);
GlobalCommandSystem().addWithCheck("MakeVisportal",
cmd::noArgs(selection::algorithm::makeVisportal),
selection::pred::haveSelectedBrush);
GlobalCommandSystem().addCommand("SurroundWithMonsterclip", selection::algorithm::surroundWithMonsterclip);

GlobalCommandSystem().addCommand("ResizeSelectedBrushesToBounds", selection::algorithm::resizeSelectedBrushesToBounds,
Expand Down
24 changes: 15 additions & 9 deletions radiantcore/clipper/Clipper.cpp
Expand Up @@ -14,6 +14,7 @@
#include "SplitAlgorithm.h"
#include "brush/csg/CSG.h"
#include "debugging/debugging.h"
#include "selectionlib.h"

#include <functional>

Expand Down Expand Up @@ -280,28 +281,33 @@ void Clipper::initialiseModule(const IApplicationContext& ctx)
constructPreferences();

// Register the clip commands
GlobalCommandSystem().addCommand("ClipSelected", std::bind(&Clipper::clipSelectionCmd, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("SplitSelected", std::bind(&Clipper::splitSelectedCmd, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("FlipClip", std::bind(&Clipper::flipClipperCmd, this, std::placeholders::_1));
auto haveSomethingToClip = [this] {
return clipMode() && selection::pred::haveSelectedBrush();
};
GlobalCommandSystem().addWithCheck(
"ClipSelected", cmd::noArgs([this] { clipSelectionCmd(); }), haveSomethingToClip
);
GlobalCommandSystem().addWithCheck(
"SplitSelected", cmd::noArgs([this] { splitSelectedCmd(); }), haveSomethingToClip
);
GlobalCommandSystem().addWithCheck(
"FlipClip", cmd::noArgs([this] { flipClip(); }), haveSomethingToClip
);
}

void Clipper::clipSelectionCmd(const cmd::ArgumentList& args) {
void Clipper::clipSelectionCmd() {
if (clipMode()) {
UndoableCommand undo("clipperClip");
clip();
}
}

void Clipper::splitSelectedCmd(const cmd::ArgumentList& args) {
void Clipper::splitSelectedCmd() {
if (clipMode()) {
UndoableCommand undo("clipperSplit");
splitClip();
}
}

void Clipper::flipClipperCmd(const cmd::ArgumentList& args) {
flipClip();
}

// Define the static Clipper module
module::StaticModuleRegistration<Clipper> clipperModule;
5 changes: 2 additions & 3 deletions radiantcore/clipper/Clipper.h
Expand Up @@ -82,9 +82,8 @@ class Clipper final :
void initialiseModule(const IApplicationContext& ctx) override;

// Command targets
void clipSelectionCmd(const cmd::ArgumentList& args);
void splitSelectedCmd(const cmd::ArgumentList& args);
void flipClipperCmd(const cmd::ArgumentList& args);
void clipSelectionCmd();
void splitSelectedCmd();

}; // class Clipper

0 comments on commit 01b22c1

Please sign in to comment.