1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added autocomplete for /alias remove

This commit is contained in:
James Booth 2014-01-25 01:00:51 +00:00
parent cb590dd82c
commit b05e17db3e
3 changed files with 47 additions and 3 deletions

View File

@ -68,6 +68,7 @@ static char * _bookmark_autocomplete(char *input, int *size);
static char * _otr_autocomplete(char *input, int *size);
static char * _connect_autocomplete(char *input, int *size);
static char * _statuses_autocomplete(char *input, int *size);
static char * _alias_autocomplete(char *input, int *size);
GHashTable *commands = NULL;
@ -877,6 +878,7 @@ static Autocomplete connect_property_ac;
static Autocomplete statuses_ac;
static Autocomplete statuses_cons_chat_ac;
static Autocomplete alias_ac;
static Autocomplete aliases_ac;
/*
* Initialise command autocompleter and history
@ -887,6 +889,7 @@ cmd_init(void)
log_info("Initialising commands");
commands_ac = autocomplete_new();
aliases_ac = autocomplete_new();
help_ac = autocomplete_new();
autocomplete_add(help_ac, "commands");
@ -922,6 +925,7 @@ cmd_init(void)
GString *ac_alias = g_string_new("/");
g_string_append(ac_alias, alias->name);
autocomplete_add(commands_ac, ac_alias->str);
autocomplete_add(aliases_ac, alias->name);
g_string_free(ac_alias, TRUE);
curr = g_list_next(curr);
}
@ -1113,6 +1117,7 @@ cmd_uninit(void)
autocomplete_free(statuses_ac);
autocomplete_free(statuses_cons_chat_ac);
autocomplete_free(alias_ac);
autocomplete_free(aliases_ac);
}
void
@ -1131,6 +1136,22 @@ cmd_autocomplete_remove(char *value)
}
}
void
cmd_alias_add(char *value)
{
if (aliases_ac != NULL) {
autocomplete_add(aliases_ac, value);
}
}
void
cmd_alias_remove(char *value)
{
if (aliases_ac != NULL) {
autocomplete_remove(aliases_ac, value);
}
}
// Command autocompletion functions
void
cmd_autocomplete(char *input, int *size)
@ -1208,6 +1229,7 @@ cmd_reset_autocomplete()
autocomplete_reset(statuses_ac);
autocomplete_reset(statuses_cons_chat_ac);
autocomplete_reset(alias_ac);
autocomplete_reset(aliases_ac);
bookmark_autocomplete_reset();
}
@ -1455,8 +1477,8 @@ _cmd_complete_parameters(char *input, int *size)
return;
}
gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins", "/alias" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac, alias_ac };
gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, size, cmds[i], completers[i]);
@ -1471,7 +1493,7 @@ _cmd_complete_parameters(char *input, int *size)
_autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete,
_account_autocomplete, _roster_autocomplete, _group_autocomplete,
_bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete,
_connect_autocomplete, _statuses_autocomplete };
_connect_autocomplete, _statuses_autocomplete, _alias_autocomplete };
for (i = 0; i < ARRAY_SIZE(acs); i++) {
result = acs[i](input, size);
@ -1776,6 +1798,24 @@ _statuses_autocomplete(char *input, int *size)
return NULL;
}
static char *
_alias_autocomplete(char *input, int *size)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, size, "/alias remove", aliases_ac);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/alias", alias_ac);
if (result != NULL) {
return result;
}
return NULL;
}
static char *
_connect_autocomplete(char *input, int *size)
{

View File

@ -34,6 +34,8 @@ void cmd_autocomplete(char *input, int *size);
void cmd_reset_autocomplete(void);
void cmd_autocomplete_add(char *value);
void cmd_autocomplete_remove(char *value);
void cmd_alias_add(char *value);
void cmd_alias_remove(char *value);
gboolean cmd_execute(const char * const command, const char * const inp);
gboolean cmd_execute_alias(const char * const inp, gboolean *ran);

View File

@ -1839,6 +1839,7 @@ cmd_alias(gchar **args, struct cmd_help_t help)
GString *ac_value = g_string_new("/");
g_string_append(ac_value, alias);
cmd_autocomplete_add(ac_value->str);
cmd_alias_add(alias);
g_string_free(ac_value, TRUE);
cons_show("Command alias added /%s -> %s", alias, value);
} else {
@ -1860,6 +1861,7 @@ cmd_alias(gchar **args, struct cmd_help_t help)
GString *ac_value = g_string_new("/");
g_string_append(ac_value, alias);
cmd_autocomplete_remove(ac_value->str);
cmd_alias_remove(alias);
g_string_free(ac_value, TRUE);
cons_show("Command alias removed -> /%s", alias);
}