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:
PatR
2020-08-05 11:34:56 -07:00
parent f4cee951ca
commit addebf7090
2 changed files with 32 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.272 $ $NHDT-Date: 1596651973 2020/08/05 18:26:13 $
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.273 $ $NHDT-Date: 1596652492 2020/08/05 18:34:52 $
General Fixes and Modified Features
-----------------------------------
@@ -351,6 +351,11 @@ Qt: don't disable [cancel] button when viewing inventory or other pick-none
menus; ESC works to dismiss those and [cancel] should be the same
Qt: bring status conditions up to 3.6 levels but new ones lack pictures
Qt: fix control key on OSX
Qt: clicking on the window's Close button brought up a dialog offering
choices of "Save" and "Cancel"; picking Cancel sent nethack into an
infinite loop with complaints about Qt's event loop already being
active; change dialog: offer "Save and exit" or "Quit without saving"
with no opportunity to try to back out of the Close operation
tiles: add indicator of thonged portion to aklys tile
tty: role and race selection menus weren't filtering out potential choices
which got excluded by OPTIONS=align:!lawful or !neutral or !chaotic

View File

@@ -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();
}