Esempio n. 1
0
/*
 * Handle input and update display
 */
void uimenu::query(bool loop)
{
    keypress = 0;
    if ( entries.empty() ) {
        return;
    }
    int startret = UIMENU_INVALID;
    ret = UIMENU_INVALID;
    bool keycallback = (callback != NULL );

    show();
    do {
        bool skiprefresh = false;
        bool skipkey = false;
        keypress = getch();

        if ( scrollby(0, keypress) == true ) {
            /* nothing */
        } else if ( filtering && ( keypress == '/' || keypress == '.' ) ) {
            inputfilter();
        } else if ( !fentries.empty() && ( keypress == '\n' || keypress == KEY_ENTER ||
                                           keymap.find(keypress) != keymap.end() ) ) {
            if ( keymap.find(keypress) != keymap.end() ) {
                selected = keymap[ keypress ];//fixme ?
            }
            if( entries[ selected ].enabled ) {
                ret = entries[ selected ].retval; // valid
            } else if ( return_invalid ) {
                ret = 0 - entries[ selected ].retval; // disabled
            }
        } else if ( keypress == KEY_ESCAPE && return_invalid) { //break loop with ESCAPE key
            break;
        } else {
            if ( keycallback ) {
                skipkey = callback->key( keypress, selected, this );
            }
            if ( ! skipkey && return_invalid ) {
                ret = -1;
            }
        }

        if ( skiprefresh == false ) {
            show();
        }
    } while ( loop && (ret == startret ) );
}
Esempio n. 2
0
/**
 * Handle input and update display
 *
 */
void uimenu::query( bool loop, int timeout )
{
    bool new_interface = dynamic_cast<uilist *>( this ) != nullptr;
    keypress = 0;
    if ( entries.empty() ) {
        if( new_interface ) {
            ret = UIMENU_ERROR;
        }
        return;
    }
    ret = ( new_interface ? UIMENU_WAIT_INPUT : UIMENU_INVALID );

    input_context ctxt( input_category );
    ctxt.register_updown();
    ctxt.register_action( "PAGE_UP" );
    ctxt.register_action( "PAGE_DOWN" );
    ctxt.register_action( "SCROLL_UP" );
    ctxt.register_action( "SCROLL_DOWN" );
    if( new_interface ? allow_cancel : return_invalid ) {
        ctxt.register_action( "QUIT" );
    }
    ctxt.register_action( "CONFIRM" );
    ctxt.register_action( "FILTER" );
    ctxt.register_action( "ANY_INPUT" );
    ctxt.register_action( "HELP_KEYBINDINGS" );
    for ( const auto &additional_action : additional_actions ) {
        ctxt.register_action( additional_action.first, additional_action.second );
    }
    hotkeys = ctxt.get_available_single_char_hotkeys( hotkeys );

    show();

#ifdef __ANDROID__
    for (const auto& entry : entries) {
        if (entry.hotkey > 0 && entry.enabled)
            ctxt.register_manual_key(entry.hotkey, entry.txt);
    }
#endif

    do {
        const auto action = ctxt.handle_input( timeout );
        const auto event = ctxt.get_raw_input();
        keypress = event.get_first_input();
        const auto iter = keymap.find( keypress );

        if( scrollby( scroll_amount_from_action( action ) ) ) {
            /* nothing */
        } else if ( action == "HELP_KEYBINDINGS" ) {
            /* nothing, handled by input_context */
        } else if ( filtering && action == "FILTER" ) {
            inputfilter();
        } else if( iter != keymap.end() ) {
            selected = iter->second;
            if( entries[ selected ].enabled ) {
                ret = entries[ selected ].retval; // valid
            } else if( !new_interface && return_invalid ) {
                ret = 0 - entries[ selected ].retval; // disabled
            } else if( new_interface && allow_disabled ) {
                ret = entries[selected].retval; // disabled
            }
        } else if ( !fentries.empty() && action == "CONFIRM" ) {
            if( entries[ selected ].enabled ) {
                ret = entries[ selected ].retval; // valid
            } else if ( !new_interface && return_invalid ) {
                ret = 0 - entries[ selected ].retval; // disabled
            } else if( new_interface && allow_disabled ) {
                ret = entries[selected].retval; // disabled
            }
        } else if( ( !new_interface || allow_cancel ) && action == "QUIT" ) {
            if( new_interface ) {
                ret = UIMENU_CANCEL;
            } else {
                break;
            }
        } else if( action == "TIMEOUT" ) {
            ret = UIMENU_TIMEOUT;
        } else {
            bool unhandled = callback == nullptr || !callback->key( ctxt, event, selected, this );
            if( unhandled && ( new_interface ? allow_anykey : return_invalid ) ) {
                ret = new_interface ? UIMENU_UNBOUND : -1;
            }
        }

        show();
    } while( loop && ret == ( new_interface ? UIMENU_WAIT_INPUT : UIMENU_INVALID ) );
}
	InputFilterClosure scope()
	{
		if (m_taglevel < 0) return InputFilterClosure( InputFilterR( new InputFilterScope()));
		--m_taglevel; //consumed by returned scope
		return InputFilterClosure( InputFilterR( new InputFilterScope( inputfilter())));
	}