Qt: remove "Search [______]" from Help menu

Prevent Qt from inserting an extra entry in the Help dropdown
menu displayed in the menu bar across the top of the screen
when nethack has focus.  "Search [______]" lets the user enter
a string to search for but doesn't give nethack any control
over that so we can't have it.

I haven't found a sane way to get rid of it.  The insane way
of not naming any menu "Help" works.  This uses "\177Help" so
that it still looks like "Help" but won't match that string.
This commit is contained in:
PatR
2020-12-13 13:45:04 -08:00
parent c1b0f4e47a
commit 04724fc5a0
3 changed files with 24 additions and 7 deletions

View File

@@ -781,7 +781,28 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
info->setTitle("Info");
menubar->addMenu(info);
menubar->addSeparator();
#ifndef MACOSX
help->setTitle("Help");
#else
// On OSX, an entry in the menubar called "Help" will get an
// extra action, "Search [______]", inserted as the first entry.
// We have no control over what it does and don't want it.
//
// Using actions() to fetch a list of all entries doesn't find it,
// so we don't have its widget pointer to pass to removeAction().
//
// Altering the name with an invisible character to inhibit
// string matching is ludicrous but keeps the unwanted action
// from getting inserted into the "Help" menu behind our back.
// Underscore works too and is more robust but unless we prepend
// it to every entry, "_Help" would stand out as strange.
help->setTitle("\177Help");
// (Renaming back to "Help" after the fact does reset the menu's
// name but it also results in the Search action being added.
// Perhaps a custom context menu that changes its name to "Help"
// as it is being shown--and possibly changes back afterward--
// would work but the name mangling hack is much simpler.)
#endif
menubar->addMenu(help);
}