Qt "close window" debacle on OSX
Prevent an infinite loop that occurred if player clicked on the close window button and then tried to cancel out of that in the dialog it brings up. I don't know whether Qt interface on platforms other than OSX need this but they're getting it. The choices are changed from "Save" or "Cancel" to "Save and exit" or "Quit without saving". Since save allows subsequent restore, not being able to cancel out of the application shutdown should only be an inconvenience. Unresolved issues: I don't know whether there's any other way to bring up that dialog, where Cancel might be a viable choice. If so, handling that might be tricky. Quit should definitely be available as an alterative to Save, but that type of dialog doesn't seem to allow more than two choices. Picking "nethack" from application menu and then "quit nethack" from the resulting pull down menu results in executing nethack's help command (the '?' menu) and then just resumes play.
This commit is contained in:
@@ -1071,21 +1071,33 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event)
|
||||
void NetHackQtMainWindow::closeEvent(QCloseEvent* e)
|
||||
{
|
||||
if ( g.program_state.something_worth_saving ) {
|
||||
switch ( QMessageBox::information( this, "NetHack",
|
||||
"This will end your NetHack session",
|
||||
"&Save", "&Cancel", 0, 1 ) )
|
||||
{
|
||||
case 0:
|
||||
// See dosave() function
|
||||
if (dosave0()) {
|
||||
u.uhp = -1;
|
||||
NetHackQtBind::qt_exit_nhwindows(0);
|
||||
nh_terminate(EXIT_SUCCESS);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
break; // ignore the event
|
||||
int ok = 0;
|
||||
/* this used to offer "Save" and "Cancel"
|
||||
but cancel (ignoring the close attempt) won't work
|
||||
if user has clicked on the window's Close button */
|
||||
int act = QMessageBox::information(this, "NetHack",
|
||||
"This will end your NetHack session",
|
||||
"&Save and exit", "&Quit without saving", 0, 1);
|
||||
switch (act) {
|
||||
case 0:
|
||||
// See dosave() function
|
||||
ok = dosave0();
|
||||
break;
|
||||
case 1:
|
||||
// quit -- bypass the prompting preformed by done2()
|
||||
ok = 1;
|
||||
g.program_state.stopprint++;
|
||||
done(QUIT);
|
||||
/*NOTREACHED*/
|
||||
break;
|
||||
case 2:
|
||||
// cancel -- no longer an alternative
|
||||
break; // ignore the event
|
||||
}
|
||||
/* if !ok, we should try to continue, but we don't... */
|
||||
u.uhp = -1;
|
||||
NetHackQtBind::qt_exit_nhwindows(0);
|
||||
nh_terminate(EXIT_SUCCESS);
|
||||
} else {
|
||||
e->accept();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user