Skip to content

Commit

Permalink
#5374: Disable file operation progress messages when exporting the ma…
Browse files Browse the repository at this point in the history
…p selection to a stream (used by Ctrl-C, for instance), to get rid of the progress dialog that is flashing up for a very short amount of time.
  • Loading branch information
codereader committed Nov 3, 2020
1 parent fbe6e4f commit a47dcbd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions radiantcore/map/Map.cpp
Expand Up @@ -816,6 +816,7 @@ void Map::exportSelected(std::ostream& out, const MapFormatPtr& format)
// Create our main MapExporter walker for traversal
auto writer = format->getMapWriter();
MapExporter exporter(*writer, GlobalSceneGraph().root(), out);
exporter.disableProgressMessages();

// Pass the traverseSelected function and start writing selected nodes
exporter.exportMap(GlobalSceneGraph().root(), scene::traverseSelected);
Expand Down
39 changes: 30 additions & 9 deletions radiantcore/map/algorithm/MapExporter.cpp
Expand Up @@ -33,7 +33,8 @@ MapExporter::MapExporter(IMapWriter& writer, const scene::IMapRootNodePtr& root,
_totalNodeCount(nodeCount),
_curNodeCount(0),
_entityNum(0),
_primitiveNum(0)
_primitiveNum(0),
_sendProgressMessages(true)
{
construct();
}
Expand All @@ -48,7 +49,8 @@ MapExporter::MapExporter(IMapWriter& writer, const scene::IMapRootNodePtr& root,
_totalNodeCount(nodeCount),
_curNodeCount(0),
_entityNum(0),
_primitiveNum(0)
_primitiveNum(0),
_sendProgressMessages(true)
{
construct();
}
Expand Down Expand Up @@ -81,8 +83,11 @@ void MapExporter::construct()

void MapExporter::exportMap(const scene::INodePtr& root, const GraphTraversalFunc& traverse)
{
FileOperation startedMsg(FileOperation::Type::Export, FileOperation::Started, _totalNodeCount > 0);
GlobalRadiantCore().getMessageBus().sendMessage(startedMsg);
if (_sendProgressMessages)
{
FileOperation startedMsg(FileOperation::Type::Export, FileOperation::Started, _totalNodeCount > 0);
GlobalRadiantCore().getMessageBus().sendMessage(startedMsg);
}

try
{
Expand Down Expand Up @@ -235,13 +240,26 @@ void MapExporter::onNodeProgress()
float progressFraction = _totalNodeCount > 0 ?
static_cast<float>(_curNodeCount) / static_cast<float>(_totalNodeCount) : 0.0f;

FileOperation msg(FileOperation::Type::Export, FileOperation::Progress, _totalNodeCount > 0, progressFraction);
msg.setText(fmt::format(_("Writing node {0:d}"), _curNodeCount));
if (_sendProgressMessages)
{
FileOperation msg(FileOperation::Type::Export, FileOperation::Progress, _totalNodeCount > 0, progressFraction);
msg.setText(fmt::format(_("Writing node {0:d}"), _curNodeCount));

GlobalRadiantCore().getMessageBus().sendMessage(msg);
GlobalRadiantCore().getMessageBus().sendMessage(msg);
}
}
}

void MapExporter::enableProgressMessages()
{
_sendProgressMessages = true;
}

void MapExporter::disableProgressMessages()
{
_sendProgressMessages = false;
}

void MapExporter::prepareScene()
{
removeOriginFromChildPrimitives(_root);
Expand All @@ -263,8 +281,11 @@ void MapExporter::finishScene()
// Re-evaluate all brushes, to update the Winding calculations
recalculateBrushWindings();

FileOperation finishedMsg(FileOperation::Type::Export, FileOperation::Finished, _totalNodeCount > 0);
GlobalRadiantCore().getMessageBus().sendMessage(finishedMsg);
if (_sendProgressMessages)
{
FileOperation finishedMsg(FileOperation::Type::Export, FileOperation::Finished, _totalNodeCount > 0);
GlobalRadiantCore().getMessageBus().sendMessage(finishedMsg);
}
}

void MapExporter::recalculateBrushWindings()
Expand Down
8 changes: 8 additions & 0 deletions radiantcore/map/algorithm/MapExporter.h
Expand Up @@ -53,6 +53,8 @@ class MapExporter :
std::size_t _entityNum;
std::size_t _primitiveNum;

bool _sendProgressMessages;

public:
// The constructor prepares the scene and the output stream
MapExporter(IMapWriter& writer, const scene::IMapRootNodePtr& root,
Expand All @@ -72,6 +74,12 @@ class MapExporter :
bool pre(const scene::INodePtr& node) override;
void post(const scene::INodePtr& node) override;

// Send FileProgress messages through the MessageBus while exporting
void enableProgressMessages();

// Don't send any progress messages through the MessageBus while exporting
void disableProgressMessages();

private:
// Common code shared by the constructors
void construct();
Expand Down

0 comments on commit a47dcbd

Please sign in to comment.