Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5440: Add FileOverwriteConfirmation message. An unhandled message wi…
…ll cancel the save process.
- Loading branch information
1 parent
04ae576
commit e836a29
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
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,70 @@ | ||
#pragma once | ||
|
||
#include <stdexcept> | ||
#include "imessagebus.h" | ||
#include "iradiant.h" | ||
|
||
namespace radiant | ||
{ | ||
|
||
/** | ||
* Message sent when the backend code wants the user to | ||
* confirm overwriting a file. | ||
* Senders: If this message stays unresponded no overwrite should occur. | ||
*/ | ||
class FileOverwriteConfirmation : | ||
public radiant::IMessage | ||
{ | ||
private: | ||
std::string _title; | ||
std::string _message; | ||
|
||
bool _confirmed; | ||
|
||
public: | ||
FileOverwriteConfirmation(const std::string& title, const std::string& message) : | ||
_title(title), | ||
_message(message) | ||
{} | ||
|
||
const std::string& getTitle() const | ||
{ | ||
return _title; | ||
} | ||
|
||
bool hasTitle() const | ||
{ | ||
return !_title.empty(); | ||
} | ||
|
||
const std::string& getMessage() const | ||
{ | ||
return _message; | ||
} | ||
|
||
std::size_t getId() const override | ||
{ | ||
return IMessage::Type::FileOverwriteConfirmation; | ||
} | ||
|
||
void confirmOverwrite(bool confirmed = true) | ||
{ | ||
_confirmed = confirmed; | ||
} | ||
|
||
bool overwriteConfirmed() | ||
{ | ||
return isHandled() && _confirmed; | ||
} | ||
|
||
// Convenience method, creating an instance and dispatching it to the message bus, returning the answer | ||
static bool SendAndReceiveAnswer(const std::string& message, const std::string& title = std::string()) | ||
{ | ||
FileOverwriteConfirmation msg(title, message); | ||
GlobalRadiantCore().getMessageBus().sendMessage(msg); | ||
|
||
return msg.overwriteConfirmed(); | ||
} | ||
}; | ||
|
||
} |
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