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

Allow previous autocompletion with shift tab

This commit is contained in:
James Booth 2017-04-01 00:27:11 +01:00
parent 1b9d033cef
commit 6b830277a6
38 changed files with 597 additions and 466 deletions

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,7 @@
void cmd_ac_init(void);
void cmd_ac_uninit(void);
char* cmd_ac_complete(ProfWin *window, const char *const input);
char* cmd_ac_complete(ProfWin *window, const char *const input, gboolean previous);
void cmd_ac_reset(ProfWin *window);
gboolean cmd_ac_exists(char *cmd);
@ -57,6 +57,6 @@ void cmd_ac_remove_alias_value(char *value);
void cmd_ac_add_form_fields(DataForm *form);
void cmd_ac_remove_form_fields(DataForm *form);
char* cmd_ac_complete_filepath(const char *const input, char *const startstr);
char* cmd_ac_complete_filepath(const char *const input, char *const startstr, gboolean previous);
#endif

View File

@ -2133,16 +2133,16 @@ cmd_group(ProfWin *window, const char *const command, gchar **args)
// list all groups
if (args[0] == NULL) {
GSList *groups = roster_get_groups();
GSList *curr = groups;
GList *groups = roster_get_groups();
GList *curr = groups;
if (curr) {
cons_show("Groups:");
while (curr) {
cons_show(" %s", curr->data);
curr = g_slist_next(curr);
curr = g_list_next(curr);
}
g_slist_free_full(groups, g_free);
g_list_free_full(groups, g_free);
} else {
cons_show("No groups.");
}
@ -3562,9 +3562,9 @@ cmd_invite(ProfWin *window, const char *const command, gchar **args)
gboolean
cmd_invites(ProfWin *window, const char *const command, gchar **args)
{
GSList *invites = muc_invites();
GList *invites = muc_invites();
cons_show_room_invites(invites);
g_slist_free_full(invites, g_free);
g_list_free_full(invites, g_free);
return TRUE;
}

View File

@ -96,15 +96,15 @@ accounts_close(void)
}
char*
accounts_find_enabled(const char *const prefix)
accounts_find_enabled(const char *const prefix, gboolean previous)
{
return autocomplete_complete(enabled_ac, prefix, TRUE);
return autocomplete_complete(enabled_ac, prefix, TRUE, previous);
}
char*
accounts_find_all(const char *const prefix)
accounts_find_all(const char *const prefix, gboolean previous)
{
return autocomplete_complete(all_ac, prefix, TRUE);
return autocomplete_complete(all_ac, prefix, TRUE, previous);
}
void

View File

@ -43,8 +43,8 @@
void accounts_load(void);
void accounts_close(void);
char* accounts_find_all(const char *const prefix);
char* accounts_find_enabled(const char *const prefix);
char* accounts_find_all(const char *const prefix, gboolean previous);
char* accounts_find_enabled(const char *const prefix, gboolean previous);
void accounts_reset_all_search(void);
void accounts_reset_enabled_search(void);
void accounts_add(const char *jid, const char *altdomain, const int port, const char *const tls_policy);

View File

@ -183,9 +183,9 @@ prefs_close(void)
}
char*
prefs_autocomplete_boolean_choice(const char *const prefix)
prefs_autocomplete_boolean_choice(const char *const prefix, gboolean previous)
{
return autocomplete_complete(boolean_choice_ac, prefix, TRUE);
return autocomplete_complete(boolean_choice_ac, prefix, TRUE, previous);
}
void
@ -195,9 +195,9 @@ prefs_reset_boolean_choice(void)
}
char*
prefs_autocomplete_room_trigger(const char *const prefix)
prefs_autocomplete_room_trigger(const char *const prefix, gboolean previous)
{
return autocomplete_complete(room_trigger_ac, prefix, TRUE);
return autocomplete_complete(room_trigger_ac, prefix, TRUE, previous);
}
void

View File

@ -162,10 +162,10 @@ void prefs_close(void);
char* prefs_find_login(char *prefix);
void prefs_reset_login_search(void);
char* prefs_autocomplete_boolean_choice(const char *const prefix);
char* prefs_autocomplete_boolean_choice(const char *const prefix, gboolean previous);
void prefs_reset_boolean_choice(void);
char* prefs_autocomplete_room_trigger(const char *const prefix);
char* prefs_autocomplete_room_trigger(const char *const prefix, gboolean previous);
void prefs_reset_room_trigger_ac(void);
gint prefs_get_gone(void);

View File

@ -368,9 +368,9 @@ tlscerts_get_trusted(const char * const fingerprint)
}
char*
tlscerts_complete(const char *const prefix)
tlscerts_complete(const char *const prefix, gboolean previous)
{
return autocomplete_complete(certs_ac, prefix, TRUE);
return autocomplete_complete(certs_ac, prefix, TRUE, previous);
}
void

View File

@ -89,7 +89,7 @@ void tlscerts_free(TLSCertificate *cert);
GList* tlscerts_list(void);
char* tlscerts_complete(const char *const prefix);
char* tlscerts_complete(const char *const prefix, gboolean previous);
void tlscerts_reset_ac(void);

View File

@ -749,9 +749,9 @@ p_gpg_free_decrypted(char *decrypted)
}
char*
p_gpg_autocomplete_key(const char *const search_str)
p_gpg_autocomplete_key(const char *const search_str, gboolean previous)
{
return autocomplete_complete(key_ac, search_str, TRUE);
return autocomplete_complete(key_ac, search_str, TRUE, previous);
}
void

View File

@ -67,7 +67,7 @@ void p_gpg_verify(const char *const barejid, const char *const sign);
char* p_gpg_encrypt(const char *const barejid, const char *const message, const char *const fp);
char* p_gpg_decrypt(const char *const cipher);
void p_gpg_free_decrypted(char *decrypted);
char* p_gpg_autocomplete_key(const char *const search_str);
char* p_gpg_autocomplete_key(const char *const search_str, gboolean previous);
void p_gpg_autocomplete_key_reset(void);
char* p_gpg_format_fp_str(char *fp);

View File

@ -129,7 +129,7 @@ autocompleters_filepath_add(const char *const plugin_name, const char *prefix)
}
char*
autocompleters_complete(const char * const input)
autocompleters_complete(const char * const input, gboolean previous)
{
char *result = NULL;
@ -141,7 +141,7 @@ autocompleters_complete(const char * const input)
GList *keys = g_hash_table_get_keys(key_to_ac);
GList *curr = keys;
while (curr) {
result = autocomplete_param_with_ac(input, curr->data, g_hash_table_lookup(key_to_ac, curr->data), TRUE);
result = autocomplete_param_with_ac(input, curr->data, g_hash_table_lookup(key_to_ac, curr->data), TRUE, previous);
if (result) {
g_list_free(ac_hashes);
g_list_free(keys);
@ -164,7 +164,7 @@ autocompleters_complete(const char * const input)
while (curr_prefix) {
char *prefix = curr_prefix->data;
if (g_str_has_prefix(input, prefix)) {
result = cmd_ac_complete_filepath(input, prefix);
result = cmd_ac_complete_filepath(input, prefix, previous);
if (result) {
g_list_free(filepath_hashes);
g_list_free(prefixes);

View File

@ -42,7 +42,7 @@ void autocompleters_add(const char *const plugin_name, const char *key, char **i
void autocompleters_remove(const char *const plugin_name, const char *key, char **items);
void autocompleters_clear(const char *const plugin_name, const char *key);
void autocompleters_filepath_add(const char *const plugin_name, const char *prefix);
char* autocompleters_complete(const char * const input);
char* autocompleters_complete(const char * const input, gboolean previous);
void autocompleters_reset(void);
void autocompleters_destroy(void);

View File

@ -369,9 +369,9 @@ plugins_loaded_list(void)
}
char *
plugins_autocomplete(const char * const input)
plugins_autocomplete(const char * const input, gboolean previous)
{
return autocompleters_complete(input);
return autocompleters_complete(input, previous);
}
void

View File

@ -108,7 +108,7 @@ typedef struct prof_plugin_t {
void plugins_init(void);
GSList *plugins_unloaded_list(void);
GList *plugins_loaded_list(void);
char* plugins_autocomplete(const char *const input);
char* plugins_autocomplete(const char *const input, gboolean previous);
void plugins_reset_autocomplete(void);
void plugins_shutdown(void);

View File

@ -40,14 +40,16 @@
#include "common.h"
#include "tools/autocomplete.h"
#include "tools/parser.h"
#include "ui/ui.h"
struct autocomplete_t {
GSList *items;
GSList *last_found;
GList *items;
GList *last_found;
gchar *search_str;
};
static gchar* _search_from(Autocomplete ac, GSList *curr, gboolean quote);
static gchar* _search_next(Autocomplete ac, GList *curr, gboolean quote);
static gchar* _search_prev(Autocomplete ac, GList *curr, gboolean quote);
Autocomplete
autocomplete_new(void)
@ -64,7 +66,7 @@ void
autocomplete_clear(Autocomplete ac)
{
if (ac) {
g_slist_free_full(ac->items, free);
g_list_free_full(ac->items, free);
ac->items = NULL;
autocomplete_reset(ac);
@ -95,7 +97,7 @@ autocomplete_length(Autocomplete ac)
} else if (!ac->items) {
return 0;
} else {
return g_slist_length(ac->items);
return g_list_length(ac->items);
}
}
@ -104,7 +106,7 @@ autocomplete_add(Autocomplete ac, const char *item)
{
if (ac) {
char *item_cpy;
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
GList *curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp);
// if item already exists
if (curr) {
@ -112,7 +114,7 @@ autocomplete_add(Autocomplete ac, const char *item)
}
item_cpy = strdup(item);
ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
ac->items = g_list_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
}
return;
@ -131,7 +133,7 @@ void
autocomplete_remove(Autocomplete ac, const char *const item)
{
if (ac) {
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
GList *curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp);
if (!curr) {
return;
@ -143,7 +145,7 @@ autocomplete_remove(Autocomplete ac, const char *const item)
}
free(curr->data);
ac->items = g_slist_delete_link(ac->items, curr);
ac->items = g_list_delete_link(ac->items, curr);
}
return;
@ -158,15 +160,15 @@ autocomplete_remove_all(Autocomplete ac, char **items)
}
}
GSList*
GList*
autocomplete_create_list(Autocomplete ac)
{
GSList *copy = NULL;
GSList *curr = ac->items;
GList *copy = NULL;
GList *curr = ac->items;
while(curr) {
copy = g_slist_append(copy, strdup(curr->data));
curr = g_slist_next(curr);
copy = g_list_append(copy, strdup(curr->data));
curr = g_list_next(curr);
}
return copy;
@ -175,20 +177,20 @@ autocomplete_create_list(Autocomplete ac)
gboolean
autocomplete_contains(Autocomplete ac, const char *value)
{
GSList *curr = ac->items;
GList *curr = ac->items;
while(curr) {
if (strcmp(curr->data, value) == 0) {
return TRUE;
}
curr = g_slist_next(curr);
curr = g_list_next(curr);
}
return FALSE;
}
gchar*
autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote)
autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote, gboolean previous)
{
gchar *found = NULL;
@ -209,22 +211,38 @@ autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote)
}
ac->search_str = strdup(search_str);
found = _search_from(ac, ac->items, quote);
found = _search_next(ac, ac->items, quote);
return found;
// subsequent search attempt
} else {
// search from here+1 to end
found = _search_from(ac, g_slist_next(ac->last_found), quote);
if (found) {
return found;
if (previous) {
// search from here-1 to beginning
found = _search_prev(ac, g_list_previous(ac->last_found), quote);
if (found) {
return found;
}
} else {
// search from here+1 to end
found = _search_next(ac, g_list_next(ac->last_found), quote);
if (found) {
return found;
}
}
// search from beginning
found = _search_from(ac, ac->items, quote);
if (found) {
return found;
if (previous) {
// search from end
found = _search_prev(ac, g_list_last(ac->items), quote);
if (found) {
return found;
}
} else {
// search from beginning
found = _search_next(ac, ac->items, quote);
if (found) {
return found;
}
}
// we found nothing, reset search
@ -235,7 +253,7 @@ autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote)
}
char*
autocomplete_param_with_func(const char *const input, char *command, autocomplete_func func)
autocomplete_param_with_func(const char *const input, char *command, autocomplete_func func, gboolean previous)
{
GString *auto_msg = NULL;
char *result = NULL;
@ -252,7 +270,7 @@ autocomplete_param_with_func(const char *const input, char *command, autocomplet
}
prefix[inp_len - len] = '\0';
char *found = func(prefix);
char *found = func(prefix, previous);
if (found) {
auto_msg = g_string_new(command_cpy);
g_string_append(auto_msg, found);
@ -266,7 +284,7 @@ autocomplete_param_with_func(const char *const input, char *command, autocomplet
}
char*
autocomplete_param_with_ac(const char *const input, char *command, Autocomplete ac, gboolean quote)
autocomplete_param_with_ac(const char *const input, char *command, Autocomplete ac, gboolean quote, gboolean previous)
{
GString *auto_msg = NULL;
char *result = NULL;
@ -282,7 +300,7 @@ autocomplete_param_with_ac(const char *const input, char *command, Autocomplete
}
prefix[inp_len - len] = '\0';
char *found = autocomplete_complete(ac, prefix, quote);
char *found = autocomplete_complete(ac, prefix, quote, previous);
if (found) {
auto_msg = g_string_new(command_cpy);
g_string_append(auto_msg, found);
@ -297,7 +315,7 @@ autocomplete_param_with_ac(const char *const input, char *command, Autocomplete
}
char*
autocomplete_param_no_with_func(const char *const input, char *command, int arg_number, autocomplete_func func)
autocomplete_param_no_with_func(const char *const input, char *command, int arg_number, autocomplete_func func, gboolean previous)
{
if (strncmp(input, command, strlen(command)) == 0) {
GString *result_str = NULL;
@ -312,7 +330,7 @@ autocomplete_param_no_with_func(const char *const input, char *command, int arg_
// autocomplete param
if (comp_str) {
char *found = func(comp_str);
char *found = func(comp_str, previous);
if (found) {
result_str = g_string_new("");
g_string_append(result_str, start_str);
@ -329,7 +347,7 @@ autocomplete_param_no_with_func(const char *const input, char *command, int arg_
}
static gchar*
_search_from(Autocomplete ac, GSList *curr, gboolean quote)
_search_next(Autocomplete ac, GList *curr, gboolean quote)
{
gchar *search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
gchar *search_str_lower = g_ascii_strdown(search_str_ascii, -1);
@ -368,7 +386,54 @@ _search_from(Autocomplete ac, GSList *curr, gboolean quote)
}
g_free(curr_lower);
curr = g_slist_next(curr);
curr = g_list_next(curr);
}
g_free(search_str_lower);
return NULL;
}
static gchar*
_search_prev(Autocomplete ac, GList *curr, gboolean quote)
{
gchar *search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
gchar *search_str_lower = g_ascii_strdown(search_str_ascii, -1);
g_free(search_str_ascii);
while(curr) {
gchar *curr_ascii = g_str_to_ascii(curr->data, NULL);
gchar *curr_lower = g_ascii_strdown(curr_ascii, -1);
g_free(curr_ascii);
// match found
if (strncmp(curr_lower, search_str_lower, strlen(search_str_lower)) == 0) {
// set pointer to last found
ac->last_found = curr;
// if contains space, quote before returning
if (quote && g_strrstr(curr->data, " ")) {
GString *quoted = g_string_new("\"");
g_string_append(quoted, curr->data);
g_string_append(quoted, "\"");
gchar *result = quoted->str;
g_string_free(quoted, FALSE);
g_free(search_str_lower);
g_free(curr_lower);
return result;
// otherwise just return the string
} else {
g_free(search_str_lower);
g_free(curr_lower);
return strdup(curr->data);
}
}
g_free(curr_lower);
curr = g_list_previous(curr);
}
g_free(search_str_lower);

View File

@ -37,7 +37,7 @@
#include <glib.h>
typedef char* (*autocomplete_func)(const char *const);
typedef char* (*autocomplete_func)(const char *const, gboolean);
typedef struct autocomplete_t *Autocomplete;
// allocate new autocompleter with no items
@ -55,19 +55,19 @@ void autocomplete_remove(Autocomplete ac, const char *const item);
void autocomplete_remove_all(Autocomplete ac, char **items);
// find the next item prefixed with search string
gchar* autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote);
gchar* autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote, gboolean previous);
GSList* autocomplete_create_list(Autocomplete ac);
GList* autocomplete_create_list(Autocomplete ac);
gint autocomplete_length(Autocomplete ac);
char* autocomplete_param_with_func(const char *const input, char *command,
autocomplete_func func);
autocomplete_func func, gboolean previous);
char* autocomplete_param_with_ac(const char *const input, char *command,
Autocomplete ac, gboolean quote);
Autocomplete ac, gboolean quote, gboolean previous);
char* autocomplete_param_no_with_func(const char *const input, char *command,
int arg_number, autocomplete_func func);
int arg_number, autocomplete_func func, gboolean previous);
void autocomplete_reset(Autocomplete ac);

View File

@ -505,7 +505,7 @@ cons_show_wins(gboolean unread)
}
void
cons_show_room_invites(GSList *invites)
cons_show_room_invites(GList *invites)
{
cons_show("");
if (invites == NULL) {
@ -514,7 +514,7 @@ cons_show_room_invites(GSList *invites)
cons_show("Chat room invites, use /join or /decline commands:");
while (invites) {
cons_show(" %s", invites->data);
invites = g_slist_next(invites);
invites = g_list_next(invites);
}
}
@ -608,17 +608,17 @@ cons_show_caps(const char *const fulljid, resource_presence_t presence)
void
cons_show_received_subs(void)
{
GSList *received = presence_get_subscription_requests();
GList *received = presence_get_subscription_requests();
if (received == NULL) {
cons_show("No outstanding subscription requests.");
} else {
cons_show("Outstanding subscription requests from:",
g_slist_length(received));
g_list_length(received));
while (received) {
cons_show(" %s", received->data);
received = g_slist_next(received);
received = g_list_next(received);
}
g_slist_free_full(received, g_free);
g_list_free_full(received, g_free);
}
cons_alert();

View File

@ -96,6 +96,7 @@ static void _inp_rl_addfuncs(void);
static int _inp_rl_getc(FILE *stream);
static void _inp_rl_linehandler(char *line);
static int _inp_rl_tab_handler(int count, int key);
static int _inp_rl_shift_tab_handler(int count, int key);
static int _inp_rl_win_clear_handler(int count, int key);
static int _inp_rl_win_1_handler(int count, int key);
static int _inp_rl_win_2_handler(int count, int key);
@ -421,6 +422,7 @@ _inp_rl_startup_hook(void)
rl_bind_keyseq("\\eOs", _inp_rl_win_pagedown_handler);
rl_bind_key('\t', _inp_rl_tab_handler);
rl_bind_keyseq("\\e[Z", _inp_rl_shift_tab_handler);
// unbind unwanted mappings
rl_bind_keyseq("\\e=", NULL);
@ -449,10 +451,27 @@ _inp_rl_linehandler(char *line)
inp_line = line;
}
static gboolean shift_tab = FALSE;
static int
_inp_rl_getc(FILE *stream)
{
int ch = rl_getc(stream);
// 27, 91, 90 = Shift tab
if (ch == 27) {
shift_tab = TRUE;
return ch;
}
if (shift_tab && ch == 91) {
return ch;
}
if (shift_tab && ch == 90) {
return ch;
}
shift_tab = FALSE;
if (_inp_printable(ch)) {
ProfWin *window = wins_get_current();
cmd_ac_reset(window);
@ -477,7 +496,7 @@ _inp_rl_tab_handler(int count, int key)
ProfWin *current = wins_get_current();
if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
char *result = muc_autocomplete(current, rl_line_buffer);
char *result = muc_autocomplete(current, rl_line_buffer, FALSE);
if (result) {
rl_replace_line(result, 1);
rl_point = rl_end;
@ -485,7 +504,35 @@ _inp_rl_tab_handler(int count, int key)
}
} else if (strncmp(rl_line_buffer, "/", 1) == 0) {
ProfWin *window = wins_get_current();
char *result = cmd_ac_complete(window, rl_line_buffer);
char *result = cmd_ac_complete(window, rl_line_buffer, FALSE);
if (result) {
rl_replace_line(result, 1);
rl_point = rl_end;
free(result);
}
}
return 0;
}
static int
_inp_rl_shift_tab_handler(int count, int key)
{
if (rl_point != rl_end || !rl_line_buffer) {
return 0;
}
ProfWin *current = wins_get_current();
if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
char *result = muc_autocomplete(current, rl_line_buffer, TRUE);
if (result) {
rl_replace_line(result, 1);
rl_point = rl_end;
free(result);
}
} else if (strncmp(rl_line_buffer, "/", 1) == 0) {
ProfWin *window = wins_get_current();
char *result = cmd_ac_complete(window, rl_line_buffer, TRUE);
if (result) {
rl_replace_line(result, 1);
rl_point = rl_end;

View File

@ -138,13 +138,13 @@ rosterwin_roster(void)
_rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb");
_rosterwin_contacts_by_presence(layout, "offline", "Offline");
} else if (g_strcmp0(by, "group") == 0) {
GSList *groups = roster_get_groups();
GSList *curr_group = groups;
GList *groups = roster_get_groups();
GList *curr_group = groups;
while (curr_group) {
_rosterwin_contacts_by_group(layout, curr_group->data);
curr_group = g_slist_next(curr_group);
curr_group = g_list_next(curr_group);
}
g_slist_free_full(groups, free);
g_list_free_full(groups, free);
_rosterwin_contacts_by_group(layout, NULL);
} else {
_rosterwin_contacts_all(layout);

View File

@ -278,7 +278,7 @@ void cons_show_incoming_room_message(const char *const nick, const char *const r
gboolean mention, GList *triggers, int unread);
void cons_show_incoming_message(const char *const short_from, const int win_index, int unread);
void cons_show_incoming_private_message(const char *const nick, const char *const room, const int win_index, int unread);
void cons_show_room_invites(GSList *invites);
void cons_show_room_invites(GList *invites);
void cons_show_received_subs(void);
void cons_show_sent_subs(void);
void cons_alert(void);

View File

@ -1073,15 +1073,15 @@ wins_create_summary(gboolean unread)
}
char*
win_autocomplete(const char *const search_str)
win_autocomplete(const char *const search_str, gboolean previous)
{
return autocomplete_complete(wins_ac, search_str, TRUE);
return autocomplete_complete(wins_ac, search_str, TRUE, previous);
}
char*
win_close_autocomplete(const char *const search_str)
win_close_autocomplete(const char *const search_str, gboolean previous)
{
return autocomplete_complete(wins_close_ac, search_str, TRUE);
return autocomplete_complete(wins_close_ac, search_str, TRUE, previous);
}
void

View File

@ -91,9 +91,9 @@ gboolean wins_swap(int source_win, int target_win);
void wins_hide_subwin(ProfWin *window);
void wins_show_subwin(ProfWin *window);
char* win_autocomplete(const char *const search_str);
char* win_autocomplete(const char *const search_str, gboolean previous);
void win_reset_search_attempts(void);
char* win_close_autocomplete(const char *const search_str);
char* win_close_autocomplete(const char *const search_str, gboolean previous);
void win_close_reset_search_attempts(void);
#endif

View File

@ -92,9 +92,9 @@ blocked_list(void)
}
char*
blocked_ac_find(const char *const search_str)
blocked_ac_find(const char *const search_str, gboolean previous)
{
return autocomplete_complete(blocked_ac, search_str, TRUE);
return autocomplete_complete(blocked_ac, search_str, TRUE, previous);
}
void

View File

@ -212,9 +212,9 @@ bookmark_get_list(void)
}
char*
bookmark_find(const char *const search_str)
bookmark_find(const char *const search_str, gboolean previous)
{
return autocomplete_complete(bookmark_ac, search_str, TRUE);
return autocomplete_complete(bookmark_ac, search_str, TRUE, previous);
}
void

View File

@ -120,7 +120,7 @@ muc_invites_count(void)
return autocomplete_length(invite_ac);
}
GSList*
GList*
muc_invites(void)
{
return autocomplete_create_list(invite_ac);
@ -135,17 +135,17 @@ muc_invite_password(const char *const room)
gboolean
muc_invites_contain(const char *const room)
{
GSList *invites = autocomplete_create_list(invite_ac);
GSList *curr = invites;
GList *invites = autocomplete_create_list(invite_ac);
GList *curr = invites;
while (curr) {
if (strcmp(curr->data, room) == 0) {
g_slist_free_full(invites, g_free);
g_list_free_full(invites, g_free);
return TRUE;
} else {
curr = g_slist_next(curr);
curr = g_list_next(curr);
}
}
g_slist_free_full(invites, g_free);
g_list_free_full(invites, g_free);
return FALSE;
}
@ -157,9 +157,9 @@ muc_invites_reset_ac(void)
}
char*
muc_invites_find(const char *const search_str)
muc_invites_find(const char *const search_str, gboolean previous)
{
return autocomplete_complete(invite_ac, search_str, TRUE);
return autocomplete_complete(invite_ac, search_str, TRUE, previous);
}
void
@ -663,7 +663,7 @@ muc_roster_nick_change_complete(const char *const room, const char *const nick)
}
char*
muc_autocomplete(ProfWin *window, const char *const input)
muc_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin*)window;
@ -686,7 +686,7 @@ muc_autocomplete(ProfWin *window, const char *const input)
}
}
char *result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE);
char *result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE, previous);
if (result) {
GString *replace_with = g_string_new(chat_room->autocomplete_prefix);
g_string_append(replace_with, result);

View File

@ -120,10 +120,10 @@ char* muc_roster_nick_change_complete(const char *const room, const char *const
void muc_invites_add(const char *const room, const char *const password);
void muc_invites_remove(const char *const room);
gint muc_invites_count(void);
GSList* muc_invites(void);
GList* muc_invites(void);
gboolean muc_invites_contain(const char *const room);
void muc_invites_reset_ac(void);
char* muc_invites_find(const char *const search_str);
char* muc_invites_find(const char *const search_str, gboolean previous);
void muc_invites_clear(void);
char* muc_invite_password(const char *const room);
@ -133,7 +133,7 @@ char* muc_subject(const char *const room);
void muc_pending_broadcasts_add(const char *const room, const char *const message);
GList* muc_pending_broadcasts(const char *const room);
char* muc_autocomplete(ProfWin *window, const char *const input);
char* muc_autocomplete(ProfWin *window, const char *const input, gboolean previous);
void muc_autocomplete_reset(const char *const room);
gboolean muc_requires_config(const char *const room);

View File

@ -141,7 +141,7 @@ presence_subscription(const char *const jid, const jabber_subscr_t action)
xmpp_stanza_release(presence);
}
GSList*
GList*
presence_get_subscription_requests(void)
{
return autocomplete_create_list(sub_requests_ac);
@ -160,9 +160,9 @@ presence_clear_sub_requests(void)
}
char*
presence_sub_request_find(const char *const search_str)
presence_sub_request_find(const char *const search_str, gboolean previous)
{
return autocomplete_complete(sub_requests_ac, search_str, TRUE);
return autocomplete_complete(sub_requests_ac, search_str, TRUE, previous);
}
gboolean
@ -170,16 +170,16 @@ presence_sub_request_exists(const char *const bare_jid)
{
gboolean result = FALSE;
GSList *requests = autocomplete_create_list(sub_requests_ac);
GSList *curr = requests;
GList *requests = autocomplete_create_list(sub_requests_ac);
GList *curr = requests;
while (curr) {
if (strcmp(curr->data, bare_jid) == 0) {
result = TRUE;
break;
}
curr = g_slist_next(curr);
curr = g_list_next(curr);
}
g_slist_free_full(requests, free);
g_list_free_full(requests, free);
return result;
}

View File

@ -472,19 +472,19 @@ roster_has_pending_subscriptions(void)
}
char*
roster_contact_autocomplete(const char *const search_str)
roster_contact_autocomplete(const char *const search_str, gboolean previous)
{
assert(roster != NULL);
return autocomplete_complete(roster->name_ac, search_str, TRUE);
return autocomplete_complete(roster->name_ac, search_str, TRUE, previous);
}
char*
roster_fulljid_autocomplete(const char *const search_str)
roster_fulljid_autocomplete(const char *const search_str, gboolean previous)
{
assert(roster != NULL);
return autocomplete_complete(roster->fulljid_ac, search_str, TRUE);
return autocomplete_complete(roster->fulljid_ac, search_str, TRUE, previous);
}
GSList*
@ -526,7 +526,7 @@ roster_get_group(const char *const group, roster_ord_t order)
return result;
}
GSList*
GList*
roster_get_groups(void)
{
assert(roster != NULL);
@ -535,19 +535,19 @@ roster_get_groups(void)
}
char*
roster_group_autocomplete(const char *const search_str)
roster_group_autocomplete(const char *const search_str, gboolean previous)
{
assert(roster != NULL);
return autocomplete_complete(roster->groups_ac, search_str, TRUE);
return autocomplete_complete(roster->groups_ac, search_str, TRUE, previous);
}
char*
roster_barejid_autocomplete(const char *const search_str)
roster_barejid_autocomplete(const char *const search_str, gboolean previous)
{
assert(roster != NULL);
return autocomplete_complete(roster->barejid_ac, search_str, TRUE);
return autocomplete_complete(roster->barejid_ac, search_str, TRUE, previous);
}
static gboolean

View File

@ -62,12 +62,12 @@ char* roster_barejid_from_name(const char *const name);
GSList* roster_get_contacts(roster_ord_t order);
GSList* roster_get_contacts_online(void);
gboolean roster_has_pending_subscriptions(void);
char* roster_contact_autocomplete(const char *const search_str);
char* roster_fulljid_autocomplete(const char *const search_str);
char* roster_contact_autocomplete(const char *const search_str, gboolean previous);
char* roster_fulljid_autocomplete(const char *const search_str, gboolean previous);
GSList* roster_get_group(const char *const group, roster_ord_t order);
GSList* roster_get_groups(void);
char* roster_group_autocomplete(const char *const search_str);
char* roster_barejid_autocomplete(const char *const search_str);
GList* roster_get_groups(void);
char* roster_group_autocomplete(const char *const search_str, gboolean previous);
char* roster_barejid_autocomplete(const char *const search_str, gboolean previous);
GSList* roster_get_contacts_by_presence(const char *const presence);
char* roster_get_msg_display_name(const char *const barejid, const char *const resource);

View File

@ -147,10 +147,10 @@ void message_send_gone(const char *const jid);
void message_send_invite(const char *const room, const char *const contact, const char *const reason);
void presence_subscription(const char *const jid, const jabber_subscr_t action);
GSList* presence_get_subscription_requests(void);
GList* presence_get_subscription_requests(void);
gint presence_sub_request_count(void);
void presence_reset_sub_request_search(void);
char* presence_sub_request_find(const char *const search_str);
char* presence_sub_request_find(const char *const search_str, gboolean previous);
void presence_join_room(const char *const room, const char *const nick, const char *const passwd);
void presence_change_room_nick(const char *const room, const char *const nick);
void presence_leave_chat_room(const char *const room_jid);
@ -194,7 +194,7 @@ gboolean bookmark_update(const char *jid, const char *nick, const char *password
gboolean bookmark_remove(const char *jid);
gboolean bookmark_join(const char *jid);
GList* bookmark_get_list(void);
char* bookmark_find(const char *const search_str);
char* bookmark_find(const char *const search_str, gboolean previous);
void bookmark_autocomplete_reset(void);
gboolean bookmark_exists(const char *const room);
@ -207,7 +207,7 @@ void roster_send_remove(const char *const barejid);
GList* blocked_list(void);
gboolean blocked_add(char *jid);
gboolean blocked_remove(char *jid);
char* blocked_ac_find(const char *const search_str);
char* blocked_ac_find(const char *const search_str, gboolean previous);
void blocked_ac_reset(void);
void form_destroy(DataForm *form);

View File

@ -56,7 +56,7 @@ void p_gpg_free_keys(GHashTable *keys) {}
void p_gpg_autocomplete_key_reset(void) {}
char * p_gpg_autocomplete_key(const char * const search_str)
char * p_gpg_autocomplete_key(const char * const search_str, gboolean previous)
{
return NULL;
}

View File

@ -24,7 +24,7 @@ void reset_after_create(void **state)
void find_after_create(void **state)
{
Autocomplete ac = autocomplete_new();
autocomplete_complete(ac, "hello", TRUE);
autocomplete_complete(ac, "hello", TRUE, FALSE);
autocomplete_clear(ac);
}
@ -43,7 +43,7 @@ void add_one_and_complete(void **state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
char *result = autocomplete_complete(ac, "Hel", TRUE);
char *result = autocomplete_complete(ac, "Hel", TRUE, FALSE);
assert_string_equal("Hello", result);
@ -55,7 +55,7 @@ void add_two_and_complete_returns_first(void **state)
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Help");
char *result = autocomplete_complete(ac, "Hel", TRUE);
char *result = autocomplete_complete(ac, "Hel", TRUE, FALSE);
assert_string_equal("Hello", result);
@ -67,8 +67,8 @@ void add_two_and_complete_returns_second(void **state)
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Help");
char *result1 = autocomplete_complete(ac, "Hel", TRUE);
char *result2 = autocomplete_complete(ac, result1, TRUE);
char *result1 = autocomplete_complete(ac, "Hel", TRUE, FALSE);
char *result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
assert_string_equal("Help", result2);
@ -123,7 +123,7 @@ void complete_accented_with_accented(void **state)
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "èâîô");
char *result = autocomplete_complete(ac, "èâ", TRUE);
char *result = autocomplete_complete(ac, "èâ", TRUE, FALSE);
assert_string_equal("èâîô", result);
@ -135,7 +135,7 @@ void complete_accented_with_base(void **state)
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "èâîô");
char *result = autocomplete_complete(ac, "ea", TRUE);
char *result = autocomplete_complete(ac, "ea", TRUE, FALSE);
assert_string_equal("èâîô", result);
@ -148,8 +148,8 @@ void complete_both_with_accented(void **state)
autocomplete_add(ac, "eaooooo");
autocomplete_add(ac, "èâîô");
char *result1 = autocomplete_complete(ac, "èâ", TRUE);
char *result2 = autocomplete_complete(ac, result1, TRUE);
char *result1 = autocomplete_complete(ac, "èâ", TRUE, FALSE);
char *result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
assert_string_equal("èâîô", result2);
@ -162,8 +162,8 @@ void complete_both_with_base(void **state)
autocomplete_add(ac, "eaooooo");
autocomplete_add(ac, "èâîô");
char *result1 = autocomplete_complete(ac, "ea", TRUE);
char *result2 = autocomplete_complete(ac, result1, TRUE);
char *result1 = autocomplete_complete(ac, "ea", TRUE, FALSE);
char *result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
assert_string_equal("èâîô", result2);
@ -175,9 +175,26 @@ void complete_ignores_case(void **state)
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "MyBuddy");
char *result = autocomplete_complete(ac, "myb", TRUE);
char *result = autocomplete_complete(ac, "myb", TRUE, FALSE);
assert_string_equal("MyBuddy", result);
autocomplete_clear(ac);
}
void complete_previous(void **state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "MyBuddy1");
autocomplete_add(ac, "MyBuddy2");
autocomplete_add(ac, "MyBuddy3");
char *result1 = autocomplete_complete(ac, "myb", TRUE, FALSE);
char *result2 = autocomplete_complete(ac, result1, TRUE, FALSE);
char *result3 = autocomplete_complete(ac, result2, TRUE, FALSE);
char *result4 = autocomplete_complete(ac, result3, TRUE, TRUE);
assert_string_equal("MyBuddy2", result4);
autocomplete_clear(ac);
}

View File

@ -13,3 +13,4 @@ void complete_accented_with_base(void **state);
void complete_both_with_accented(void **state);
void complete_both_with_base(void **state);
void complete_ignores_case(void **state);
void complete_previous(void **state);

View File

@ -158,7 +158,7 @@ void find_first_exists(void **state)
char *search = strdup("B");
char *result = roster_contact_autocomplete(search);
char *result = roster_contact_autocomplete(search, FALSE);
assert_string_equal("Bob", result);
free(result);
free(search);
@ -172,7 +172,7 @@ void find_second_exists(void **state)
roster_add("Dave", NULL, NULL, NULL, FALSE);
roster_add("Bob", NULL, NULL, NULL, FALSE);
char *result = roster_contact_autocomplete("Dav");
char *result = roster_contact_autocomplete("Dav", FALSE);
assert_string_equal("Dave", result);
free(result);
roster_destroy();
@ -185,7 +185,7 @@ void find_third_exists(void **state)
roster_add("Dave", NULL, NULL, NULL, FALSE);
roster_add("Bob", NULL, NULL, NULL, FALSE);
char *result = roster_contact_autocomplete("Ja");
char *result = roster_contact_autocomplete("Ja", FALSE);
assert_string_equal("James", result);
free(result);
roster_destroy();
@ -198,7 +198,7 @@ void find_returns_null(void **state)
roster_add("Dave", NULL, NULL, NULL, FALSE);
roster_add("Bob", NULL, NULL, NULL, FALSE);
char *result = roster_contact_autocomplete("Mike");
char *result = roster_contact_autocomplete("Mike", FALSE);
assert_null(result);
roster_destroy();
}
@ -206,7 +206,7 @@ void find_returns_null(void **state)
void find_on_empty_returns_null(void **state)
{
roster_create();
char *result = roster_contact_autocomplete("James");
char *result = roster_contact_autocomplete("James", FALSE);
assert_null(result);
roster_destroy();
}
@ -218,8 +218,8 @@ void find_twice_returns_second_when_two_match(void **state)
roster_add("Jamie", NULL, NULL, NULL, FALSE);
roster_add("Bob", NULL, NULL, NULL, FALSE);
char *result1 = roster_contact_autocomplete("Jam");
char *result2 = roster_contact_autocomplete(result1);
char *result1 = roster_contact_autocomplete("Jam", FALSE);
char *result2 = roster_contact_autocomplete(result1, FALSE);
assert_string_equal("Jamie", result2);
free(result1);
free(result2);
@ -240,11 +240,11 @@ void find_five_times_finds_fifth(void **state)
roster_add("Jamy", NULL, NULL, NULL, FALSE);
roster_add("Jamz", NULL, NULL, NULL, FALSE);
char *result1 = roster_contact_autocomplete("Jam");
char *result2 = roster_contact_autocomplete(result1);
char *result3 = roster_contact_autocomplete(result2);
char *result4 = roster_contact_autocomplete(result3);
char *result5 = roster_contact_autocomplete(result4);
char *result1 = roster_contact_autocomplete("Jam", FALSE);
char *result2 = roster_contact_autocomplete(result1, FALSE);
char *result3 = roster_contact_autocomplete(result2, FALSE);
char *result4 = roster_contact_autocomplete(result3, FALSE);
char *result5 = roster_contact_autocomplete(result4, FALSE);
assert_string_equal("Jamo", result5);
free(result1);
free(result2);
@ -261,9 +261,9 @@ void find_twice_returns_first_when_two_match_and_reset(void **state)
roster_add("Jamie", NULL, NULL, NULL, FALSE);
roster_add("Bob", NULL, NULL, NULL, FALSE);
char *result1 = roster_contact_autocomplete("Jam");
char *result1 = roster_contact_autocomplete("Jam", FALSE);
roster_reset_search_attempts();
char *result2 = roster_contact_autocomplete(result1);
char *result2 = roster_contact_autocomplete(result1, FALSE);
assert_string_equal("James", result2);
free(result1);
free(result2);

View File

@ -408,7 +408,7 @@ void cons_check_version(gboolean not_available_msg) {}
void cons_show_typing(const char * const barejid) {}
void cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index, gboolean mention, GList *triggers, int unread) {}
void cons_show_incoming_message(const char * const short_from, const int win_index, int unread) {}
void cons_show_room_invites(GSList *invites) {}
void cons_show_room_invites(GList *invites) {}
void cons_show_received_subs(void) {}
void cons_show_sent_subs(void) {}
void cons_alert(void) {}

View File

@ -95,6 +95,7 @@ int main(int argc, char* argv[]) {
unit_test(complete_both_with_accented),
unit_test(complete_both_with_base),
unit_test(complete_ignores_case),
unit_test(complete_previous),
unit_test(create_jid_from_null_returns_null),
unit_test(create_jid_from_empty_string_returns_null),

View File

@ -128,7 +128,7 @@ void message_send_invite(const char * const room, const char * const contact,
// presence functions
void presence_subscription(const char * const jid, const jabber_subscr_t action) {}
GSList* presence_get_subscription_requests(void)
GList* presence_get_subscription_requests(void)
{
return NULL;
}
@ -140,7 +140,7 @@ gint presence_sub_request_count(void)
void presence_reset_sub_request_search(void) {}
char * presence_sub_request_find(const char * const search_str)
char * presence_sub_request_find(const char * const search_str, gboolean previous)
{
return NULL;
}
@ -250,7 +250,7 @@ GList * bookmark_get_list(void)
return (GList *)mock();
}
char * bookmark_find(const char * const search_str)
char * bookmark_find(const char * const search_str, gboolean previous)
{
return NULL;
}
@ -298,7 +298,7 @@ gboolean blocked_remove(char *jid)
return TRUE;
}
char* blocked_ac_find(const char *const search_str)
char* blocked_ac_find(const char *const search_str, gboolean previous)
{
return NULL;
}