Skip to content

Commit

Permalink
#5231: Replace direct calls to wxutil::MessageBox from CSG algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Aug 1, 2020
1 parent 867c7e6 commit a37db0c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
28 changes: 22 additions & 6 deletions libs/messages/NotificationMessage.h
Expand Up @@ -21,16 +21,32 @@ class NotificationMessage :
};

private:
std::string _title;
std::string _message;

Type _type;

public:
NotificationMessage(const std::string& message, Type type) :
NotificationMessage(std::string(), message, type)
{}

NotificationMessage(const std::string& title, const std::string& message, Type type) :
_title(title),
_message(message),
_type(type)
{}

const std::string& getTitle() const
{
return _title;
}

bool hasTitle() const
{
return !_title.empty();
}

const std::string& getMessage() const
{
return _message;
Expand All @@ -47,21 +63,21 @@ class NotificationMessage :
}

// Convenience method, creating an instance and dispatching it to the message bus
static void SendInformation(const std::string& message)
static void SendInformation(const std::string& message, const std::string& title = std::string())
{
NotificationMessage msg(message, Information);
NotificationMessage msg(title, message, Information);
GlobalRadiantCore().getMessageBus().sendMessage(msg);
}

static void SendWarning(const std::string& message)
static void SendWarning(const std::string& message, const std::string& title = std::string())
{
NotificationMessage msg(message, Warning);
NotificationMessage msg(title, message, Warning);
GlobalRadiantCore().getMessageBus().sendMessage(msg);
}

static void SendError(const std::string& message)
static void SendError(const std::string& message, const std::string& title = std::string())
{
NotificationMessage msg(message, Error);
NotificationMessage msg(title, message, Error);
GlobalRadiantCore().getMessageBus().sendMessage(msg);
}
};
Expand Down
11 changes: 8 additions & 3 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -227,13 +227,18 @@ void UserInterfaceModule::HandleNotificationMessage(radiant::NotificationMessage
switch (msg.getType())
{
case radiant::NotificationMessage::Information:
wxutil::Messagebox::Show(_("Notification"), msg.getMessage(), IDialog::MessageType::MESSAGE_CONFIRM, parentWindow);
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Notification"),
msg.getMessage(), IDialog::MessageType::MESSAGE_CONFIRM, parentWindow);
break;

case radiant::NotificationMessage::Warning:
wxutil::Messagebox::Show(_("Warning"), msg.getMessage(), IDialog::MessageType::MESSAGE_WARNING, parentWindow);
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Warning"),
msg.getMessage(), IDialog::MessageType::MESSAGE_WARNING, parentWindow);
break;

case radiant::NotificationMessage::Error:
wxutil::Messagebox::Show(_("Error"), msg.getMessage(), IDialog::MessageType::MESSAGE_ERROR, parentWindow);
wxutil::Messagebox::Show(msg.hasTitle() ? msg.getTitle() : _("Error"),
msg.getMessage(), IDialog::MessageType::MESSAGE_ERROR, parentWindow);
break;
};
}
Expand Down
39 changes: 19 additions & 20 deletions radiantcore/brush/csg/CSG.cpp
Expand Up @@ -17,12 +17,14 @@
#include "brush/BrushNode.h"
#include "brush/BrushVisit.h"
#include "selection/algorithm/Primitives.h"
#include "messages/NotificationMessage.h"
#include "command/ExecutionNotPossible.h"

#include "wxutil/dialog/MessageBox.h"
#include "wxutil/dialog/MessageBox.h"
namespace brush
{

namespace brush {
namespace algorithm {
namespace algorithm
{

const std::string RKEY_EMIT_CSG_SUBTRACT_WARNING("user/ui/brush/emitCSGSubtractWarning");

Expand Down Expand Up @@ -271,10 +273,11 @@ void subtractBrushesFromUnselected(const cmd::ArgumentList& args)
{
if (registry::getValue<bool>(RKEY_EMIT_CSG_SUBTRACT_WARNING))
{
wxutil::Messagebox::Show(_("This Is Not Dromed Warning"),
radiant::NotificationMessage::SendInformation(
_("Note: be careful when using the CSG tool, as you might end up\n"
"with an unnecessary number of tiny brushes and/or leaks.\n"
"This popup will not be shown again."), ui::IDialog::MESSAGE_CONFIRM);
"This popup will not be shown again."),
_("This Is Not Dromed Warning"));

// Disable this warning
registry::setValue(RKEY_EMIT_CSG_SUBTRACT_WARNING, false);
Expand All @@ -283,10 +286,9 @@ void subtractBrushesFromUnselected(const cmd::ArgumentList& args)
// Collect all selected brushes
BrushPtrVector brushes = selection::algorithm::getSelectedBrushes();

if (brushes.empty()) {
rMessage() << _("CSG Subtract: No brushes selected.") << std::endl;
wxutil::Messagebox::ShowError(_("CSG Subtract: No brushes selected."));
return;
if (brushes.empty())
{
throw cmd::ExecutionNotPossible(_("CSG Subtract: No brushes selected."));
}

rMessage() << "CSG Subtract: Subtracting " << brushes.size() << " brushes.\n";
Expand Down Expand Up @@ -394,16 +396,14 @@ void mergeSelectedBrushes(const cmd::ArgumentList& args)
// Get the current selection
BrushPtrVector brushes = selection::algorithm::getSelectedBrushes();

if (brushes.empty()) {
rMessage() << _("CSG Merge: No brushes selected.") << std::endl;
wxutil::Messagebox::ShowError(_("CSG Merge: No brushes selected."));
return;
if (brushes.empty())
{
throw cmd::ExecutionNotPossible(_("CSG Merge: No brushes selected."));
}

if (brushes.size() < 2) {
rMessage() << "CSG Merge: At least two brushes have to be selected.\n";
wxutil::Messagebox::ShowError("CSG Merge: At least two brushes have to be selected.");
return;
if (brushes.size() < 2)
{
throw cmd::ExecutionNotPossible("CSG Merge: At least two brushes have to be selected.");
}

rMessage() << "CSG Merge: Merging " << brushes.size() << " brushes." << std::endl;
Expand Down Expand Up @@ -431,8 +431,7 @@ void mergeSelectedBrushes(const cmd::ArgumentList& args)
// Attempt to merge the selected brushes into the new one
if (!Brush_merge(*brush, brushes, true))
{
rWarning() << "CSG Merge: Failed - result would not be convex." << std::endl;
return;
throw cmd::ExecutionFailure(_("CSG Merge: Failed - result would not be convex"));
}

ASSERT_MESSAGE(!brush->empty(), "brush left with no faces after merge");
Expand Down

0 comments on commit a37db0c

Please sign in to comment.