diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 89f41e168..9884c6b50 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -15,6 +15,7 @@ For a list of important changes that require manual actions, please look at rele Bug fixes:: + * core: fix renaming of options with command `/item rename` (issue #1978) * core: don't send "key_pressed" signal again for the same key press (issue #1976) * core: don't send "key_combo_*" signals for incomplete keys (issue #1976) * core: add key ctrl-backspace in /help key (issue #1975) diff --git a/src/gui/gui-bar-item-custom.c b/src/gui/gui-bar-item-custom.c index 2864f3cb2..64065c1fe 100644 --- a/src/gui/gui-bar-item-custom.c +++ b/src/gui/gui-bar-item-custom.c @@ -443,10 +443,18 @@ gui_bar_item_custom_new (const char *name, const char *conditions, name, GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS, conditions); + if (!option_conditions) + return NULL; + option_content = gui_bar_item_custom_create_option ( name, GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT, content); + if (!option_content) + { + config_file_option_free (option_conditions, 0); + return NULL; + } new_bar_item_custom = gui_bar_item_custom_new_with_options ( name, @@ -517,21 +525,48 @@ int gui_bar_item_custom_rename (struct t_gui_bar_item_custom *item, const char *new_name) { + char *old_name, *option_name; + int i, length; + if (!item || !gui_bar_item_custom_name_valid (new_name)) return 0; if (gui_bar_item_custom_search (new_name)) return 0; + old_name = strdup (item->name); + if (!old_name) + return 0; + + length = strlen (new_name) + 128; + option_name = malloc (length); + if (!option_name) + { + free (old_name); + return 0; + } + free (item->bar_item->name); item->bar_item->name = strdup (new_name); - gui_bar_item_update (item->name); - gui_bar_item_update (item->bar_item->name); - free (item->name); item->name = strdup (new_name); + for (i = 0; i < GUI_BAR_ITEM_CUSTOM_NUM_OPTIONS; i++) + { + snprintf (option_name, length, + "%s.%s", + new_name, + gui_bar_item_custom_option_string[i]); + config_file_option_rename (item->options[i], option_name); + } + + gui_bar_item_update (old_name); + gui_bar_item_update (item->name); + + free (old_name); + free (option_name); + return 1; } diff --git a/tests/unit/gui/test-gui-bar-item-custom.cpp b/tests/unit/gui/test-gui-bar-item-custom.cpp index 4ac1a849c..f3c221851 100644 --- a/tests/unit/gui/test-gui-bar-item-custom.cpp +++ b/tests/unit/gui/test-gui-bar-item-custom.cpp @@ -455,6 +455,9 @@ TEST(GuiBarItemCustom, Rename) CHECK(new_item->bar_item); STRCMP_EQUAL("test3", new_item->bar_item->name); + STRCMP_EQUAL("test3.conditions", new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONDITIONS]->name); + STRCMP_EQUAL("test3.content", new_item->options[GUI_BAR_ITEM_CUSTOM_OPTION_CONTENT]->name); + gui_bar_item_custom_free (new_item); gui_bar_item_custom_free (new_item2); }