-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5780: Add FileSaveConfirmationHandler to UI module. Map module is no…
…w sending the FileSaveConfirmation to query the user's intent, remove the corresponding UI references from Map.cpp.
- Loading branch information
1 parent
2776128
commit 3d77e54
Showing
6 changed files
with
69 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
#include "idialogmanager.h" | ||
#include "iradiant.h" | ||
#include "i18n.h" | ||
#include "messages/FileSaveConfirmation.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
class FileSaveConfirmationHandler | ||
{ | ||
private: | ||
std::size_t _msgSubscription; | ||
|
||
public: | ||
FileSaveConfirmationHandler() | ||
{ | ||
_msgSubscription = GlobalRadiantCore().getMessageBus().addListener( | ||
radiant::IMessage::Type::FileSaveConfirmation, | ||
radiant::TypeListener<radiant::FileSaveConfirmation>( | ||
sigc::mem_fun(this, &FileSaveConfirmationHandler::handleRequest))); | ||
} | ||
|
||
~FileSaveConfirmationHandler() | ||
{ | ||
GlobalRadiantCore().getMessageBus().removeListener(_msgSubscription); | ||
} | ||
|
||
private: | ||
void handleRequest(radiant::FileSaveConfirmation& msg) | ||
{ | ||
// Ask the user | ||
auto msgBox = GlobalDialogManager().createMessageBox( | ||
msg.getTitle(), msg.getMessage(), | ||
ui::IDialog::MESSAGE_SAVECONFIRMATION | ||
); | ||
|
||
auto result = msgBox->run(); | ||
|
||
msg.setHandled(true); | ||
|
||
switch (result) | ||
{ | ||
case IDialog::RESULT_CANCELLED: | ||
msg.setAction(radiant::FileSaveConfirmation::Action::Cancel); | ||
break; | ||
case IDialog::RESULT_YES: | ||
msg.setAction(radiant::FileSaveConfirmation::Action::SaveChanges); | ||
break; | ||
default: | ||
msg.setAction(radiant::FileSaveConfirmation::Action::DiscardChanges); | ||
} | ||
} | ||
}; | ||
|
||
} |
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