diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-15 20:52:51 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-25 16:35:28 +0200 |
commit | fc1a69957354ff7908c0f22ee8d8e09c0628690c (patch) | |
tree | 7c6519b59e3e2984af701f5e7d7a691ffd0232b3 | |
parent | f7516bd6d86a451f141a860d1e7669316af37bbd (diff) | |
download | weechat-fc1a69957354ff7908c0f22ee8d8e09c0628690c.zip |
fset: fix refresh of options after changing marked options
-rw-r--r-- | src/plugins/fset/fset-command.c | 16 | ||||
-rw-r--r-- | src/plugins/fset/fset-option.c | 79 | ||||
-rw-r--r-- | src/plugins/fset/fset-option.h | 3 |
3 files changed, 85 insertions, 13 deletions
diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c index 53993054a..5d709386e 100644 --- a/src/plugins/fset/fset-command.c +++ b/src/plugins/fset/fset-command.c @@ -237,7 +237,7 @@ fset_command_fset (const void *pointer, void *data, { if (fset_option_count_marked > 0) { - fset_option_config_changed_timer = 1; + fset_option_enable_timer_config_changed (); num_options = weechat_arraylist_size (fset_options); for (i = 0; i < num_options; i++) { @@ -249,7 +249,7 @@ fset_command_fset (const void *pointer, void *data, fset_option_toggle_value (ptr_fset_option, ptr_option); } } - fset_option_config_changed_timer = 0; + fset_option_disable_timer_config_changed (); } else { @@ -267,7 +267,7 @@ fset_command_fset (const void *pointer, void *data, if (fset_option_count_marked > 0) { - fset_option_config_changed_timer = 1; + fset_option_enable_timer_config_changed (); num_options = weechat_arraylist_size (fset_options); for (i = 0; i < num_options; i++) { @@ -279,7 +279,7 @@ fset_command_fset (const void *pointer, void *data, fset_option_add_value (ptr_fset_option, ptr_option, value); } } - fset_option_config_changed_timer = 0; + fset_option_disable_timer_config_changed (); } else { @@ -303,7 +303,7 @@ fset_command_fset (const void *pointer, void *data, { if (fset_option_count_marked > 0) { - fset_option_config_changed_timer = 1; + fset_option_enable_timer_config_changed (); num_options = weechat_arraylist_size (fset_options); for (i = 0; i < num_options; i++) { @@ -315,7 +315,7 @@ fset_command_fset (const void *pointer, void *data, fset_option_reset_value (ptr_fset_option, ptr_option); } } - fset_option_config_changed_timer = 0; + fset_option_disable_timer_config_changed (); } else { @@ -329,7 +329,7 @@ fset_command_fset (const void *pointer, void *data, { if (fset_option_count_marked > 0) { - fset_option_config_changed_timer = 1; + fset_option_enable_timer_config_changed (); num_options = weechat_arraylist_size (fset_options); for (i = 0; i < num_options; i++) { @@ -341,7 +341,7 @@ fset_command_fset (const void *pointer, void *data, fset_option_unset_value (ptr_fset_option, ptr_option); } } - fset_option_config_changed_timer = 0; + fset_option_disable_timer_config_changed (); } else { diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index 849b5983c..fb6b929fa 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -42,7 +42,8 @@ struct t_hashtable *fset_option_filter_hashtable_extra_vars = NULL; struct t_hashtable *fset_option_filter_hashtable_options = NULL; /* refresh */ -int fset_option_config_changed_timer = 0; +int fset_option_config_changed_use_timer = 0; +struct t_hashtable *fset_option_timer_options_changed = NULL; struct t_hook *fset_option_timer_hook = NULL; /* types */ @@ -1153,7 +1154,7 @@ fset_option_config_changed (const char *option_name) full_refresh = 1; } } - else if (!ptr_option) + else if (ptr_option) { /* option added: get options and refresh the whole buffer */ full_refresh = 1; @@ -1162,6 +1163,7 @@ fset_option_config_changed (const char *option_name) if (full_refresh) { fset_option_get_options (); + fset_buffer_selected_line = 0; fset_buffer_refresh (1); } else @@ -1185,6 +1187,24 @@ fset_option_config_changed (const char *option_name) } /* + * Callback called by the timer for each option changed. + */ + +void +fset_option_timer_option_changed_cb (void *data, + struct t_hashtable *hashtable, + const void *key, + const void *value) +{ + /* make C compiler happy */ + (void) data; + (void) hashtable; + (void) value; + + fset_option_config_changed (key); +} + +/* * Callback for timer after an option is changed. */ @@ -1195,9 +1215,21 @@ fset_option_config_timer_cb (const void *pointer, { /* make C compiler happy */ (void) pointer; + (void) data; (void) remaining_calls; - fset_option_config_changed ((const char *)data); + if (fset_option_timer_options_changed) + { + weechat_hashtable_map (fset_option_timer_options_changed, + &fset_option_timer_option_changed_cb, + NULL); + weechat_hashtable_free (fset_option_timer_options_changed); + fset_option_timer_options_changed = NULL; + } + else + { + fset_option_config_changed (NULL); + } fset_option_timer_hook = NULL; @@ -1230,7 +1262,7 @@ fset_option_config_cb (const void *pointer, if (ptr_info && (strcmp (ptr_info, "1") == 0)) return WEECHAT_RC_OK; - if (fset_option_config_changed_timer) + if (fset_option_config_changed_use_timer) { if (!fset_option_timer_hook) { @@ -1238,6 +1270,8 @@ fset_option_config_cb (const void *pointer, 1, 0, 1, &fset_option_config_timer_cb, NULL, NULL); } + weechat_hashtable_set (fset_option_timer_options_changed, + option, NULL); } else { @@ -1248,6 +1282,38 @@ fset_option_config_cb (const void *pointer, } /* + * Enables a timer when options are changed. + */ + +void +fset_option_enable_timer_config_changed () +{ + if (fset_option_timer_options_changed) + { + weechat_hashtable_remove_all (fset_option_timer_options_changed); + } + else + { + fset_option_timer_options_changed = weechat_hashtable_new ( + 32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, NULL); + } + fset_option_config_changed_use_timer = 1; +} + +/* + * Disables timer when options are changed. + */ + +void +fset_option_disable_timer_config_changed () +{ + fset_option_config_changed_use_timer = 0; +} + +/* * Returns hdata for option. */ @@ -1480,4 +1546,9 @@ fset_option_end () weechat_hashtable_free (fset_option_filter_hashtable_options); fset_option_filter_hashtable_options = NULL; } + if (fset_option_timer_options_changed) + { + weechat_hashtable_free (fset_option_timer_options_changed); + fset_option_timer_options_changed = NULL; + } } diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h index 64c3e851e..0e7364734 100644 --- a/src/plugins/fset/fset-option.h +++ b/src/plugins/fset/fset-option.h @@ -56,7 +56,6 @@ extern struct t_arraylist *fset_options; extern int fset_option_count_marked; extern struct t_hashtable *fset_option_max_length_field; extern char *fset_option_filter; -extern int fset_option_config_changed_timer; extern char *fset_option_type_string[]; extern char *fset_option_type_string_short[]; extern char *fset_option_type_string_tiny[]; @@ -93,6 +92,8 @@ extern int fset_option_config_cb (const void *pointer, void *data, const char *option, const char *value); +extern void fset_option_enable_timer_config_changed (); +extern void fset_option_disable_timer_config_changed (); extern struct t_hdata *fset_option_hdata_option_cb (const void *pointer, void *data, const char *hdata_name); |