added the ctrl-i and ctrl-d console shortcuts

This commit is contained in:
myT 2019-02-21 17:11:29 +01:00
parent 3305c6f515
commit b3456d0a10
5 changed files with 45 additions and 1 deletions

View file

@ -1,6 +1,10 @@
DD Mmm 19 - 1.51
add: new console keyboard shortcuts
Ctrl-I | insert cvar's current value
Ctrl-D | insert cvar's default value
add: demo recording status query extension for CPMA 1.52+
add: /cvar_add <cvar> <number> to add a number to a cvar

View file

@ -546,6 +546,18 @@ static void Console_Key( int key )
return;
}
// ctrl-i = insert CVar's current value
if ( keys[K_CTRL].down && tolower(key) == 'i' ) {
Field_InsertValue( &g_consoleField, qfalse );
return;
}
// ctrl-d = insert CVar's default value
if ( keys[K_CTRL].down && tolower(key) == 'd' ) {
Field_InsertValue( &g_consoleField, qtrue );
return;
}
// pass to the normal editline routine
Field_KeyDownEvent( &g_consoleField, key );
}

View file

@ -3162,6 +3162,31 @@ void Field_AutoCompleteKeyName( fieldCallback_t callback )
#endif
void Field_InsertValue( field_t *edit, qbool defaultValue )
{
if ( Cmd_Argc() < 1 )
return;
const char* name = Cmd_Argv( 0 );
if ( name[0] == '\\' || name[0] == '/' )
name++;
if ( name[0] == '\0' )
return;
const cvar_t* const cvar = Cvar_FindVar( name );
if ( !cvar )
return;
const char* const valueString = defaultValue ? cvar->resetString : cvar->string;
const qbool quotesNeeded = valueString[0] == '\0' || strchr( valueString, ' ' ) != NULL;
const char* const quotes = quotesNeeded ? "\"" : "";
Com_sprintf( edit->buffer, sizeof( edit->buffer ), "\\%s %s", cvar->name, quotes );
edit->cursor = strlen( edit->buffer );
Q_strcat( edit->buffer, sizeof( edit->buffer ), va( "%s%s", valueString, quotes ) );
}
void History_Clear( history_t* history, int width )
{
for ( int i = 0; i < COMMAND_HISTORY; ++i ) {

View file

@ -86,7 +86,7 @@ static qbool Cvar_ValidateString( const char *s )
}
static cvar_t* Cvar_FindVar( const char* var_name )
cvar_t* Cvar_FindVar( const char* var_name )
{
long hash = Cvar_Hash(var_name);

View file

@ -516,6 +516,8 @@ cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
// that allows variables to be unarchived without needing bitflags
// if value is "", the value will not override a previously set value.
cvar_t* Cvar_FindVar( const char* var_name );
void Cvar_PrintDeprecationWarnings();
void Cvar_SetHelp( const char *var_name, const char *help );
@ -777,6 +779,7 @@ typedef struct {
void Field_Clear( field_t *edit );
void Field_AutoComplete( field_t *edit, qbool insertBackslash ); // should only be called by Console_Key
void Field_InsertValue( field_t *edit, qbool defaultValue );
typedef void (*fieldCallback_t)( const char* );
typedef void (*fieldCompletionHandler_t)( fieldCallback_t );