mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
core: fix renaming of options with command /item rename (closes #1978)
The options `weechat.custom_bar_item.xxx.*` are now properly renamed to the new item name. This fixes a save issue (item saved with old name in config) and a crash if a new item is created with the old name.
This commit is contained in:
@@ -27,6 +27,7 @@ New features::
|
||||
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user