mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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(++).
This commit is contained in:
parent
0820090e75
commit
a5d77e4430
@ -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)
|
||||
|
@ -3,7 +3,6 @@
|
||||
/* Includes the header in the wrapper code */
|
||||
#include <config.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <dialog-report-column-view.h>
|
||||
#include <gnc-plugin-page-report.h>
|
||||
#include <window-report.h>
|
||||
#include <dialog-custom-report.h>
|
||||
@ -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);
|
||||
|
||||
|
@ -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* '())
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user