Skip to content

Commit

Permalink
#5231: Algorithms in the core binary can signal command execution fai…
Browse files Browse the repository at this point in the history
…lure by throwing the corresponding exception.

It will be sent across the messagebus where the UI module will receive it as listener, displaying the error message.
  • Loading branch information
codereader committed May 22, 2020
1 parent 2a82983 commit 7993dcd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions radiant/RadiantModule.h
@@ -1,6 +1,7 @@
#pragma once

#include "iradiant.h"
#include "messages/CommandExecutionFailed.h"
#include <memory>

namespace radiant
Expand Down
4 changes: 3 additions & 1 deletion radiant/patch/algorithm/General.cpp
Expand Up @@ -11,6 +11,8 @@
#include "ui/surfaceinspector/SurfaceInspector.h"
#include "selection/algorithm/Primitives.h"

#include "command/ExecutionFailure.h"

namespace patch
{

Expand Down Expand Up @@ -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."));
}
}

Expand Down
14 changes: 14 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -13,6 +13,7 @@

#include "wxutil/menu/CommandMenuItem.h"
#include "wxutil/MultiMonitor.h"
#include "wxutil/dialog/MessageBox.h"

#include "module/StaticModule.h"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -137,6 +139,10 @@ void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx)
_longOperationHandler.reset(new LongRunningOperationHandler);

initialiseEntitySettings();

GlobalRadiantCore().getMessageBus().addListener(
radiant::TypeListener<radiant::CommandExecutionFailedMessage>(
sigc::mem_fun(this, &UserInterfaceModule::handleCommandExecutionFailure)));
}

void UserInterfaceModule::shutdownModule()
Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -8,6 +8,7 @@

#include "EntityClassColourManager.h"
#include "LongRunningOperationHandler.h"
#include "messages/CommandExecutionFailed.h"

namespace ui
{
Expand Down Expand Up @@ -43,6 +44,8 @@ class UserInterfaceModule :
void applyBrushVertexColours();
void applyPatchVertexColours();
void refreshShadersCmd(const cmd::ArgumentList& args);

void handleCommandExecutionFailure(radiant::CommandExecutionFailedMessage& msg);
};

}
12 changes: 6 additions & 6 deletions radiantcore/modulesystem/ModuleRegistry.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 7993dcd

Please sign in to comment.