From adf547a47c9e194900ea4db95c64f95c7cef265c Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Wed, 5 Feb 2014 10:19:59 +0100 Subject: [PATCH] trigger: add option "addinput" in command /trigger --- src/plugins/trigger/trigger-command.c | 99 +++++++++++++++++------- src/plugins/trigger/trigger-completion.c | 2 +- src/plugins/trigger/trigger.c | 2 +- src/plugins/trigger/trigger.h | 3 +- 4 files changed, 77 insertions(+), 29 deletions(-) diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c index 293a1d8f5..8c4723ec8 100644 --- a/src/plugins/trigger/trigger-command.c +++ b/src/plugins/trigger/trigger-command.c @@ -135,12 +135,11 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc, { struct t_trigger *ptr_trigger; const char *option; - char *value, **sargv; - int i, type, count, index_option, enable, sargc; + char *value, **sargv, **items, input[1024]; + int i, type, count, index_option, enable, sargc, num_items, rc; /* make C compiler happy */ (void) data; - (void) buffer; sargv = NULL; @@ -194,6 +193,13 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc, weechat_printf_tags (NULL, "no_trigger", " command: \"%s\"", option); } + rc = weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE]); + if (rc != TRIGGER_RC_OK) + { + weechat_printf_tags (NULL, "no_trigger", + " return code: %s", + trigger_return_code_string[rc]); + } } } else @@ -268,6 +274,38 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc, goto end; } + /* add trigger command in input (to help trigger creation) */ + if (weechat_strcasecmp (argv[1], "addinput") == 0) + { + type = TRIGGER_HOOK_SIGNAL; + if (argc >= 3) + { + type = trigger_search_hook_type (argv[2]); + if (type < 0) + { + weechat_printf_tags (NULL, "no_trigger", + _("%sError: invalid hook type \"%s\""), + weechat_prefix ("error"), argv[2]); + goto end; + } + } + items = weechat_string_split (trigger_hook_default_rc[type], ",", 0, 0, + &num_items); + snprintf (input, sizeof (input), + "/trigger add name %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s", + trigger_hook_type_string[type], + trigger_hook_default_arguments[type], + trigger_hook_default_conditions[type], + trigger_hook_default_regex[type], + trigger_hook_default_command[type], + (items && (num_items > 0)) ? " \"" : "", + (items && (num_items > 0)) ? items[0] : "", + (items && (num_items > 0)) ? "\"" : ""); + weechat_buffer_set (buffer, "input", input); + weechat_buffer_set (buffer, "input_pos", "13"); + goto end; + } + /* set option in a trigger */ if (weechat_strcasecmp (argv[1], "set") == 0) { @@ -454,35 +492,43 @@ trigger_command_init () N_("list" " || add [\"\" [\"\" " "[\"\" [\"\" [\"\"]]]]]" + " || addinput []" " || set