summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-01-26 08:39:37 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-02-09 12:55:40 +0100
commit4205f7c498da82d4f29b730ec2ceb0cb16202d3d (patch)
tree53befe45c0cb17699afeaf76205d06109ea74fbf /src
parentf92d6e9da3b3cc6153433c9ead05437476ab62c8 (diff)
downloadweechat-4205f7c498da82d4f29b730ec2ceb0cb16202d3d.zip
trigger: add option "rename" in command /trigger
Diffstat (limited to 'src')
-rw-r--r--src/plugins/trigger/trigger-command.c40
-rw-r--r--src/plugins/trigger/trigger.c6
2 files changed, 42 insertions, 4 deletions
diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c
index eaa16d1de..33f3dc5aa 100644
--- a/src/plugins/trigger/trigger-command.c
+++ b/src/plugins/trigger/trigger-command.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "../weechat-plugin.h"
#include "trigger.h"
@@ -38,6 +39,7 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
{
struct t_trigger *ptr_trigger;
const char *option;
+ char *name;
int i, type, count, index_option, enabled;
/* make C compiler happy */
@@ -176,7 +178,7 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
}
if (weechat_strcasecmp (argv[3], "name") == 0)
{
- if (!trigger_rename (ptr_trigger, argv_eol[4]))
+ if (!trigger_rename (ptr_trigger, argv[4]))
return WEECHAT_RC_OK;
}
else
@@ -197,6 +199,39 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
return WEECHAT_RC_OK;
}
+ /* rename a trigger */
+ if (weechat_strcasecmp (argv[1], "rename") == 0)
+ {
+ if (argc < 4)
+ {
+ weechat_printf_tags (NULL, "no_trigger",
+ _("%sError: missing arguments for \"%s\" "
+ "command"),
+ weechat_prefix ("error"), "trigger");
+ return WEECHAT_RC_OK;
+ }
+ ptr_trigger = trigger_search (argv[2]);
+ if (!ptr_trigger)
+ {
+ weechat_printf_tags (NULL, "no_trigger",
+ _("%sTrigger \"%s\" not found"),
+ weechat_prefix ("error"), argv[2]);
+ return WEECHAT_RC_OK;
+ }
+ name = strdup (ptr_trigger->name);
+ if (name)
+ {
+ if (trigger_rename (ptr_trigger, argv[3]))
+ {
+ weechat_printf_tags (NULL, "no_trigger",
+ _("Trigger \"%s\" renamed to \"%s\""),
+ name, ptr_trigger->name);
+ }
+ free (name);
+ }
+ return WEECHAT_RC_OK;
+ }
+
/* delete a trigger */
if (weechat_strcasecmp (argv[1], "del") == 0)
{
@@ -301,6 +336,7 @@ trigger_command_init ()
N_("list"
" || add <name> <hook> [<arguments>]"
" || set <name> <option> <value>"
+ " || rename <name> <new_name>"
" || del <name>|-all [<name>...]"
" || enable|disable|toggle <name>"
" || monitor"),
@@ -319,6 +355,7 @@ trigger_command_init ()
" (for help on option, you can do /help "
"trigger.trigger.<name>.<option>)\n"
" value: new value for the option\n"
+ " rename: rename a trigger\n"
" del: delete a trigger\n"
" -all: delete all triggers\n"
" enable: enable a trigger\n"
@@ -353,6 +390,7 @@ trigger_command_init ()
"list"
" || add %(trigger_names) %(trigger_hooks)"
" || set %(trigger_names) %(trigger_options)|name %(trigger_option_value)"
+ " || rename %(trigger_names) %(trigger_names)"
" || del %(trigger_names)|-all %(trigger_names)|%*"
" || enable|disable|toggle %(trigger_names)"
" || monitor",
diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c
index dad9373b3..de1ee1797 100644
--- a/src/plugins/trigger/trigger.c
+++ b/src/plugins/trigger/trigger.c
@@ -673,9 +673,9 @@ trigger_rename (struct t_trigger *trigger, const char *name)
if (name[0] == '-')
{
- weechat_printf (NULL,
- _("%s%s: name can not start with \"-\""),
- weechat_prefix ("error"), TRIGGER_PLUGIN_NAME);
+ weechat_printf_tags (NULL, "no_trigger",
+ _("%s%s: name can not start with \"-\""),
+ weechat_prefix ("error"), TRIGGER_PLUGIN_NAME);
return 0;
}