Fix writing the default value when a key is missing for hidden

prefs, even if it was overridden when it was originally read.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5121 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2010-08-10 12:46:30 +00:00
parent 0c4b7a2ab0
commit cc736eb4af
2 changed files with 18 additions and 7 deletions

View File

@ -6,6 +6,9 @@
merged into one enum; the order of keybindings is now just the
order they are added to each group. Keybindings can be reordered
without breaking the plugin ABI but groups must stay the same.
* src/stash.c:
Fix writing the default value when a key is missing for hidden
prefs, even if it was overridden when it was originally read.
2010-08-05 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -101,9 +101,9 @@ stash_group_update(group, parent);
struct StashPref
{
GType setting_type; /* e.g. G_TYPE_INT */
gpointer setting;
gpointer setting; /* Address of a variable */
const gchar *key_name;
gpointer default_value;
gpointer default_value; /* Default value, e.g. (gpointer)1 */
GType widget_type; /* e.g. GTK_TYPE_TOGGLE_BUTTON */
StashWidgetID widget_id; /* (GtkWidget*) or (gchar*) */
gpointer fields; /* extra fields */
@ -233,15 +233,21 @@ static void keyfile_action(SettingAction action, StashGroup *group, GKeyFile *ke
foreach_array(StashPref, entry, group->entries)
{
/* don't overwrite write_once prefs */
if (group->write_once && action == SETTING_WRITE &&
g_key_file_has_key(keyfile, group->name, entry->key_name, NULL))
continue;
gpointer tmp = entry->setting;
/* don't override settings with default values */
if (!group->use_defaults && action == SETTING_READ &&
!g_key_file_has_key(keyfile, group->name, entry->key_name, NULL))
continue;
/* don't overwrite write_once prefs */
if (group->write_once && action == SETTING_WRITE)
{
if (g_key_file_has_key(keyfile, group->name, entry->key_name, NULL))
continue;
/* We temporarily use the default value for writing */
entry->setting = &entry->default_value;
}
switch (entry->setting_type)
{
case G_TYPE_BOOLEAN:
@ -251,13 +257,15 @@ static void keyfile_action(SettingAction action, StashGroup *group, GKeyFile *ke
case G_TYPE_STRING:
handle_string_setting(group, entry, keyfile, action); break;
default:
/* G_TYPE_STRV is not a constant */
/* Note: G_TYPE_STRV is not a constant, can't use case label */
if (entry->setting_type == G_TYPE_STRV)
handle_strv_setting(group, entry, keyfile, action);
else
g_warning("Unhandled type for %s::%s in %s()!", group->name, entry->key_name,
G_STRFUNC);
}
if (group->write_once && action == SETTING_WRITE)
entry->setting = tmp;
}
}