Improve gui component handling of report plugin pages.

Let them be closed on session shutdown by setting the session.  Call
gnc_main_window_close_page in close handler.  Unregister the component
in _destroy_widget and move _destroy into it.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16104 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler 2007-05-19 23:19:56 +00:00
parent b23b36822f
commit f18fa0614b

View File

@ -57,6 +57,7 @@
#include "gnc-plugin.h" #include "gnc-plugin.h"
#include "gnc-plugin-page-report.h" #include "gnc-plugin-page-report.h"
#include "gnc-report.h" #include "gnc-report.h"
#include "gnc-session.h"
#include "gnc-ui-util.h" #include "gnc-ui-util.h"
#include "gnc-ui.h" #include "gnc-ui.h"
#include "gnc-window.h" #include "gnc-window.h"
@ -85,6 +86,7 @@ typedef struct GncPluginPageReportPrivate
{ {
/// The report-id /// The report-id
int reportId; int reportId;
gint component_manager_id;
/// The report which this Page is satisifying /// The report which this Page is satisifying
SCM cur_report; SCM cur_report;
@ -334,8 +336,11 @@ gnc_plugin_page_report_create_widget( GncPluginPage *page )
gtk_container_add(GTK_CONTAINER(priv->container), gtk_container_add(GTK_CONTAINER(priv->container),
gnc_html_get_widget(priv->html)); gnc_html_get_widget(priv->html));
gnc_register_gui_component( WINDOW_REPORT_CM_CLASS, NULL, priv->component_manager_id =
close_handler, priv ); gnc_register_gui_component(WINDOW_REPORT_CM_CLASS, NULL,
close_handler, page);
gnc_gui_component_set_session(priv->component_manager_id,
gnc_get_current_session());
gnc_html_set_urltype_cb(priv->html, gnc_plugin_page_report_check_urltype); gnc_html_set_urltype_cb(priv->html, gnc_plugin_page_report_check_urltype);
gnc_html_set_load_cb(priv->html, gnc_plugin_page_report_load_cb, report); gnc_html_set_load_cb(priv->html, gnc_plugin_page_report_load_cb, report);
@ -643,6 +648,13 @@ gnc_plugin_page_report_destroy_widget(GncPluginPage *plugin_page)
PINFO("destroy widget"); PINFO("destroy widget");
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(plugin_page); priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(plugin_page);
if (priv->component_manager_id) {
gnc_unregister_gui_component(priv->component_manager_id);
priv->component_manager_id = 0;
}
gnc_plugin_page_report_destroy(priv);
gnc_report_remove_by_id(priv->reportId); gnc_report_remove_by_id(priv->reportId);
} }
@ -902,8 +914,6 @@ gnc_plugin_page_report_destroy(GncPluginPageReportPrivate * priv)
SCM set_editor = scm_c_eval_string("gnc:report-set-editor-widget!"); SCM set_editor = scm_c_eval_string("gnc:report-set-editor-widget!");
SCM edited, editor; SCM edited, editor;
gnc_unregister_gui_component_by_data (WINDOW_REPORT_CM_CLASS, priv);
/* close any open editors */ /* close any open editors */
for (edited = scm_list_copy(priv->edited_reports); !SCM_NULLP(edited); for (edited = scm_list_copy(priv->edited_reports); !SCM_NULLP(edited);
edited = SCM_CDR(edited)) { edited = SCM_CDR(edited)) {
@ -1125,9 +1135,9 @@ gnc_plugin_page_report_raise_editor(SCM report)
static void static void
close_handler (gpointer user_data) close_handler (gpointer user_data)
{ {
GncPluginPageReportPrivate *priv = user_data; GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(user_data);
DEBUG("in close handler\n"); DEBUG("in close handler\n");
gnc_plugin_page_report_destroy (priv); gnc_main_window_close_page (plugin_page);
} }
static void static void