1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 06:46:38 +02:00

core: add /theme reset to restore original themable defaults

This commit is contained in:
Sébastien Helleu
2026-05-27 22:06:23 +02:00
parent ad3b7b825c
commit 2bbcd8a68f
12 changed files with 239 additions and 1 deletions
+10
View File
@@ -7333,6 +7333,12 @@ COMMAND_CALLBACK(theme)
return theme_apply (argv[2]);
}
/* "/theme reset": reset every themable option to its default value */
if (string_strcmp (argv[1], "reset") == 0)
{
return theme_reset ();
}
/* "/theme save <name> [-full]": write a user theme file */
if (string_strcmp (argv[1], "save") == 0)
{
@@ -10073,6 +10079,7 @@ command_init (void)
/* TRANSLATORS: only text between angle brackets (eg: "<name>") may be translated */
N_("[list [-backups]]"
" || apply <name>"
" || reset"
" || save <name> [-full]"
" || delete <name>"
" || info <name>"),
@@ -10086,6 +10093,8 @@ command_init (void)
"value from the theme); if a file named <name>.theme "
"exists in directory \"themes\" it shadows any built-in "
"theme of the same name"),
N_("raw[reset]: reset every themable option to its default "
"value (restores the original look shipped with WeeChat)"),
N_("raw[save]: save current themable options to a file "
"<name>.theme in directory \"themes\"; by default only "
"options whose value differs from their default are "
@@ -10112,6 +10121,7 @@ command_init (void)
"weechat.look.theme_backup.")),
"list -backups"
" || apply %(theme_themes_all)"
" || reset"
" || save %(theme_themes_user) -full"
" || delete %(theme_themes_user)"
" || info %(theme_themes_all)",
+78
View File
@@ -1025,6 +1025,84 @@ theme_apply (const char *name)
return WEECHAT_RC_OK;
}
/*
* Resets every themable option to its default value.
*
* Same backup-first safety as theme_apply: if weechat.look.theme_backup
* is on, a backup file is written before any option is touched, and the
* reset is aborted if the backup cannot be written. The active-theme
* label (weechat.look.theme) is reset to its default (empty string).
*
* Returns WEECHAT_RC_OK on success, WEECHAT_RC_ERROR if the backup is
* required but failed.
*/
int
theme_reset (void)
{
struct t_config_file *ptr_config;
struct t_config_section *ptr_section;
struct t_config_option *ptr_option;
char *backup_name = NULL;
if (CONFIG_BOOLEAN(config_look_theme_backup))
{
backup_name = theme_make_backup ();
if (!backup_name)
{
gui_chat_printf (
NULL,
_("%sUnable to create theme backup; aborting reset "
"(disable option weechat.look.theme_backup to force)"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
return WEECHAT_RC_ERROR;
}
}
/* reset every themable option to its default value; per-option gui
refreshes are suppressed via theme_applying */
theme_applying = 1;
for (ptr_config = config_files; ptr_config;
ptr_config = ptr_config->next_config)
{
for (ptr_section = ptr_config->sections; ptr_section;
ptr_section = ptr_section->next_section)
{
for (ptr_option = ptr_section->options; ptr_option;
ptr_option = ptr_option->next_option)
{
if (ptr_option->themable)
config_file_option_reset (ptr_option, 1);
}
}
}
theme_applying = 0;
if (gui_init_ok)
{
gui_color_init_weechat ();
gui_window_ask_refresh (1);
}
/* clear active-theme label */
config_file_option_reset (config_look_theme, 1);
if (backup_name)
{
gui_chat_printf (
NULL,
_("Previous state saved as theme \"%s\"; to restore: "
"/theme apply %s"),
backup_name, backup_name);
free (backup_name);
}
hook_signal_send ("theme_applied",
WEECHAT_HOOK_SIGNAL_STRING, (char *)"");
return WEECHAT_RC_OK;
}
/*
* Saves the current themable options to a user theme file.
*
+1
View File
@@ -69,6 +69,7 @@ extern const char *theme_get_override (struct t_theme *theme,
const char *option_name);
extern struct t_arraylist *theme_list (void);
extern int theme_apply (const char *name);
extern int theme_reset (void);
extern int theme_save (const char *name, int full);
extern int theme_delete (const char *name);
extern char *theme_make_backup (void);