summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-07-10 07:31:28 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-07-10 07:31:28 +0200
commit2a02bb10e5b818c9ffabf0c4499a53ba63002b75 (patch)
tree8b9baa7299bdc5fa2a31995131947f73816f409f /src
parent107f83c9230e1bf3e0b2a362f50e00a13932acf9 (diff)
downloadweechat-2a02bb10e5b818c9ffabf0c4499a53ba63002b75.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui-bar-item-custom.c41
1 files changed, 38 insertions, 3 deletions
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;
}