MCPcopy Create free account
hub / github.com/NetHack/NetHack / ghack_ext_key_hit

Function ghack_ext_key_hit

outdated/win/gnome/gnmenu.c:620–676  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

618}
619
620static void
621ghack_ext_key_hit(GtkWidget *menuWin, GdkEventKey *event, gpointer data)
622{
623 GtkWidget *clist;
624 extMenu *info = (extMenu *) data;
625 int i;
626 char c = event->string[0];
627
628 clist = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(menuWin), "clist"));
629 g_assert(clist != NULL);
630
631 /* if too long between keystrokes, reset to initial state */
632 if (event->time - info->lastTime > 500)
633 goto init_state;
634
635 /* see if current item continue to match */
636 if (info->charIdx > 0) {
637 if (extcmdlist[info->curItem].ef_txt[info->charIdx] == c) {
638 ++info->charIdx;
639 goto found;
640 }
641 }
642
643 /* see if the prefix matches a later command in the list */
644 if (info->curItem >= 0) {
645 for (i = info->curItem + 1; i < info->numRows; ++i) {
646 if (!strncmp(extcmdlist[info->curItem].ef_txt,
647 extcmdlist[i].ef_txt, info->charIdx)) {
648 if (extcmdlist[i].ef_txt[info->charIdx] == c) {
649 ++info->charIdx;
650 info->curItem = i;
651 goto found;
652 }
653 }
654 }
655 }
656
657init_state:
658 /* reset to initial state, look for matching 1st character */
659 for (i = 0; i < info->numRows; ++i) {
660 if (extcmdlist[i].ef_txt[0] == c) {
661 info->charIdx = 1;
662 info->curItem = i;
663 goto found;
664 }
665 }
666
667 /* no match: leave prior, if any selection in place */
668 return;
669
670found:
671 info->lastTime = event->time;
672 gtk_clist_select_row(GTK_CLIST(clist), info->curItem, 0);
673 if (gtk_clist_row_is_visible(GTK_CLIST(clist), info->curItem)
674 != GTK_VISIBILITY_FULL)
675 gtk_clist_moveto(GTK_CLIST(clist), info->curItem, 0, 0.5, 0);
676}
677

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected