]> granicus.if.org Git - nethack/commitdiff
Qt "close window" debacle on OSX
authorPatR <rankin@nethack.org>
Wed, 5 Aug 2020 18:34:56 +0000 (11:34 -0700)
committerPatR <rankin@nethack.org>
Wed, 5 Aug 2020 18:34:56 +0000 (11:34 -0700)
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.

doc/fixes37.0
win/Qt/qt_main.cpp

index 7dcf6459693e39c4fedf32a08b95fb06e3863087..970889489875f70b075e273cbda97555edc7f068 100644 (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
index 4968fc7bf7a641074233c6ee9eac081bb9ed1321..975917e4d7e1c571c9ecca5a336f161aebf428bc 100644 (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();
     }