From a5d77e4430319e81fbd2f6b5a005851857fb290e Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 23 Dec 2014 12:03:38 +0100 Subject: [PATCH] Move code to open report options dialog from guile to C This code was switching a lot between the guile and C context. This move at least reduces some of them. The switches can only be eliminated completely when the options code itself gets rewritten in C(++). --- .../report-gnome/gnc-plugin-page-report.c | 13 +-- src/report/report-gnome/report-gnome.i | 6 -- src/report/report-gnome/report-gnome.scm | 24 ------ src/report/report-gnome/window-report.c | 80 ++++++++++++++----- src/report/report-gnome/window-report.h | 3 +- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c index 828f4b53f7..3ec09f0d8e 100644 --- a/src/report/report-gnome/gnc-plugin-page-report.c +++ b/src/report/report-gnome/gnc-plugin-page-report.c @@ -1593,24 +1593,13 @@ static void gnc_plugin_page_report_options_cb( GtkAction *action, GncPluginPageReport *report ) { GncPluginPageReportPrivate *priv; - SCM start_editor = scm_c_eval_string("gnc:report-edit-options"); - SCM result; priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report); if (priv->cur_report == SCM_BOOL_F) return; - result = gfec_apply(start_editor, scm_cons(priv->cur_report, SCM_EOL), - error_handler); - if (result == SCM_BOOL_F || result == SCM_UNDEFINED) - { - gnc_warning_dialog(GTK_WIDGET(gnc_ui_get_toplevel()), "%s", - _("There are no options for this report.")); - } - else - { + if (gnc_report_edit_options (priv->cur_report)) gnc_plugin_page_report_add_edited_report(priv, priv->cur_report); - } } static GncInvoice *lookup_invoice(GncPluginPageReportPrivate *priv) diff --git a/src/report/report-gnome/report-gnome.i b/src/report/report-gnome/report-gnome.i index 9e49ac0989..605523d949 100644 --- a/src/report/report-gnome/report-gnome.i +++ b/src/report/report-gnome/report-gnome.i @@ -3,7 +3,6 @@ /* Includes the header in the wrapper code */ #include #include -#include #include #include #include @@ -18,10 +17,5 @@ SCM scm_init_sw_report_gnome_module (void); %import "base-typemaps.i" -void gnc_report_raise_editor(SCM report); void gnc_main_window_open_report(int report_id, GncMainWindow *window); -GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report); -GtkWidget * gnc_column_view_edit_options(SCM options, SCM view); - void gnc_ui_custom_report(GncMainWindow * window); - diff --git a/src/report/report-gnome/report-gnome.scm b/src/report/report-gnome/report-gnome.scm index b68350b985..4825f53844 100644 --- a/src/report/report-gnome/report-gnome.scm +++ b/src/report/report-gnome/report-gnome.scm @@ -26,33 +26,9 @@ (gnc:module-load "gnucash/report/report-system" 0) (gnc:module-load "gnucash/report/utility-reports" 0) -(export gnc:report-edit-options) (export gnc:report-menu-setup) (export gnc:add-report-template-menu-items) -;; returns a function that takes a list: (options, report), -;; and returns a widget -(define (gnc:report-options-editor report) - (if (equal? (gnc:report-type report) "d8ba4a2e89e8479ca9f6eccdeb164588") - gnc-column-view-edit-options - gnc-report-window-default-params-editor)) - -;; do not rely on the return value of this function - it has none. -;; instead, this function's side-effect is to set the report's editor widget. -(define (gnc:report-edit-options report) - (let* ((editor-widg (gnc:report-editor-widget report))) - (if (and editor-widg (not (null? editor-widg))) - (gnc-report-raise-editor report) - (begin - (if (gnc:report-options report) - (begin - (set! editor-widg - ((gnc:report-options-editor report) - (gnc:report-options report) - report)) - (gnc:report-set-editor-widget! report editor-widg)) - (gnc-warning-dialog '() (_ "This report has no options."))))))) - (define (gnc:add-report-template-menu-items) (define *template-items* '()) diff --git a/src/report/report-gnome/window-report.c b/src/report/report-gnome/window-report.c index bb68a7d396..00d7b1ac2b 100644 --- a/src/report/report-gnome/window-report.c +++ b/src/report/report-gnome/window-report.c @@ -34,6 +34,7 @@ #include "swig-runtime.h" #include "dialog-options.h" +#include "dialog-report-column-view.h" #include "file-utils.h" #include "gnc-gkeyfile-utils.h" #include "gnc-guile-utils.h" @@ -120,11 +121,28 @@ gnc_options_dialog_close_cb(GNCOptionWin * propertybox, g_free(win); } +static gboolean +gnc_report_raise_editor(SCM report) +{ + SCM get_editor = scm_c_eval_string("gnc:report-editor-widget"); + SCM editor = scm_call_1(get_editor, report); + if (editor != SCM_BOOL_F) + { +#define FUNC_NAME "gnc-report-raise-editor" + GtkWidget *w = SWIG_MustGetPtr(editor, + SWIG_TypeQuery("_p_GtkWidget"), 1, 0); +#undef FUNC_NAME + gtk_window_present(GTK_WINDOW(w)); + return TRUE; + } + else + return FALSE; +} + GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report) { - SCM get_editor = scm_c_eval_string("gnc:report-editor-widget"); SCM get_report_type = scm_c_eval_string("gnc:report-type"); SCM get_template = scm_c_eval_string("gnc:find-report-template"); SCM get_template_name = scm_c_eval_string("gnc:report-template-name"); @@ -132,15 +150,8 @@ gnc_report_window_default_params_editor(SCM options, SCM report) const gchar *title = NULL; - ptr = scm_call_1(get_editor, report); - if (ptr != SCM_BOOL_F) - { -#define FUNC_NAME "gtk_window_present" - GtkWindow * w = SWIG_MustGetPtr(ptr, SWIG_TypeQuery("_p_GtkWidget"), 1, 0); - gtk_window_present(w); -#undef FUNC_NAME + if (gnc_report_raise_editor (report)) return NULL; - } else { struct report_default_params_data * prm = @@ -187,16 +198,48 @@ gnc_report_window_default_params_editor(SCM options, SCM report) } } -void -gnc_report_raise_editor(SCM report) +gboolean +gnc_report_edit_options(SCM report) { - SCM get_editor = scm_c_eval_string("gnc:report-editor-widget"); - SCM editor = scm_call_1(get_editor, report); -#define FUNC_NAME "gtk_window_present" - GtkWidget *w = SWIG_MustGetPtr(editor, - SWIG_TypeQuery("_p_GtkWidget"), 1, 0); + SCM set_editor = scm_c_eval_string("gnc:report-set-editor-widget!"); + SCM get_options = scm_c_eval_string("gnc:report-options"); + SCM get_report_type = scm_c_eval_string("gnc:report-type"); + SCM ptr; + SCM options; + GtkWidget *options_widget = NULL; + + /* If the options editor widget already exists we simply raise it */ + if (gnc_report_raise_editor (report)) + return TRUE; + + /* Check if this report has options to edit */ + options = scm_call_1(get_options, report); + if (options == SCM_BOOL_F) + { + gnc_warning_dialog(GTK_WIDGET(gnc_ui_get_toplevel()), "%s", + _("There are no options for this report.")); + return FALSE; + } + + /* Multi-column type reports need a special options dialog */ + ptr = scm_call_1(get_report_type, report); + if (scm_is_string(ptr)) + { + gchar *rpt_type = gnc_scm_to_utf8_string (ptr); + if (g_strcmp0 (rpt_type, "d8ba4a2e89e8479ca9f6eccdeb164588") == 0) + options_widget = gnc_column_view_edit_options (options, report); + else + options_widget = gnc_report_window_default_params_editor (options, report); + g_free (rpt_type); + } + + /* Store the options editor widget for future reuse */ +#define FUNC_NAME "gnc-report-edit-options" + ptr = SWIG_NewPointerObj (options_widget, SWIG_TypeQuery("_p_GtkWidget"), 0); #undef FUNC_NAME - gtk_window_present(GTK_WINDOW(w)); + scm_call_2 (set_editor, report, ptr); + + return TRUE; } static gboolean @@ -236,7 +279,6 @@ static gboolean gnc_html_options_url_cb (const char *location, const char *label, gboolean new_window, GNCURLResult *result) { - SCM start_editor = scm_c_eval_string ("gnc:report-edit-options"); SCM report; int report_id; @@ -266,7 +308,7 @@ gnc_html_options_url_cb (const char *location, const char *label, return FALSE; } - scm_call_1 (start_editor, report); + gnc_report_edit_options (report); return TRUE; } diff --git a/src/report/report-gnome/window-report.h b/src/report/report-gnome/window-report.h index cacba95441..96f33ce10a 100644 --- a/src/report/report-gnome/window-report.h +++ b/src/report/report-gnome/window-report.h @@ -39,8 +39,7 @@ GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report); // [business-gnome/dialog-invoice.c;gnome/window-register.c]; and // scm-exposed; 3-liner which calls gnc_main_window_open_report after handling busy-cursor. void reportWindow(int id); -// scm-exposed; ~priv -void gnc_report_raise_editor(SCM report); +gboolean gnc_report_edit_options(SCM report); // module[/plugin]-init void gnc_report_init (void);