diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c index 71ec1bf1..1bf0a954 100644 --- a/src/fe-common/core/fe-settings.c +++ b/src/fe-common/core/fe-settings.c @@ -274,24 +274,32 @@ static void settings_save_confirm(const char *line, char *fname) /* SYNTAX: SAVE [] */ static void cmd_save(const char *data) { - char *format; + GHashTable *optlist; + char *format, *fname; + void *free_arg; - if (*data == '\0') - data = mainconfig->fname; - - if (!irssi_config_is_changed(data)) { - settings_save_fe(data); + if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS, + "save", &optlist, &fname)) return; + + if (*fname == '\0') + fname = mainconfig->fname; + + if (!irssi_config_is_changed(fname)) + settings_save_fe(fname); + else { + /* config file modified outside irssi */ + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + TXT_CONFIG_MODIFIED, fname); + + format = format_get_text(MODULE_NAME, NULL, NULL, NULL, + TXT_OVERWRITE_CONFIG); + keyboard_entry_redirect((SIGNAL_FUNC) settings_save_confirm, + format, 0, g_strdup(fname)); + g_free(format); } - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - TXT_CONFIG_MODIFIED, data); - - format = format_get_text(MODULE_NAME, NULL, NULL, NULL, - TXT_OVERWRITE_CONFIG); - keyboard_entry_redirect((SIGNAL_FUNC) settings_save_confirm, - format, 0, g_strdup(data)); - g_free(format); + cmd_params_free(free_arg); } static void settings_clean_confirm(const char *line) diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c index 8aee0d95..04763612 100644 --- a/src/fe-common/core/themes.c +++ b/src/fe-common/core/themes.c @@ -1000,8 +1000,13 @@ static void cmd_format(const char *data) cmd_params_free(free_arg); } +typedef struct { + CONFIG_REC *config; + int save_all; +} THEME_SAVE_REC; + static void module_save(const char *module, MODULE_THEME_REC *rec, - CONFIG_REC *config) + THEME_SAVE_REC *data) { CONFIG_NODE *fnode, *node; FORMAT_REC *formats; @@ -1010,27 +1015,33 @@ static void module_save(const char *module, MODULE_THEME_REC *rec, formats = g_hash_table_lookup(default_formats, rec->name); if (formats == NULL) return; - fnode = config_node_traverse(config, "formats", TRUE); + fnode = config_node_traverse(data->config, "formats", TRUE); node = config_node_section(fnode, rec->name, NODE_TYPE_BLOCK); - for (n = 0; formats[n].def != NULL; n++) { + for (n = 1; formats[n].def != NULL; n++) { if (rec->formats[n] != NULL) { - config_node_set_str(config, node, formats[n].tag, + config_node_set_str(data->config, node, formats[n].tag, rec->formats[n]); - } + } else if (data->save_all && formats[n].tag != NULL) { + config_node_set_str(data->config, node, formats[n].tag, + formats[n].def); + } } if (node->value == NULL) { /* not modified, don't keep the empty section */ - config_node_remove(config, fnode, node); - if (fnode->value == NULL) - config_node_remove(config, config->mainnode, fnode); + config_node_remove(data->config, fnode, node); + if (fnode->value == NULL) { + config_node_remove(data->config, + data->config->mainnode, fnode); + } } } -static void theme_save(THEME_REC *theme) +static void theme_save(THEME_REC *theme, int save_all) { CONFIG_REC *config; + THEME_SAVE_REC data; char *path; int ok; @@ -1050,7 +1061,9 @@ static void theme_save(THEME_REC *theme) } } - g_hash_table_foreach(theme->modules, (GHFunc) module_save, config); + data.config = config; + data.save_all = save_all; + g_hash_table_foreach(theme->modules, (GHFunc) module_save, &data); /* always save the theme to ~/.irssi/ */ path = g_strdup_printf("%s/%s", get_irssi_dir(), @@ -1065,16 +1078,27 @@ static void theme_save(THEME_REC *theme) config_close(config); } -/* save changed formats */ -static void cmd_save(void) +/* save changed formats, -format saves all */ +static void cmd_save(const char *data) { GSList *tmp; + GHashTable *optlist; + void *free_arg; + char *fname; + int saveall; + if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS, + "save", &optlist, &fname)) + return; + + saveall = g_hash_table_lookup(optlist, "formats") != NULL; for (tmp = themes; tmp != NULL; tmp = tmp->next) { THEME_REC *theme = tmp->data; - theme_save(theme); + theme_save(theme, saveall); } + + cmd_params_free(free_arg); } static void complete_format_list(THEME_SEARCH_REC *rec, const char *key, GList **list) @@ -1215,6 +1239,7 @@ void themes_init(void) signal_add("setup reread", (SIGNAL_FUNC) themes_read); command_set_options("format", "delete reset"); + command_set_options("save", "formats"); } void themes_deinit(void)