Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5231: Add a message type to signal the start and finish of a long-ru…
…nning operation. The UI can and will react to this by showing a blocking window on top of the mainframe.
- Loading branch information
1 parent
3123992
commit 4698288
Showing
15 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include "imessagebus.h" | ||
|
||
namespace radiant | ||
{ | ||
|
||
enum class OperationEvent | ||
{ | ||
Started, | ||
Finished, | ||
}; | ||
|
||
/** | ||
* Message object sent to the MessageBus when one of the | ||
* modules are performing a long-running operation. | ||
* | ||
* UI modules can react to this by showing a blocking | ||
* window, depending on the event type as returned by getType(). | ||
* | ||
* See also ScopedLongRunningOperation.h | ||
*/ | ||
class LongRunningOperationMessage : | ||
public radiant::IMessage | ||
{ | ||
private: | ||
OperationEvent _event; | ||
|
||
std::string _title; | ||
|
||
public: | ||
LongRunningOperationMessage(OperationEvent ev) : | ||
LongRunningOperationMessage(ev, std::string()) | ||
{} | ||
|
||
LongRunningOperationMessage(OperationEvent ev, const std::string& title) : | ||
_event(ev), | ||
_title(title) | ||
{} | ||
|
||
OperationEvent getType() const | ||
{ | ||
return _event; | ||
} | ||
|
||
const std::string& getTitle() const | ||
{ | ||
return _title; | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "iradiant.h" | ||
#include "LongRunningOperationMessage.h" | ||
#include "util/Noncopyable.h" | ||
|
||
namespace radiant | ||
{ | ||
|
||
/** | ||
* Scoped helper class dispatching a LongRunningOperationMessage | ||
* to DarkRadiant's message bus. The constructor will send | ||
* the Started event, the destructor will do the Finished part | ||
*/ | ||
class ScopedLongRunningOperation : | ||
public util::Noncopyable | ||
{ | ||
public: | ||
ScopedLongRunningOperation(const std::string& title) | ||
{ | ||
LongRunningOperationMessage started(OperationEvent::Started, title); | ||
GlobalRadiantCore().getMessageBus().sendMessage(started); | ||
} | ||
|
||
~ScopedLongRunningOperation() | ||
{ | ||
LongRunningOperationMessage finished(OperationEvent::Finished); | ||
GlobalRadiantCore().getMessageBus().sendMessage(finished); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include "iradiant.h" | ||
#include "imainframe.h" | ||
#include "messages/LongRunningOperationMessage.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
/** | ||
* Listener class responding to LongRunningOperationMessages | ||
* sent from the core routines. It will show a blocking dialog | ||
* when any operation is started, and will hide that window | ||
* once the last running operation is finished. | ||
*/ | ||
class LongRunningOperationHandler | ||
{ | ||
private: | ||
std::size_t _level; | ||
|
||
IScopedScreenUpdateBlockerPtr _blocker; | ||
|
||
public: | ||
LongRunningOperationHandler() : | ||
_level(0) | ||
{ | ||
GlobalRadiantCore().getMessageBus().addListener( | ||
radiant::TypeListener<radiant::LongRunningOperationMessage>( | ||
std::bind(&LongRunningOperationHandler::onMessage, this, std::placeholders::_1) | ||
) | ||
); | ||
} | ||
|
||
private: | ||
void onMessage(radiant::LongRunningOperationMessage& message) | ||
{ | ||
if (message.getType() == radiant::OperationEvent::Started) | ||
{ | ||
std::string title = message.getTitle(); | ||
|
||
if (title.empty()) | ||
{ | ||
title = _("Operation in progress"); | ||
} | ||
|
||
if (++_level == 1) | ||
{ | ||
_blocker = GlobalMainFrame().getScopedScreenUpdateBlocker(title, std::string()); | ||
} | ||
} | ||
else if (message.getType() == radiant::OperationEvent::Finished) | ||
{ | ||
assert(_level > 0); | ||
|
||
if (_level > 0 && --_level == 0) | ||
{ | ||
_blocker.reset(); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters