Qt menu sanity

The Qt menu entries which were executing nethack's help command
(the '?' menu) were doing so because their command keystroke was
a meta-character and such characters are being converted to '?'
to indicate an error in conversion to Latin1 character set.  The
old Qt3 code didn't perform any such conversion.

This fix feels fragile because there are two different places
deciding how to disambiguate partial extended commands (the code
for Qt's '#' handling and a new routine in the core).  Qt menus
now send '#' and enough letters to satisfy '#' handling for any
command which uses M-c or has no regular keystroke nor M-c one.
(If it were to send the full extended command name, the letters
after the unambiguous prefix would be left in the input queue to
be processed as subsequent commands.)

There is a fundamental problem that this doesn't address:  if
the player uses BIND directives in the run-time config file, the
Qt menu bindings will break unless the BINDs are all done before
selecting windowtype.  Qt's menu bindings translate a click on
a menu entry into the keystroke used to invoke the corresponding
command, so using BIND to change that after the menus are set up
will result in the wrong commands being executed.
This commit is contained in:
PatR
2020-08-10 07:24:16 -07:00
parent ef9caca4da
commit 264cbed2cc
4 changed files with 79 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 cmd.c $NHDT-Date: 1596498153 2020/08/03 23:42:33 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.421 $ */
/* NetHack 3.7 cmd.c $NHDT-Date: 1597069374 2020/08/10 14:22:54 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.422 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */
@@ -2278,6 +2278,57 @@ int NDECL((*fn));
return '\0';
}
/* return extended command name (without leading '#') for command (*fn)() */
const char *
cmdname_from_func(fn, outbuf, fullname)
int NDECL((*fn));
char outbuf[];
boolean fullname; /* False: just enough to disambiguate */
{
const struct ext_func_tab *extcmd, *cmdptr = 0;
const char *res = 0;
for (extcmd = extcmdlist; extcmd->ef_txt; ++extcmd)
if (extcmd->ef_funct == fn) {
cmdptr = extcmd;
res = cmdptr->ef_txt;
break;
}
if (!res) {
/* make sure output buffer doesn't contain junk or stale data;
return Null below */
outbuf[0] = '\0';
} else if (fullname) {
/* easy; the entire command name */
res = strcpy(outbuf, res);
} else {
const struct ext_func_tab *matchcmd = extcmdlist;
int len = 0;
/* find the shortest leading substring which is unambiguous */
do {
if (++len >= (int) strlen(res))
break;
for (extcmd = matchcmd; extcmd->ef_txt; ++extcmd) {
if (extcmd == cmdptr)
continue;
if ((extcmd->flags & CMD_NOT_AVAILABLE) != 0
|| ((extcmd->flags & WIZMODECMD) != 0 && !wizard))
continue;
if (!strncmp(res, extcmd->ef_txt, len)) {
matchcmd = extcmd;
break;
}
}
} while (extcmd->ef_txt);
copynchars(outbuf, res, len);
debugpline2("shortened %s: \"%s\"", res, outbuf);
res = outbuf;
}
return res;
}
/*
* wizard mode sanity_check code
*/