From f043a820f325e4c4cb386bd56aad73d09480ffbe Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 28 Jul 2019 12:02:22 +0100 Subject: [PATCH] Remove plugin preferences Make sure when a GncMainWindow closes that the preference callbacks that were setup for the plugins are removed. At this point the actions are not touched as it causes errors to be logged to the terminal. --- gnucash/gnome-utils/gnc-main-window.c | 10 ++++++++++ gnucash/gnome-utils/gnc-main-window.h | 1 + gnucash/gnome-utils/gnc-plugin-menu-additions.c | 3 ++- gnucash/gnome-utils/gnc-plugin.c | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c index a0f364279b0..a96aff8d978 100644 --- a/gnucash/gnome-utils/gnc-main-window.c +++ b/gnucash/gnome-utils/gnc-main-window.c @@ -2747,6 +2747,7 @@ gnc_main_window_new (void) active_windows = g_list_append (active_windows, window); gnc_main_window_update_title(window); window->window_quitting = FALSE; + window->just_plugin_prefs = FALSE; #ifdef MAC_INTEGRATION gnc_quartz_set_menu(window); #else @@ -3115,6 +3116,15 @@ gnc_main_window_close_page (GncPluginPage *page) priv = GNC_MAIN_WINDOW_GET_PRIVATE(window); if (priv->installed_pages == NULL) { + GncPluginManager *manager = gnc_plugin_manager_get (); + GList *plugins = gnc_plugin_manager_get_plugins (manager); + + /* remove only the preference callbacks from the window plugins */ + window->just_plugin_prefs = TRUE; + g_list_foreach (plugins, gnc_main_window_remove_plugin, window); + window->just_plugin_prefs = FALSE; + g_list_free (plugins); + /* remove the preference callbacks from the main window */ gnc_main_window_remove_prefs (window); diff --git a/gnucash/gnome-utils/gnc-main-window.h b/gnucash/gnome-utils/gnc-main-window.h index e599852e578..cea61e243f9 100644 --- a/gnucash/gnome-utils/gnc-main-window.h +++ b/gnucash/gnome-utils/gnc-main-window.h @@ -58,6 +58,7 @@ typedef struct GncMainWindow GtkUIManager *ui_merge; /**< A pointer to the UI Manager data structure for the whole window. */ gboolean window_quitting; /**< Set to TRUE when quitting from this window. */ + gboolean just_plugin_prefs; /**< Just remove preferences only from plugins */ } GncMainWindow; /** The class data structure for a main window object. */ diff --git a/gnucash/gnome-utils/gnc-plugin-menu-additions.c b/gnucash/gnome-utils/gnc-plugin-menu-additions.c index 2cc48982485..090ccbbff7e 100644 --- a/gnucash/gnome-utils/gnc-plugin-menu-additions.c +++ b/gnucash/gnome-utils/gnc-plugin-menu-additions.c @@ -474,7 +474,8 @@ gnc_plugin_menu_additions_remove_from_window (GncPlugin *plugin, /* Have to remove our actions manually. Its only automatic if the * actions name is installed into the plugin class. */ group = gnc_main_window_get_action_group(window, PLUGIN_ACTIONS_NAME); - if (group) + + if (group && !window->just_plugin_prefs) gtk_ui_manager_remove_action_group(window->ui_merge, group); /* Note: This code does not clean up the per-callback data structures diff --git a/gnucash/gnome-utils/gnc-plugin.c b/gnucash/gnome-utils/gnc-plugin.c index d84f359e423..77240c3f2d7 100644 --- a/gnucash/gnome-utils/gnc-plugin.c +++ b/gnucash/gnome-utils/gnc-plugin.c @@ -201,7 +201,7 @@ gnc_plugin_remove_from_window (GncPlugin *plugin, /* * Update window to remove UI items */ - if (klass->actions_name) + if (klass->actions_name && !window->just_plugin_prefs) { DEBUG ("%s: %d actions to unmerge", klass->actions_name, (klass->n_actions + klass->n_toggle_actions));