diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-04-01 16:00:44 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-04-01 16:00:44 +0200 |
commit | a03232e155e1d23269673cbcd2c9954ee9122340 (patch) | |
tree | 2da56c8502fe8d65a7d5dae5fa1c21bedeb7e173 /src | |
parent | af32279dc5b1ebc8bb9a2aa087f2745f70d91639 (diff) | |
download | weechat-a03232e155e1d23269673cbcd2c9954ee9122340.zip |
core: add default key alt-'-' to toggle filters in current buffer (closes #17)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 129 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 11 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-key.c | 1 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 32 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 1 | ||||
-rw-r--r-- | src/gui/gui-filter.c | 4 |
6 files changed, 125 insertions, 53 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index d33d4373f..f38477878 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1823,7 +1823,6 @@ COMMAND_CALLBACK(filter) /* make C compiler happy */ (void) data; - (void) buffer; if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) @@ -1860,26 +1859,41 @@ COMMAND_CALLBACK(filter) { if (argc > 2) { - /* enable a filter */ - ptr_filter = gui_filter_search_by_name (argv[2]); - if (ptr_filter) + if (strcmp (argv[2], "@") == 0) { - if (!ptr_filter->enabled) + /* enable filters in buffer */ + if (!buffer->filter) { - ptr_filter->enabled = 1; - gui_filter_all_buffers (); - gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, - _("Filter \"%s\" enabled"), - ptr_filter->name); + buffer->filter = 1; + gui_filter_buffer (buffer, NULL); } } else { - gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, - _("%sError: filter \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[2]); - return WEECHAT_RC_OK; + /* enable a filter */ + ptr_filter = gui_filter_search_by_name (argv[2]); + if (ptr_filter) + { + if (!ptr_filter->enabled) + { + ptr_filter->enabled = 1; + gui_filter_all_buffers (); + gui_chat_printf_date_tags (NULL, 0, + GUI_FILTER_TAG_NO_FILTER, + _("Filter \"%s\" enabled"), + ptr_filter->name); + } + } + else + { + gui_chat_printf_date_tags (NULL, 0, + GUI_FILTER_TAG_NO_FILTER, + _("%sError: filter \"%s\" not " + "found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + return WEECHAT_RC_OK; + } } } else @@ -1900,26 +1914,41 @@ COMMAND_CALLBACK(filter) { if (argc > 2) { - /* disable a filter */ - ptr_filter = gui_filter_search_by_name (argv[2]); - if (ptr_filter) + if (strcmp (argv[2], "@") == 0) { - if (ptr_filter->enabled) + /* disable filters in buffer */ + if (buffer->filter) { - ptr_filter->enabled = 0; - gui_filter_all_buffers (); - gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, - _("Filter \"%s\" disabled"), - ptr_filter->name); + buffer->filter = 0; + gui_filter_buffer (buffer, NULL); } } else { - gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, - _("%sError: filter \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[2]); - return WEECHAT_RC_OK; + /* disable a filter */ + ptr_filter = gui_filter_search_by_name (argv[2]); + if (ptr_filter) + { + if (ptr_filter->enabled) + { + ptr_filter->enabled = 0; + gui_filter_all_buffers (); + gui_chat_printf_date_tags (NULL, 0, + GUI_FILTER_TAG_NO_FILTER, + _("Filter \"%s\" disabled"), + ptr_filter->name); + } + } + else + { + gui_chat_printf_date_tags (NULL, 0, + GUI_FILTER_TAG_NO_FILTER, + _("%sError: filter \"%s\" not " + "found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + return WEECHAT_RC_OK; + } } } else @@ -1940,20 +1969,31 @@ COMMAND_CALLBACK(filter) { if (argc > 2) { - /* toggle a filter */ - ptr_filter = gui_filter_search_by_name (argv[2]); - if (ptr_filter) + if (strcmp (argv[2], "@") == 0) { - ptr_filter->enabled ^= 1; - gui_filter_all_buffers (); + /* toggle filters in buffer */ + buffer->filter ^= 1; + gui_filter_buffer (buffer, NULL); } else { - gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, - _("%sError: filter \"%s\" not found"), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - argv[2]); - return WEECHAT_RC_OK; + /* toggle a filter */ + ptr_filter = gui_filter_search_by_name (argv[2]); + if (ptr_filter) + { + ptr_filter->enabled ^= 1; + gui_filter_all_buffers (); + } + else + { + gui_chat_printf_date_tags (NULL, 0, + GUI_FILTER_TAG_NO_FILTER, + _("%sError: filter \"%s\" not " + "found"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + return WEECHAT_RC_OK; + } } } else @@ -6872,7 +6912,7 @@ command_init () N_("filter messages in buffers, to hide/show them according to tags or " "regex"), N_("list" - " || enable|disable|toggle [<name>]" + " || enable|disable|toggle [<name>|@]" " || add <name> <buffer>[,<buffer>...] <tags> <regex>" " || rename <name> <new_name>" " || del <name>|-all"), @@ -6880,7 +6920,8 @@ command_init () " enable: enable filters (filters are enabled by default)\n" "disable: disable filters\n" " toggle: toggle filters\n" - " name: filter name\n" + " name: filter name (\"@\" = enable/disable all filters in current " + "buffer)\n" " add: add a filter\n" " rename: rename a filter\n" " del: delete a filter\n" @@ -6936,9 +6977,9 @@ command_init () " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" " /filter add sucks irc.freenode.#weechat * weechat sucks"), "list" - " || enable %(filters_names)" - " || disable %(filters_names)" - " || toggle %(filters_names)" + " || enable %(filters_names)|@" + " || disable %(filters_names)|@" + " || toggle %(filters_names)|@" " || add %(filters_names) %(buffers_plugins_names)|*" " || rename %(filters_names) %(filters_names)" " || del %(filters_names)|-all", diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index ccc24ef37..0e1b6a242 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -481,6 +481,7 @@ upgrade_weechat_read_cb (void *data, { upgrade_current_buffer->day_change = 1; } + /* "clear" is in WeeChat >= 0.4.4 */ if (infolist_search_var (infolist, "clear")) { upgrade_current_buffer->clear = @@ -492,6 +493,16 @@ upgrade_weechat_read_cb (void *data, (upgrade_current_buffer->type == GUI_BUFFER_TYPE_FREE) ? 0 : 1; } + /* "filter" is in WeeChat >= 0.4.4 */ + if (infolist_search_var (infolist, "filter")) + { + upgrade_current_buffer->filter = + infolist_integer (infolist, "filter"); + } + else + { + upgrade_current_buffer->filter = 1; + } upgrade_current_buffer->nicklist_case_sensitive = infolist_integer (infolist, "nicklist_case_sensitive"); upgrade_current_buffer->nicklist_display_groups = diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c index 167c821a6..d05e8d37f 100644 --- a/src/gui/curses/gui-curses-key.c +++ b/src/gui/curses/gui-curses-key.c @@ -199,6 +199,7 @@ gui_key_default_bindings (int context) BIND(/* m-w,m-s */ "meta-wmeta-s", "/window swap"); BIND(/* m-z */ "meta-z", "/window zoom"); BIND(/* m-= */ "meta-=", "/filter toggle"); + BIND(/* m-= */ "meta--", "/filter toggle @"); BIND(/* m-0 */ "meta-0", "/buffer *10"); BIND(/* m-1 */ "meta-1", "/buffer *1"); BIND(/* m-2 */ "meta-2", "/buffer *2"); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 81567bc5b..05bf6ce58 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -48,6 +48,7 @@ #include "gui-chat.h" #include "gui-color.h" #include "gui-completion.h" +#include "gui-filter.h" #include "gui-history.h" #include "gui-hotlist.h" #include "gui-input.h" @@ -77,7 +78,7 @@ char *gui_buffer_notify_string[GUI_BUFFER_NUM_NOTIFY] = char *gui_buffer_properties_get_integer[] = { "number", "layout_number", "layout_number_merge_order", "type", "notify", "num_displayed", "active", "zoomed", "print_hooks_enabled", "day_change", - "clear", "lines_hidden", "prefix_max_length", "time_for_each_line", + "clear", "filter", "lines_hidden", "prefix_max_length", "time_for_each_line", "nicklist", "nicklist_case_sensitive", "nicklist_max_length", "nicklist_display_groups", "nicklist_count", "nicklist_groups_count", "nicklist_nicks_count", "nicklist_visible_count", "input", @@ -97,12 +98,12 @@ char *gui_buffer_properties_get_pointer[] = NULL }; char *gui_buffer_properties_set[] = -{ "unread", "display", "print_hooks_enabled", "day_change", "clear", "number", - "name", "short_name", "type", "notify", "title", "time_for_each_line", - "nicklist", "nicklist_case_sensitive", "nicklist_display_groups", - "highlight_words", "highlight_words_add", "highlight_words_del", - "highlight_regex", "highlight_tags_restrict", "highlight_tags", - "hotlist_max_level_nicks", "hotlist_max_level_nicks_add", +{ "unread", "display", "print_hooks_enabled", "day_change", "clear", "filter", + "number", "name", "short_name", "type", "notify", "title", + "time_for_each_line", "nicklist", "nicklist_case_sensitive", + "nicklist_display_groups", "highlight_words", "highlight_words_add", + "highlight_words_del", "highlight_regex", "highlight_tags_restrict", + "highlight_tags", "hotlist_max_level_nicks", "hotlist_max_level_nicks_add", "hotlist_max_level_nicks_del", "input", "input_pos", "input_get_unknown_commands", NULL @@ -595,6 +596,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin, new_buffer->print_hooks_enabled = 1; new_buffer->day_change = 1; new_buffer->clear = 1; + new_buffer->filter = 1; /* close callback */ new_buffer->close_callback = close_callback; @@ -987,6 +989,8 @@ gui_buffer_get_integer (struct t_gui_buffer *buffer, const char *property) return buffer->day_change; else if (string_strcasecmp (property, "clear") == 0) return buffer->clear; + else if (string_strcasecmp (property, "filter") == 0) + return buffer->filter; else if (string_strcasecmp (property, "lines_hidden") == 0) return buffer->lines->lines_hidden; else if (string_strcasecmp (property, "prefix_max_length") == 0) @@ -1768,6 +1772,16 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, if (error && !error[0]) buffer->clear = (number) ? 1 : 0; } + else if (string_strcasecmp (property, "filter") == 0) + { + error = NULL; + number = strtol (value, &error, 10); + if (error && !error[0]) + { + buffer->filter = (number) ? 1 : 0; + gui_filter_buffer (buffer, NULL); + } + } else if (string_strcasecmp (property, "number") == 0) { error = NULL; @@ -3831,6 +3845,7 @@ gui_buffer_hdata_buffer_cb (void *data, const char *hdata_name) HDATA_VAR(struct t_gui_buffer, print_hooks_enabled, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, day_change, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, clear, INTEGER, 0, NULL, NULL); + HDATA_VAR(struct t_gui_buffer, filter, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, close_callback, POINTER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, close_callback_data, POINTER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, title, STRING, 0, NULL, NULL); @@ -4011,6 +4026,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_integer (ptr_item, "clear", buffer->clear)) return 0; + if (!infolist_new_var_integer (ptr_item, "filter", buffer->filter)) + return 0; if (!infolist_new_var_integer (ptr_item, "first_line_not_read", buffer->lines->first_line_not_read)) return 0; if (!infolist_new_var_integer (ptr_item, "lines_hidden", buffer->lines->lines_hidden)) @@ -4219,6 +4236,7 @@ gui_buffer_print_log () log_printf (" print_hooks_enabled . . : %d", ptr_buffer->print_hooks_enabled); log_printf (" day_change. . . . . . . : %d", ptr_buffer->day_change); log_printf (" clear . . . . . . . . . : %d", ptr_buffer->clear); + log_printf (" filter. . . . . . . . . : %d", ptr_buffer->filter); log_printf (" close_callback. . . . . : 0x%lx", ptr_buffer->close_callback); log_printf (" close_callback_data . . : 0x%lx", ptr_buffer->close_callback_data); log_printf (" title . . . . . . . . . : '%s'", ptr_buffer->title); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 98e6629f6..4c54c1c74 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -102,6 +102,7 @@ struct t_gui_buffer int day_change; /* 1 if "day change" displayed */ int clear; /* 1 if clear of buffer is allowed */ /* with command /buffer clear */ + int filter; /* 1 if filters enabled for buffer */ /* close callback */ int (*close_callback)(void *data, /* called when buffer is closed */ diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index 8e57e58d9..b435e829b 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -61,8 +61,8 @@ gui_filter_check_line (struct t_gui_line_data *line_data) struct t_gui_filter *ptr_filter; int rc; - /* line is always displayed if filters are disabled */ - if (!gui_filters_enabled) + /* line is always displayed if filters are disabled (globally or in buffer) */ + if (!gui_filters_enabled || !line_data->buffer->filter) return 1; if (gui_line_has_tag_no_filter (line_data)) |