diff --git a/plugins/geanyfunctions.h b/plugins/geanyfunctions.h index d41d77ee8..beaf6fb9f 100644 --- a/plugins/geanyfunctions.h +++ b/plugins/geanyfunctions.h @@ -418,6 +418,8 @@ geany_functions->p_stash->stash_group_display #define stash_group_update \ geany_functions->p_stash->stash_group_update +#define stash_group_free_settings \ + geany_functions->p_stash->stash_group_free_settings #define symbols_get_context_separator \ geany_functions->p_symbols->symbols_get_context_separator #define build_activate_menu_item \ diff --git a/src/plugindata.h b/src/plugindata.h index 77d6964d6..1bebb9b91 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -55,7 +55,7 @@ G_BEGIN_DECLS * @warning You should not test for values below 200 as previously * @c GEANY_API_VERSION was defined as an enum value, not a macro. */ -#define GEANY_API_VERSION 214 +#define GEANY_API_VERSION 215 /** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. @@ -701,6 +701,7 @@ typedef struct StashFuncs const gchar *property_name, GType type); void (*stash_group_display)(struct StashGroup *group, GtkWidget *owner); void (*stash_group_update)(struct StashGroup *group, GtkWidget *owner); + void (*stash_group_free_settings)(struct StashGroup *group); } StashFuncs; @@ -716,7 +717,7 @@ SymbolsFuncs; typedef struct BuildFuncs { void (*build_activate_menu_item)(const GeanyBuildGroup grp, const guint cmd); - const gchar *(*build_get_current_menu_item)(const GeanyBuildGroup grp, const guint cmd, + const gchar *(*build_get_current_menu_item)(const GeanyBuildGroup grp, const guint cmd, const GeanyBuildCmdEntries field); void (*build_remove_menu_item)(const GeanyBuildSource src, const GeanyBuildGroup grp, const gint cmd); diff --git a/src/plugins.c b/src/plugins.c index 42bec5d3a..65b229ff9 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -346,7 +346,8 @@ static StashFuncs stash_funcs = { &stash_group_add_entry, &stash_group_add_widget_property, &stash_group_display, - &stash_group_update + &stash_group_update, + &stash_group_free_settings }; static SymbolsFuncs symbols_funcs = { diff --git a/src/stash.c b/src/stash.c index 0427af388..40f9e708a 100644 --- a/src/stash.c +++ b/src/stash.c @@ -335,6 +335,29 @@ StashGroup *stash_group_new(const gchar *name) } +/** Frees the memory allocated for setting values in a group. + * Useful e.g. to avoid freeing strings individually. + * @note This is *not* called by stash_group_free(). + * @param group . */ +void stash_group_free_settings(StashGroup *group) +{ + StashPref *entry; + guint i; + + foreach_ptr_array(entry, i, group->entries) + { + if (entry->setting_type == G_TYPE_STRING) + g_free(*(gchararray *) entry->setting); + else if (entry->setting_type == G_TYPE_STRV) + g_strfreev(*(gchararray **) entry->setting); + else + continue; + + *(gpointer**) entry->setting = NULL; + } +} + + /** Frees a group. * @param group . */ void stash_group_free(StashGroup *group) diff --git a/src/stash.h b/src/stash.h index 949fb2da7..7391e710a 100644 --- a/src/stash.h +++ b/src/stash.h @@ -60,6 +60,8 @@ gboolean stash_group_load_from_file(StashGroup *group, const gchar *filename); gint stash_group_save_to_file(StashGroup *group, const gchar *filename, GKeyFileFlags flags); +void stash_group_free_settings(StashGroup *group); + void stash_group_free(StashGroup *group);