diff --git a/ChangeLog b/ChangeLog index 287b476803..7425615861 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2002-10-13 David Hampton + + * src/scm/printing/print-check.scm: The check printing setup + dialog is now called directly, instead of as a callback from the + check printing code. + + * src/gnome/window-register.c (gnc_register_print_check_cb): Call + the check printing setup dialog directly. + + * src/gnome/dialog-print-check.c + (gnc_ui_print_compute_new_format): Give feedback on the format + string being used. (gnc_ui_print_check_dialog_create): Rework for + being called directly from the register code. Now hiding instead + of destroying the dialog, so remove hooks to remember state. If + the current register already has a print dialog open, reuse + it. (gnc_ui_print_check_dialog_destroy): Hide the dialog instead + of destroying it. (gnc_ui_print_check_dialog_ok_cb): Call the + scheme printing code directly. + + * src/gnome/gw-gnc-spec.scm: Remove unneeded references to check + printing. + 2002-10-13 Joshua Sled * src/register/ledger-core/gnc-regwidget.c diff --git a/src/gnome/dialog-print-check.c b/src/gnome/dialog-print-check.c index ca0f1b4c8c..d5f7b4e8c4 100644 --- a/src/gnome/dialog-print-check.c +++ b/src/gnome/dialog-print-check.c @@ -30,6 +30,8 @@ #include "date.h" #include "messages.h" +#include "gnc-numeric.h" +#include "window-register.h" #include "dialog-print-check.h" #include "dialog-utils.h" #include "window-help.h" @@ -53,9 +55,6 @@ void gnc_ui_print_check_dialog_help_cb(GtkButton * button, void gnc_ui_print_check_format_changed_cb(GtkWidget *unused, gpointer user_data); -static gboolean saved_include_century = TRUE; -static gboolean saved_month_name = FALSE; -static gboolean saved_month_name_long = FALSE; static int gnc_ui_print_get_option_menu_item (GtkWidget *widget) { @@ -102,6 +101,7 @@ gnc_ui_print_compute_new_format (PrintCheckDialog *pcd) pcd->format_string = NULL; } + /* Custom format */ if (sel_option >= DATE_FORMAT_LOCALE) { format = g_strdup(gtk_entry_get_text(GTK_ENTRY(pcd->custom_format))); gtk_widget_set_sensitive(pcd->month_name_long, FALSE); @@ -111,6 +111,7 @@ gnc_ui_print_compute_new_format (PrintCheckDialog *pcd) goto finish; } + /* One of the pre-specified formats */ gnc_ui_print_enable_year(pcd, TRUE); gnc_ui_print_enable_format(pcd, FALSE); if (sel_option == DATE_FORMAT_ISO) { @@ -124,6 +125,7 @@ gnc_ui_print_compute_new_format (PrintCheckDialog *pcd) gnc_ui_print_enable_month(pcd, TRUE); } + /* Update the format string based upon the user's preferences */ if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pcd->month_name))) { format = g_strdup(getDateFormatString(sel_option)); gtk_widget_set_sensitive(pcd->month_name_long, FALSE); @@ -142,9 +144,20 @@ gnc_ui_print_compute_new_format (PrintCheckDialog *pcd) if (c) *c = 'Y'; } + + /* + * Give feedback on the format string so users can see how it works + * without having to read the strftime man page. + */ + gtk_signal_handler_block_by_data(GTK_OBJECT(pcd->custom_format), pcd); + gtk_entry_set_text(GTK_ENTRY(pcd->custom_format), format); + gtk_signal_handler_unblock_by_data(GTK_OBJECT(pcd->custom_format), pcd); finish: + /* Save the format string for when OK is clicked */ pcd->format_string = format; + + /* Visual feedback on what the date will look like. */ secs_now = time(NULL); localtime_r(&secs_now, &today); strftime(date_string, MAX_DATE_LEN, format, &today); @@ -167,18 +180,39 @@ gnc_ui_print_check_format_changed_cb(GtkWidget *unused, * make a new print check dialog and wait for it. \********************************************************************/ -PrintCheckDialog * -gnc_ui_print_check_dialog_create(SCM callback) +void +gnc_ui_print_check_dialog_create(RegWindow *reg_data, + const char *payee, + gnc_numeric amount, + time_t date, + const char *memo) { - PrintCheckDialog * pcd = g_new0(PrintCheckDialog, 1); + PrintCheckDialog * pcd; GladeXML *xml; - xml = gnc_glade_xml_new ("print.glade", "Print Check Dialog"); + pcd = (PrintCheckDialog *)gnc_RegWindow_get_pcd(reg_data); + if (pcd) { + pcd->payee = payee; + pcd->amount = amount; + pcd->date = date; + pcd->memo = memo; + gnc_ui_print_compute_new_format(pcd); + gtk_window_present (GTK_WINDOW(pcd->dialog)); + return; + } + pcd = g_new0(PrintCheckDialog, 1); + gnc_RegWindow_set_pcd(reg_data, pcd); + pcd->reg_data = reg_data; + pcd->payee = payee; + pcd->amount = amount; + pcd->date = date; + pcd->memo = memo; + + xml = gnc_glade_xml_new ("print.glade", "Print Check Dialog"); glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pcd); pcd->dialog = glade_xml_get_widget (xml, "Print Check Dialog"); - pcd->callback = callback; /* now pick out the relevant child widgets */ pcd->format_picker = glade_xml_get_widget (xml, "check_format_picker"); @@ -208,12 +242,9 @@ gnc_ui_print_check_dialog_create(SCM callback) pcd->format_entry = glade_xml_get_widget (xml, "date_format_entry"); pcd->units_picker = glade_xml_get_widget (xml, "units_picker"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcd->include_century), - saved_include_century); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcd->month_name), - saved_month_name); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcd->month_name_long), - saved_month_name_long); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcd->include_century), TRUE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcd->month_name), FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pcd->month_name_long), FALSE); /* fix the option menus so we can diagnose which option is selected */ @@ -223,37 +254,45 @@ gnc_ui_print_check_dialog_create(SCM callback) gnc_ui_print_check_format_changed_cb, pcd); gnc_option_menu_init(pcd->units_picker); - scm_protect_object(pcd->callback); - /* Set initial format to gnucash default */ gtk_option_menu_set_history(GTK_OPTION_MENU(pcd->dformat_picker), getDateFormat()); gnc_ui_print_compute_new_format(pcd); + gnome_dialog_set_parent(GNOME_DIALOG(pcd->dialog), + GTK_WINDOW(gnc_RegWindow_window(reg_data))); gtk_widget_show_all(pcd->dialog); - - return pcd; } /********************************************************************\ * gnc_ui_print_check_dialog_destroy + * + * Don't destroy the dialog until the program exits. This will + * maintain *all* user settings from invocation to invocation. + * \********************************************************************/ void gnc_ui_print_check_dialog_destroy(PrintCheckDialog * pcd) { - gnome_dialog_close(GNOME_DIALOG(pcd->dialog)); - - scm_unprotect_object(pcd->callback); - if (pcd->format_string) g_free(pcd->format_string); + + gnome_dialog_close(GNOME_DIALOG(pcd->dialog)); + gtk_widget_destroy(pcd->dialog); pcd->dialog = NULL; + gnc_RegWindow_set_pcd(pcd->reg_data, NULL); g_free(pcd); } +static void +gnc_ui_print_check_dialog_hide(PrintCheckDialog * pcd) +{ + gtk_widget_hide(pcd->dialog); +} + static double entry_to_double(GtkWidget * entry) { @@ -276,7 +315,8 @@ gnc_ui_print_check_dialog_ok_cb(GtkButton * button, PrintCheckDialog * pcd = user_data; SCM make_check_format = gh_eval_str("make-print-check-format"); - SCM callback; + SCM print_check = gh_eval_str("gnc:print-check"); + SCM format_data; SCM fmt, posn, cust_format, date_format; int sel_option; double multip = 72.0; @@ -284,13 +324,6 @@ gnc_ui_print_check_dialog_ok_cb(GtkButton * button, char * formats[] = { "quicken", "custom" }; char * positions[] = { "top", "middle", "bottom", "custom" }; - saved_include_century = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pcd->include_century)); - saved_month_name = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pcd->month_name)); - saved_month_name_long = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pcd->month_name_long)); - sel_option = gnc_ui_print_get_option_menu_item(pcd->format_picker); fmt = gh_symbol2scm(formats[sel_option]); @@ -329,16 +362,22 @@ gnc_ui_print_check_dialog_ok_cb(GtkButton * button, gh_cons(gh_symbol2scm("date-format"), gh_str02scm(gtk_entry_get_text(GTK_ENTRY(pcd->format_entry))))); - callback = pcd->callback; - - /* destroy the window */ - gnc_ui_print_check_dialog_destroy(pcd); + /* hide the window */ + gnc_ui_print_check_dialog_hide(pcd); /* now call the callback passed in from the scheme side with the format as an arg */ - gh_call1(callback, - gh_apply(make_check_format, - SCM_LIST4(fmt, posn, date_format, cust_format))); + format_data = gh_apply(make_check_format, + SCM_LIST4(fmt, posn, date_format, cust_format)); + + gh_apply(print_check, + /* FIXME: when we drop support older guiles, drop the + (char *) coercions below. */ + SCM_LIST5(format_data, + gh_str02scm((char *) pcd->payee), + gh_double2scm(gnc_numeric_to_double (pcd->amount)), + gh_ulong2scm(pcd->date), + gh_str02scm((char *) pcd->memo))); } @@ -353,7 +392,7 @@ gnc_ui_print_check_dialog_cancel_cb(GtkButton * button, { PrintCheckDialog * pcd = user_data; - gnc_ui_print_check_dialog_destroy(pcd); + gnc_ui_print_check_dialog_hide(pcd); } /********************************************************************\ diff --git a/src/gnome/dialog-print-check.h b/src/gnome/dialog-print-check.h index a4fad39efe..4825033f1f 100644 --- a/src/gnome/dialog-print-check.h +++ b/src/gnome/dialog-print-check.h @@ -33,6 +33,12 @@ typedef struct { GtkWidget * dialog; + RegWindow *reg_data; + const char *payee; + gnc_numeric amount; + time_t date; + const char *memo; + GtkWidget * format_picker; GtkWidget * position_picker; GtkWidget * dformat_picker; @@ -52,12 +58,14 @@ typedef struct { GtkWidget * include_century, * sample_date; GtkWidget * custom_label, * custom_format; gchar *format_string; - - SCM callback; } PrintCheckDialog; -PrintCheckDialog * gnc_ui_print_check_dialog_create(SCM callback); +void gnc_ui_print_check_dialog_create(RegWindow *reg_data, + const char *payee, + gnc_numeric amount, + time_t date, + const char *memo); void gnc_ui_print_check_dialog_destroy(PrintCheckDialog * pcd); #endif diff --git a/src/gnome/glade/print.glade b/src/gnome/glade/print.glade index 11af20741b..07537be700 100644 --- a/src/gnome/glade/print.glade +++ b/src/gnome/glade/print.glade @@ -27,7 +27,7 @@ True False False - False + True GtkVBox @@ -206,6 +206,7 @@ GtkCheckButton month_name_long + Use the month name instead of the month abbreviation. (E.g. January instead of Jan.) True toggled @@ -234,6 +235,7 @@ GtkCheckButton month_name + Use the month abbreviation instead of the month number. (E.g. Jan instead of '1'.) True toggled @@ -262,6 +264,7 @@ GtkCheckButton include_century + Include the century when printing the year. (E.g. 2001 instead of 01.) True toggled diff --git a/src/gnome/gw-gnc-spec.scm b/src/gnome/gw-gnc-spec.scm index ce20c053fb..6316d60a1c 100644 --- a/src/gnome/gw-gnc-spec.scm +++ b/src/gnome/gw-gnc-spec.scm @@ -38,14 +38,12 @@ "#include \n" "#include \n" "#include \n" - "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" - "#include \n" "#include \n" "#include \n" "#include \n" @@ -139,18 +137,6 @@ '() "Destroy the UI.") - (gw:wrap-as-wct ws - ' - "PrintCheckDialog*" "const PrintCheckDialog*") - - (gw:wrap-function - ws - 'gnc:print-check-dialog-create - ' - "gnc_ui_print_check_dialog_create" - '(( callback)) - "Pop up a dialog to set up printing a check.") - (gw:wrap-function ws 'gnc:ui-totd-dialog-create-and-run diff --git a/src/gnome/window-register.c b/src/gnome/window-register.c index 83fcfba750..2fc52ba48a 100644 --- a/src/gnome/window-register.c +++ b/src/gnome/window-register.c @@ -60,6 +60,7 @@ #include "window-register.h" #include "window-report.h" #include "top-level.h" +#include "dialog-print-check.h" typedef enum { BY_STANDARD = 0, @@ -123,6 +124,7 @@ struct _RegWindow sort_type_t sort_type; RegDateWindow *date_window; + gpointer pcd; }; GtkWidget *gnc_RegWindow_window (RegWindow *data) { @@ -135,6 +137,17 @@ GNCLedgerDisplay *gnc_RegWindow_ledger (RegWindow *data) return data->ledger; } +gpointer +gnc_RegWindow_get_pcd (RegWindow *data) +{ + return data->pcd; +} + +void +gnc_RegWindow_set_pcd (RegWindow *data, gpointer pcd) +{ + data->pcd = pcd; +} /* This static indicates the debugging module that this .o belongs to. */ @@ -1059,10 +1072,7 @@ gnc_register_print_check_cb(GtkWidget * widget, gpointer data) gnc_numeric amount; time_t date; - SCM print_check = gh_eval_str("gnc:print-check"); - - if(split && trans && - gh_procedure_p(print_check)) + if(split && trans) { payee = xaccTransGetDescription(trans); memo = xaccTransGetNotes(trans); @@ -1072,13 +1082,7 @@ gnc_register_print_check_cb(GtkWidget * widget, gpointer data) amount = gnc_numeric_abs (amount); date = xaccTransGetDate(trans); - gh_apply(print_check, - /* FIXME: when we drop support older guiles, drop the - (char *) coercions below. */ - SCM_LIST4(gh_str02scm((char *) payee), - gh_double2scm(gnc_numeric_to_double (amount)), - gh_ulong2scm(date), - gh_str02scm((char *) memo))); + gnc_ui_print_check_dialog_create(reg_data, payee, amount, date, memo); } } @@ -1337,6 +1341,8 @@ gnc_register_destroy_cb(GtkWidget *widget, gpointer data) regData->date_window = NULL; } + if (regData->pcd) + gnc_ui_print_check_dialog_destroy(regData->pcd); g_free(regData); DEBUG ("destroyed RegWindow"); @@ -1605,7 +1611,7 @@ regWindowLedger (GNCLedgerDisplay *ledger) if (regData != NULL) return regData; - regData = g_new (RegWindow, 1); + regData = g_new0 (RegWindow, 1); gnc_ledger_display_set_user_data (ledger, regData); diff --git a/src/gnome/window-register.h b/src/gnome/window-register.h index d97d1d2e64..a9e15060a5 100644 --- a/src/gnome/window-register.h +++ b/src/gnome/window-register.h @@ -37,6 +37,9 @@ RegWindow * regWindowSimple(Account *account); RegWindow * regWindowAccGroup(Account *account_group); RegWindow * regWindowLedger(GNCLedgerDisplay *ledger); +gpointer gnc_RegWindow_get_pcd (RegWindow *data); +void gnc_RegWindow_set_pcd (RegWindow *data, gpointer); + void gnc_register_raise(RegWindow *regData); void gnc_register_jump_to_blank(RegWindow *regData); void gnc_register_jump_to_split(RegWindow *regData, Split *split); diff --git a/src/scm/printing/print-check.scm b/src/scm/printing/print-check.scm index 93c2477f68..670dd0b7df 100644 --- a/src/scm/printing/print-check.scm +++ b/src/scm/printing/print-check.scm @@ -72,8 +72,7 @@ (middle . 288.0) (bottom . 36.0))) -(define (gnc:print-check payee amount date memo) - (define (print-check-callback format-info) +(define (gnc:print-check format-info payee amount date memo) (let* ((int-part (inexact->exact (truncate amount))) (frac-part (inexact->exact (truncate @@ -140,5 +139,3 @@ (gnc:print-session-done ps #t) (gnc:print-session-print ps))) - (gnc:print-check-dialog-create print-check-callback)) -