From 01b22c1f39ce8a66394cca070c7ee7f530140ce1 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Tue, 2 Aug 2022 20:52:57 +0100 Subject: [PATCH] #401: Brush/Clipper menu items require selected brush --- include/icommandsystem.h | 6 ++++++ radiantcore/brush/BrushModule.cpp | 7 +++---- radiantcore/clipper/Clipper.cpp | 24 +++++++++++++++--------- radiantcore/clipper/Clipper.h | 5 ++--- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/icommandsystem.h b/include/icommandsystem.h index c039483f85..002ef14e71 100644 --- a/include/icommandsystem.h +++ b/include/icommandsystem.h @@ -213,6 +213,12 @@ typedef std::vector ArgumentList; */ typedef std::function Function; +/// Convert a zero-argument function into a Function by discarding the ArgumentList +template Function noArgs(F f) +{ + return [f](const ArgumentList&) { f(); }; +} + /** * @brief Signature for a function which can test if a particular command should * be enabled. diff --git a/radiantcore/brush/BrushModule.cpp b/radiantcore/brush/BrushModule.cpp index 105870c473..47005fda4b 100644 --- a/radiantcore/brush/BrushModule.cpp +++ b/radiantcore/brush/BrushModule.cpp @@ -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, diff --git a/radiantcore/clipper/Clipper.cpp b/radiantcore/clipper/Clipper.cpp index c1a0f05da9..b42d121d75 100644 --- a/radiantcore/clipper/Clipper.cpp +++ b/radiantcore/clipper/Clipper.cpp @@ -14,6 +14,7 @@ #include "SplitAlgorithm.h" #include "brush/csg/CSG.h" #include "debugging/debugging.h" +#include "selectionlib.h" #include @@ -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 clipperModule; diff --git a/radiantcore/clipper/Clipper.h b/radiantcore/clipper/Clipper.h index 9b9e599e69..519a1fbe30 100644 --- a/radiantcore/clipper/Clipper.h +++ b/radiantcore/clipper/Clipper.h @@ -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