about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-23 23:53:20 +0000
committerJames Booth <boothj5@gmail.com>2014-01-23 23:53:20 +0000
commit5d85974bc0d56cdcd3c1a84040a26bdcc7f17325 (patch)
tree6a84e103082dd294edf75b40739b705db982dbd0 /src
parent66631308a5f09645fa8975a19615b6c1127031a4 (diff)
downloadprofani-tty-5d85974bc0d56cdcd3c1a84040a26bdcc7f17325.tar.gz
Added aliases to autocomplete
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c30
-rw-r--r--src/command/command.h2
-rw-r--r--src/command/commands.c9
-rw-r--r--src/ui/console.c7
-rw-r--r--src/ui/ui.h1
5 files changed, 40 insertions, 9 deletions
diff --git a/src/command/command.c b/src/command/command.c
index c933bff4..1ef27e21 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -547,7 +547,7 @@ static struct cmd_t command_defs[] =
           NULL } } },
 
     { "/alias",
-        cmd_alias, parse_args_with_freetext, 1, 3, &cons_alias_setting,
+        cmd_alias, parse_args_with_freetext, 1, 3, NULL,
         { "/alias add|remove|list [name value]", "Add your own command aliases.",
         { "/alias add|remove|list [name value]",
           "-----------------------------------",
@@ -907,6 +907,18 @@ cmd_init(void)
         autocomplete_add(help_ac, pcmd->cmd+1);
     }
 
+    // load aliases
+    GList *aliases = prefs_get_aliases();
+    GList *curr = aliases;
+    while (curr != NULL) {
+        ProfAlias *alias = curr->data;
+        GString *ac_alias = g_string_new("/");
+        g_string_append(ac_alias, alias->name);
+        autocomplete_add(commands_ac, ac_alias->str);
+        g_string_free(ac_alias, TRUE);
+        curr = g_list_next(curr);
+    }
+
     prefs_ac = autocomplete_new();
     autocomplete_add(prefs_ac, "ui");
     autocomplete_add(prefs_ac, "desktop");
@@ -1096,6 +1108,22 @@ cmd_uninit(void)
     autocomplete_free(alias_ac);
 }
 
+void
+cmd_autocomplete_add(char *value)
+{
+    if (commands_ac != NULL) {
+        autocomplete_add(commands_ac, value);
+    }
+}
+
+void
+cmd_autocomplete_remove(char *value)
+{
+    if (commands_ac != NULL) {
+        autocomplete_remove(commands_ac, value);
+    }
+}
+
 // Command autocompletion functions
 void
 cmd_autocomplete(char *input, int *size)
diff --git a/src/command/command.h b/src/command/command.h
index ddf19ff7..fd641302 100644
--- a/src/command/command.h
+++ b/src/command/command.h
@@ -32,6 +32,8 @@ void cmd_uninit(void);
 
 void cmd_autocomplete(char *input, int *size);
 void cmd_reset_autocomplete(void);
+void cmd_autocomplete_add(char *value);
+void cmd_autocomplete_remove(char *value);
 
 gboolean cmd_execute(const char * const command, const char * const inp);
 gboolean cmd_execute_alias(const char * const inp, gboolean *ran);
diff --git a/src/command/commands.c b/src/command/commands.c
index 5d30d183..cd82f9f6 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -27,6 +27,7 @@
 
 #include "chat_session.h"
 #include "command/commands.h"
+#include "command/command.h"
 #include "common.h"
 #include "config/accounts.h"
 #include "config/account.h"
@@ -1835,6 +1836,10 @@ cmd_alias(gchar **args, struct cmd_help_t help)
                 return TRUE;
             } else {
                 if (prefs_add_alias(alias, value) == TRUE) {
+                    GString *ac_value = g_string_new("/");
+                    g_string_append(ac_value, alias);
+                    cmd_autocomplete_add(ac_value->str);
+                    g_string_free(ac_value, TRUE);
                     cons_show("Command alias added /%s -> %s", alias, value);
                 } else {
                     cons_show("Command alias /%s already exists.", alias);
@@ -1852,6 +1857,10 @@ cmd_alias(gchar **args, struct cmd_help_t help)
             if (!removed) {
                 cons_show("No such command alias /%s", alias);
             } else {
+                GString *ac_value = g_string_new("/");
+                g_string_append(ac_value, alias);
+                cmd_autocomplete_remove(ac_value->str);
+                g_string_free(ac_value, TRUE);
                 cons_show("Command alias removed -> /%s", alias);
             }
             return TRUE;
diff --git a/src/ui/console.c b/src/ui/console.c
index 0a8b3be2..28f89b7d 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -918,12 +918,6 @@ _cons_show_aliases(GList *aliases)
 }
 
 static void
-_cons_alias_setting(void)
-{
-    cons_show("Alias setting TODO");
-}
-
-static void
 _cons_theme_setting(void)
 {
     gchar *theme = prefs_get_string(PREF_THEME);
@@ -1628,7 +1622,6 @@ console_init_module(void)
     cons_mouse_setting = _cons_mouse_setting;
     cons_statuses_setting = _cons_statuses_setting;
     cons_titlebar_setting = _cons_titlebar_setting;
-    cons_alias_setting = _cons_alias_setting;
     cons_show_ui_prefs = _cons_show_ui_prefs;
     cons_notify_setting = _cons_notify_setting;
     cons_show_desktop_prefs = _cons_show_desktop_prefs;
diff --git a/src/ui/ui.h b/src/ui/ui.h
index cdd25ced..9671b1af 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -203,7 +203,6 @@ void (*cons_show_received_subs)(void);
 void (*cons_show_sent_subs)(void);
 void (*cons_alert)(void);
 void (*cons_theme_setting)(void);
-void (*cons_alias_setting)(void);
 void (*cons_beep_setting)(void);
 void (*cons_flash_setting)(void);
 void (*cons_splash_setting)(void);