]> granicus.if.org Git - nethack/commitdiff
Qt menu fixes: mainly Quit
authorPatR <rankin@nethack.org>
Sun, 9 Aug 2020 21:55:05 +0000 (14:55 -0700)
committerPatR <rankin@nethack.org>
Sun, 9 Aug 2020 21:55:05 +0000 (14:55 -0700)
Changes affecting everybody (using Qt):  rename game->Save to
game->Save-and-exit and game->Quit to game->Quit-without-saving.

OSX-specific changes:  add separate nethack->Quit and change
game->Quit-without-saving to game->_Quit-without-saving to prevent
that from being hijacked for the nethack menu.  nethack->Quit menu
entry works.  Command+Q is a keyboard shortcut for it.  They bring
up a menu with choices of "Quit without saving" and "Cancel and
return to game".  It's not the same as the handler for the window
Close button, which used to offer "Save" or "Cancel" (with the
latter triggering an infinite loop) but now offers "Save and exit"
or "Quit without saving".  They don't share any code.  The
game->_Quit-without-saving entry doesn't work; it runs nethack's '?'
command like a bunch of other broken menu entries.  If it did work,
it would give nethack's "Really quit?" prompt and proceed from there.
The "Quit without saving" response for nethack->Quit confirmation
bypasses that and just quits.

Also OSX, add a second 'about' entry.  The first one is hijacked and
added to the nethack menu, the second is help->_About_Qt_NetHack_
and avoids hijacking.  Both nethack->About and help->_About_ bring
up the same dialog box showing version and assorted other info.

A lot of flailing about with for relatively small amount of progress.

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

index 7f5bc138f1f39910bf7f674726317f4df8ce6bcc..869863efcdb55db09ba633e2fd41722f5d814bfa 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.278 $ $NHDT-Date: 1596936095 2020/08/09 01:21:35 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.279 $ $NHDT-Date: 1597010101 2020/08/09 21:55:01 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -362,10 +362,19 @@ Qt: clicking on the window's Close button brought up a dialog offering
        with no opportunity to try to back out of the Close operation
 Qt: add 3.6 status fields Stone, Slime, Strngl, Deaf, Lev, Fly, Ride
 Qt: add Attributes, Overview, and Annotate to the "Info" pull down menu
+Qt: rename menu entries game->Save to game->Save-and-exit and game->Quit
+       to game->Quit-without-saving
 Qt+QSX: fix control key
 Qt+OSX: rename menu entry "nethack->Preferences..." for invoking nethack's
        'O' command to "Game->Run-time options" and entry "Game->Qt settings"
        for making persistent Qt customizations to "nethack->Preferences..."
+Qt+OSX: prevent game->Quit-without-saving from being hijacked for the nethack
+       menu by renaming it game->_Quit-without-saving (OSX only)
+Qt+OSX: add a separate nethack->Quit menu entry with different functionality;
+       Command+Q invokes it
+Qt+OSX: since menu entry help->"About Qt NetHack" gets hijacked and becomes
+       "nethack->About nethack", add a separate help->_About_Qt_NetHack_
+       which stays where intended and brings up the same information
 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 163616d76a485a9148ebf434cd5748bba98ced61..82bdf16ec949557ab9b2e4a019539b280f8efe95 100644 (file)
@@ -578,18 +578,22 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
         { game,    "History",            3, dohistory},
         { game,    "Redraw",             0, doredraw}, // useless
         { game,
-#ifndef MACOSX
-                   "Options",
-#else
-             /* Qt on OSX would rename "Options" to "Preferences..." and
-                move it from intended destination to the application menu */
-                   "Run-time options",
+#ifdef MACOSX
+            /* Qt on OSX would rename "Options" to "Preferences..." and
+               move it from intended destination to the application menu */
+                   "Run-time &" // rely on adjacent string concatenation
 #endif
-                                         3, doset},
+                   "Options",            3, doset},
         { game,    "Explore mode",       3, enter_explore_mode},
         { game,    0, 3},
-        { game,    "Save",               3, dosave},
-        { game,    "Quit",               3, done2},
+        { game,    "Save-and-exit",      3, dosave},
+        { game,
+#ifdef MACOSX
+            /* need something to prevent matching leading "quit"
+               so that it isn't hijacked for the application menu */
+                   "_&"
+#endif
+                   "Quit-without-saving", 3, done2},
 
         { apparel, "Apparel off",        2, doddoremarm},
         { apparel, "Remove many",        1, doddoremarm},
@@ -682,10 +686,12 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
                     "Preferences...",
 #endif
                     this, SLOT(doQtSettings(bool)));
-    /* on OSX, 'about' will end up in the application menu
-       rather than the help menu; at present, just live with that */
-    help->addAction("About Qt NetHack...",this,SLOT(doAbout(bool)));
-    //help->addAction("NetHack Guidebook...",this,SLOT(doGuidebook(bool)));
+    /* on OSX, 'about' will end up in the application menu rather than
+       the help menu (this had trailing "..." but that conflicts with
+       the convention that an elipsis indicates the choice will bring
+       up its own sub-menu) */
+    help->addAction("About Qt NetHack", this, SLOT(doAbout(bool)));
+    //help->addAction("NetHack Guidebook", this, SLOT(doGuidebook(bool)));
     help->addSeparator();
 
     for (i=0; item[i].menu; i++) {
@@ -747,6 +753,21 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
        help->setTitle("Help");
        menubar->addMenu(help);
     }
+#ifdef MACOSX
+    /* for OSX, the attempt above to add "About Qt NetHack" went into
+       the application menu instead of the help menu; we'll add it to
+       the latter now and have two ways to access it; without the
+       leading underscore (or some other spelling variation such as
+       "'bout"), this one would get interceptd too and then evidently
+       be discarded as a duplicate */
+    help->addSeparator();
+    help->addAction("_About_Qt_NetHack_", this, SLOT(doAbout(bool)));
+    /* we also want a "Quit NetHack" entry in the application menu;
+       when "_Quit-without-saving" was called "Quit" it got intercepted
+       for that, but now it needs to be added separately; we'll use a
+       handy menu and let the interception put it in the intended place */
+    game->addAction("Quit NetHack", this, SLOT(doQuit(bool)));
+#endif
 
     QSignalMapper* sm = new QSignalMapper(this);
     connect(sm, SIGNAL(mapped(const QString&)), this, SLOT(doKeys(const QString&)));
@@ -912,6 +933,41 @@ void NetHackQtMainWindow::doAbout(bool)
     QMessageBox::about(this, "About Qt NetHack", aboutMsg());
 }
 
+// on OSX, "quit nethack" has been selected in the application menu or
+// "Command+Q" has been typed -- user is asking to quit the application;
+// unlike with the window's Close button, user has a chance to back out
+void NetHackQtMainWindow::doQuit(bool)
+{
+    // there is a separate Quit-without-saving menu entry in the game menu
+    // that leads to nethack's "Really quit?" prompt; OSX players can use
+    // either one, other implementations only have that other one but this
+    // routine is unconditional in case someone wants to change that
+#ifdef MACOSX
+    QString info;
+    info.sprintf("This will end your NetHack session.%s",
+                 !g.program_state.something_worth_saving ? ""
+                 : "\n(Cancel quitting and use the Save command"
+                   "\nto save your current game.)");
+    /* this is similar to closeEvent but the details are different */
+    int act = QMessageBox::information(this, "NetHack", info,
+                                       "&Quit without saving",
+                                       "&Cancel and return to game",
+                                       0, 1);
+    switch (act) {
+    case 0:
+        // quit -- bypass the prompting preformed by done2()
+        g.program_state.stopprint++;
+        done(QUIT);
+        /*NOTREACHED*/
+        break;
+    case 1:
+        // cancel
+        break; // return to game
+    }
+#endif
+    return;
+}
+
 #if 0 // RLC this isn't used
 void NetHackQtMainWindow::doGuidebook(bool)
 {
@@ -1106,16 +1162,17 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event)
     }
 }
 
-void NetHackQtMainWindow::closeEvent(QCloseEvent* e)
+// game window's Close button has been activated
+void NetHackQtMainWindow::closeEvent(QCloseEvent *e UNUSED)
 {
+    int ok = 0;
     if ( g.program_state.something_worth_saving ) {
-        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);
+                              "This will end your NetHack session.",
+                              "&Save and exit", "&Quit without saving", 0, 1);
        switch (act) {
         case 0:
             // See dosave() function
@@ -1128,17 +1185,15 @@ void NetHackQtMainWindow::closeEvent(QCloseEvent* e)
             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();
+        /* nothing worth saving; just close/quit */
+        ok = 1;
     }
+    /* if !ok, we should try to continue, but we don't... */
+    u.uhp = -1;
+    NetHackQtBind::qt_exit_nhwindows(0);
+    nh_terminate(EXIT_SUCCESS);
 }
 
 void NetHackQtMainWindow::ShowIfReady()
index 2e4a2a5d04f747e386c5cf064cc736ba98a21af8..461a4a471fd7e1754dfd3d4695988d30b7d3b893 100644 (file)
@@ -53,6 +53,7 @@ public slots:
        void doMenuItem(QAction *);
        void doQtSettings(bool);
        void doAbout(bool);
+        void doQuit(bool);
        //RLC void doGuidebook(bool);
        void doKeys(const QString&);