Skip to content

Commit

Permalink
#5231: Remove CommandNotAvailableException.h, fall back to the more w…
Browse files Browse the repository at this point in the history
…idely used cmd::ExecutionNotPossible
  • Loading branch information
codereader committed Jul 1, 2020
1 parent 81c5199 commit a829a7f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 89 deletions.
15 changes: 15 additions & 0 deletions libs/command/ExecutionNotPossible.h
Expand Up @@ -19,6 +19,21 @@ class ExecutionNotPossible :
ExecutionNotPossible(const std::string& msg) :
ExecutionFailure(msg)
{}

// Converts a function that is throwing an ExecutionNotPossible
// to one that returns false instead (true if no exception is thrown)
static bool ToBool(const std::function<void()>& func)
{
try
{
func();
return true;
}
catch (ExecutionNotPossible&)
{
return false;
}
}
};

}
3 changes: 2 additions & 1 deletion radiantcore/map/Map.cpp
Expand Up @@ -48,6 +48,7 @@
#include "selection/algorithm/Group.h"
#include "selection/algorithm/Transformation.h"
#include "module/StaticModule.h"
#include "command/ExecutionNotPossible.h"
#include "MapPropertyInfoFileModule.h"

#include <fmt/format.h>
Expand Down Expand Up @@ -620,7 +621,7 @@ void Map::loadPrefabAt(const cmd::ArgumentList& args)
{
selection::algorithm::groupSelected();
}
catch (selection::algorithm::CommandNotAvailableException& ex)
catch (cmd::ExecutionNotPossible& ex)
{
// Ignore grouping errors on prefab insert, just log the message
rError() << "Error grouping the prefab: " << ex.what() << std::endl;
Expand Down
50 changes: 0 additions & 50 deletions radiantcore/selection/algorithm/CommandNotAvailableException.h

This file was deleted.

38 changes: 11 additions & 27 deletions radiantcore/selection/algorithm/Group.cpp
Expand Up @@ -378,23 +378,23 @@ void checkGroupSelectedAvailable()
{
if (!GlobalMapModule().getRoot())
{
throw CommandNotAvailableException(_("No map loaded"));
throw cmd::ExecutionNotPossible(_("No map loaded"));
}

if (GlobalSelectionSystem().Mode() != SelectionSystem::ePrimitive &&
GlobalSelectionSystem().Mode() != SelectionSystem::eGroupPart)
{
throw CommandNotAvailableException(_("Groups can be formed in Primitive and Group Part selection mode only"));
throw cmd::ExecutionNotPossible(_("Groups can be formed in Primitive and Group Part selection mode only"));
}

if (GlobalSelectionSystem().getSelectionInfo().totalCount == 0)
{
throw CommandNotAvailableException(_("Nothing selected, cannot group anything"));
throw cmd::ExecutionNotPossible(_("Nothing selected, cannot group anything"));
}

if (GlobalSelectionSystem().getSelectionInfo().totalCount == 1)
{
throw CommandNotAvailableException(_("Select more than one element to form a group"));
throw cmd::ExecutionNotPossible(_("Select more than one element to form a group"));
return;
}

Expand All @@ -420,7 +420,7 @@ void checkGroupSelectedAvailable()

if (!hasUngroupedNode && groupIds.size() == 1)
{
throw CommandNotAvailableException(_("The selected elements already form a group"));
throw cmd::ExecutionNotPossible(_("The selected elements already form a group"));
}
}

Expand All @@ -445,18 +445,18 @@ void checkUngroupSelectedAvailable()
{
if (!GlobalMapModule().getRoot())
{
throw CommandNotAvailableException(_("No map loaded"));
throw cmd::ExecutionNotPossible(_("No map loaded"));
}

if (GlobalSelectionSystem().Mode() != SelectionSystem::ePrimitive &&
GlobalSelectionSystem().Mode() != SelectionSystem::eGroupPart)
{
throw CommandNotAvailableException(_("Groups can be dissolved in Primitive and Group Part selection mode only"));
throw cmd::ExecutionNotPossible(_("Groups can be dissolved in Primitive and Group Part selection mode only"));
}

if (GlobalSelectionSystem().getSelectionInfo().totalCount == 0)
{
throw CommandNotAvailableException(_("Nothing selected, cannot un-group anything"));
throw cmd::ExecutionNotPossible(_("Nothing selected, cannot un-group anything"));
}

// Check if the current selection already is member of the same group
Expand All @@ -476,7 +476,7 @@ void checkUngroupSelectedAvailable()

if (hasOnlyUngroupedNodes)
{
throw CommandNotAvailableException(_("The selected elements aren't part of any group"));
throw cmd::ExecutionNotPossible(_("The selected elements aren't part of any group"));
}
}

Expand Down Expand Up @@ -527,28 +527,12 @@ void deleteAllSelectionGroupsCmd(const cmd::ArgumentList& args)

void groupSelectedCmd(const cmd::ArgumentList& args)
{
try
{
groupSelected();
}
catch (CommandNotAvailableException& ex)
{
rError() << ex.what() << std::endl;
throw cmd::ExecutionNotPossible(ex.what());
}
groupSelected();
}

void ungroupSelectedCmd(const cmd::ArgumentList& args)
{
try
{
ungroupSelected();
}
catch (CommandNotAvailableException & ex)
{
rError() << ex.what() << std::endl;
throw cmd::ExecutionNotPossible(ex.what());
}
ungroupSelected();
}

} // namespace algorithm
Expand Down
9 changes: 4 additions & 5 deletions radiantcore/selection/algorithm/Group.h
Expand Up @@ -4,7 +4,6 @@
#include "iselection.h"
#include "inode.h"
#include <list>
#include "CommandNotAvailableException.h"

namespace selection
{
Expand Down Expand Up @@ -127,25 +126,25 @@ namespace algorithm

/**
* Groups the currently selected elements.
* Will throw a CommandNotAvailableException if it cannot execute.
* Will throw cmd::ExecutionNotPossible if it cannot execute.
*/
void groupSelected();

/**
* Returns if the groupSelected command is able to execute
* at this point, otherwise throws a CommandNotAvailableException
* at this point, otherwise throws cmd::ExecutionNotPossible
*/
void checkGroupSelectedAvailable();

/**
* Resolve the currently selected group.
* Will throw a CommandNotAvailableException if it cannot execute.
* Will throw cmd::ExecutionNotPossible if it cannot execute.
*/
void ungroupSelected();

/**
* Returns if the ungroupSelected command is able to execute
* at this point, otherwise throws a CommandNotAvailableException.
* at this point, otherwise throws cmd::ExecutionNotPossible.
*/
void checkUngroupSelectedAvailable();

Expand Down
5 changes: 3 additions & 2 deletions radiantcore/selection/group/SelectionGroupModule.cpp
Expand Up @@ -15,6 +15,7 @@
#include "wxutil/menu/MenuItem.h"
#include "wxutil/menu/IconTextMenuItem.h"
#include "module/StaticModule.h"
#include "command/ExecutionNotPossible.h"

namespace selection
{
Expand Down Expand Up @@ -77,13 +78,13 @@ class SelectionGroupModule :
GlobalOrthoContextMenu().addItem(std::make_shared<wxutil::MenuItem>(
new wxutil::IconTextMenuItem(_("Group Selection"), "group_selection.png"),
[]() { algorithm::groupSelected(); },
[]() { return algorithm::CommandNotAvailableException::ToBool(algorithm::checkGroupSelectedAvailable); }),
[]() { return cmd::ExecutionNotPossible::ToBool(algorithm::checkGroupSelectedAvailable); }),
ui::IOrthoContextMenu::SECTION_SELECTION_GROUPS);

GlobalOrthoContextMenu().addItem(std::make_shared<wxutil::MenuItem>(
new wxutil::IconTextMenuItem(_("Ungroup Selection"), "ungroup_selection.png"),
[]() { algorithm::ungroupSelected(); },
[]() { return algorithm::CommandNotAvailableException::ToBool(algorithm::checkUngroupSelectedAvailable); }),
[]() { return cmd::ExecutionNotPossible::ToBool(algorithm::checkUngroupSelectedAvailable); }),
ui::IOrthoContextMenu::SECTION_SELECTION_GROUPS);
}

Expand Down
1 change: 0 additions & 1 deletion tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -940,7 +940,6 @@
<ClInclude Include="..\..\radiantcore\scenegraph\OctreeNode.h" />
<ClInclude Include="..\..\radiantcore\scenegraph\SceneGraph.h" />
<ClInclude Include="..\..\radiantcore\scenegraph\SceneGraphFactory.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\CommandNotAvailableException.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\Curves.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\Entity.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\General.h" />
Expand Down
3 changes: 0 additions & 3 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -1851,9 +1851,6 @@
<ClInclude Include="..\..\radiantcore\selection\TransformationVisitors.h">
<Filter>src\selection</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\algorithm\CommandNotAvailableException.h">
<Filter>src\selection\algorithm</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\algorithm\Curves.h">
<Filter>src\selection\algorithm</Filter>
</ClInclude>
Expand Down

0 comments on commit a829a7f

Please sign in to comment.