diff --git a/radiant/RadiantModule.h b/radiant/RadiantModule.h index b5abe14989..bec8d7e615 100644 --- a/radiant/RadiantModule.h +++ b/radiant/RadiantModule.h @@ -1,6 +1,7 @@ #pragma once #include "iradiant.h" +#include "messages/CommandExecutionFailed.h" #include namespace radiant diff --git a/radiant/patch/algorithm/General.cpp b/radiant/patch/algorithm/General.cpp index f920c96617..7793daee39 100644 --- a/radiant/patch/algorithm/General.cpp +++ b/radiant/patch/algorithm/General.cpp @@ -11,6 +11,8 @@ #include "ui/surfaceinspector/SurfaceInspector.h" #include "selection/algorithm/Primitives.h" +#include "command/ExecutionFailure.h" + namespace patch { @@ -154,7 +156,7 @@ void bulge(const cmd::ArgumentList& args) } else { - wxutil::Messagebox::ShowError(_("Cannot bulge patch. No patches selected.")); + throw cmd::ExecutionFailure(_("Cannot bulge patch. No patches selected.")); } } diff --git a/radiant/ui/UserInterfaceModule.cpp b/radiant/ui/UserInterfaceModule.cpp index dff0f9da9b..decaafc85e 100644 --- a/radiant/ui/UserInterfaceModule.cpp +++ b/radiant/ui/UserInterfaceModule.cpp @@ -13,6 +13,7 @@ #include "wxutil/menu/CommandMenuItem.h" #include "wxutil/MultiMonitor.h" +#include "wxutil/dialog/MessageBox.h" #include "module/StaticModule.h" @@ -76,6 +77,7 @@ const StringSet& UserInterfaceModule::getDependencies() const _dependencies.insert(MODULE_FILTERSYSTEM); _dependencies.insert(MODULE_ENTITY); _dependencies.insert(MODULE_EVENTMANAGER); + _dependencies.insert(MODULE_RADIANT_CORE); } return _dependencies; @@ -137,6 +139,10 @@ void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx) _longOperationHandler.reset(new LongRunningOperationHandler); initialiseEntitySettings(); + + GlobalRadiantCore().getMessageBus().addListener( + radiant::TypeListener( + sigc::mem_fun(this, &UserInterfaceModule::handleCommandExecutionFailure))); } void UserInterfaceModule::shutdownModule() @@ -148,6 +154,14 @@ void UserInterfaceModule::shutdownModule() _eClassColourManager.reset(); } +void UserInterfaceModule::handleCommandExecutionFailure(radiant::CommandExecutionFailedMessage& msg) +{ + auto parentWindow = module::GlobalModuleRegistry().moduleExists(MODULE_MAINFRAME) ? + GlobalMainFrame().getWxTopLevelWindow() : nullptr; + + wxutil::Messagebox::ShowError(msg.getMessage(), parentWindow); +} + void UserInterfaceModule::initialiseEntitySettings() { auto& settings = GlobalEntityModule().getSettings(); diff --git a/radiant/ui/UserInterfaceModule.h b/radiant/ui/UserInterfaceModule.h index 31ba13d9d7..23c411fb68 100644 --- a/radiant/ui/UserInterfaceModule.h +++ b/radiant/ui/UserInterfaceModule.h @@ -8,6 +8,7 @@ #include "EntityClassColourManager.h" #include "LongRunningOperationHandler.h" +#include "messages/CommandExecutionFailed.h" namespace ui { @@ -43,6 +44,8 @@ class UserInterfaceModule : void applyBrushVertexColours(); void applyPatchVertexColours(); void refreshShadersCmd(const cmd::ArgumentList& args); + + void handleCommandExecutionFailure(radiant::CommandExecutionFailedMessage& msg); }; } diff --git a/radiantcore/modulesystem/ModuleRegistry.cpp b/radiantcore/modulesystem/ModuleRegistry.cpp index 7680714dec..33956d8b83 100644 --- a/radiantcore/modulesystem/ModuleRegistry.cpp +++ b/radiantcore/modulesystem/ModuleRegistry.cpp @@ -98,18 +98,18 @@ void ModuleRegistry::registerModule(const RegisterableModulePtr& module) // Initialise the module (including dependencies, if necessary) void ModuleRegistry::initialiseModuleRecursive(const std::string& name) { - // Check if the module exists at all - if (_uninitialisedModules.find(name) == _uninitialisedModules.end()) - { - throw std::logic_error("ModuleRegistry: Module doesn't exist: " + name); - } - // Check if the module is already initialised if (_initialisedModules.find(name) != _initialisedModules.end()) { return; } + // Check if the module exists at all + if (_uninitialisedModules.find(name) == _uninitialisedModules.end()) + { + throw std::logic_error("ModuleRegistry: Module doesn't exist: " + name); + } + // Tag this module as "ready" by moving it into the initialised list. RegisterableModulePtr module = _initialisedModules.emplace(name, _uninitialisedModules[name]).first->second; const StringSet& dependencies = module->getDependencies();