From 4fc3a0cb83434a50fbc06795121fc3d7578dccd8 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Fri, 24 Jan 2025 12:02:34 +0000 Subject: [PATCH] Bug 799343 - Dialog boxes won't remain sized and positioned - part1 This commit allows saving the position and size of the Billing Term Editor and the Process Payment dialogs. --- gnucash/gnome/dialog-billterms.c | 25 ++++++++++++++++++- gnucash/gnome/dialog-payment.c | 23 +++++++++++++++-- ...org.gnucash.GnuCash.dialogs.gschema.xml.in | 22 ++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/gnucash/gnome/dialog-billterms.c b/gnucash/gnome/dialog-billterms.c index fbe6d5184b..c1ca3fd954 100644 --- a/gnucash/gnome/dialog-billterms.c +++ b/gnucash/gnome/dialog-billterms.c @@ -39,6 +39,7 @@ #include "dialog-billterms.h" #define DIALOG_BILLTERMS_CM_CLASS "billterms-dialog" +#define GNC_PREFS_GROUP "dialogs.bill-terms" enum term_cols { @@ -709,8 +710,10 @@ static void billterms_window_close_handler (gpointer data) { BillTermsWindow *btw = data; + g_return_if_fail (btw); + gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(btw->window)); gtk_widget_destroy (btw->window); } @@ -718,9 +721,24 @@ void billterms_window_close (GtkWidget *widget, gpointer data) { BillTermsWindow *btw = data; + gnc_close_gui_component (btw->component_id); } +static gboolean +billterms_window_delete_event_cb (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + BillTermsWindow *btw = data; + + if (!btw) return FALSE; + + // this cb allows the window size to be saved on closing with the X + gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(btw->window)); + return FALSE; +} + void billterms_window_destroy_cb (GtkWidget *widget, gpointer data) { @@ -809,7 +827,7 @@ gnc_ui_billterms_window_new (GtkWindow *parent, QofBook *book) gnc_widget_style_context_add_class (GTK_WIDGET(btw->window), "gnc-class-bill-terms"); g_signal_connect (btw->window, "key_press_event", - G_CALLBACK (billterms_window_key_press_cb), btw); + G_CALLBACK(billterms_window_key_press_cb), btw); /* Initialize the view */ view = GTK_TREE_VIEW(btw->terms_view); @@ -850,6 +868,11 @@ gnc_ui_billterms_window_new (GtkWindow *parent, QofBook *book) gnc_gui_component_set_session (btw->component_id, btw->session); + g_signal_connect (G_OBJECT(btw->window), "delete-event", + G_CALLBACK(billterms_window_delete_event_cb), btw); + + gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(btw->window), GTK_WINDOW(parent)); + gtk_widget_show_all (btw->window); billterms_window_refresh (btw); diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c index 10c4aa0bb1..761588684b 100644 --- a/gnucash/gnome/dialog-payment.c +++ b/gnucash/gnome/dialog-payment.c @@ -59,6 +59,7 @@ static const QofLogModule log_module = G_LOG_DOMAIN; #define DIALOG_PAYMENT_CM_CLASS "payment-dialog" +#define GNC_PREFS_GROUP "dialogs.process-payment" typedef enum { @@ -327,8 +328,9 @@ gnc_payment_window_close_handler (gpointer data) { PaymentWindow *pw = data; - if (pw) - gtk_widget_destroy (pw->dialog); + if (!pw) return; + gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(pw->dialog)); + gtk_widget_destroy (pw->dialog); } static void @@ -1203,6 +1205,19 @@ doc_sort_func (GtkTreeModel *model, return ret; } +static gboolean +payment_dialog_delete_event_cb (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + PaymentWindow *pw = user_data; + + // this cb allows the window size to be saved on closing with the X + gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(pw->dialog)); + + return FALSE; +} + static PaymentWindow * new_payment_window (GtkWindow *parent, QofBook *book, InitialPaymentInfo *tx_info) { @@ -1404,6 +1419,8 @@ new_payment_window (GtkWindow *parent, QofBook *book, InitialPaymentInfo *tx_inf g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (gnc_payment_dialog_xfer_acct_changed_cb), pw); + g_signal_connect (G_OBJECT(pw->dialog), "delete-event", + G_CALLBACK(payment_dialog_delete_event_cb), pw); /* Register with the component manager */ pw->component_id = @@ -1418,6 +1435,8 @@ new_payment_window (GtkWindow *parent, QofBook *book, InitialPaymentInfo *tx_inf QOF_EVENT_CREATE | QOF_EVENT_MODIFY | QOF_EVENT_DESTROY); + gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(pw->dialog), GTK_WINDOW(parent)); + /* Show it all */ gtk_widget_show_all (pw->dialog); g_object_unref(G_OBJECT(builder)); diff --git a/gnucash/gschemas/org.gnucash.GnuCash.dialogs.gschema.xml.in b/gnucash/gschemas/org.gnucash.GnuCash.dialogs.gschema.xml.in index 8554d2d3a2..9f587595cc 100644 --- a/gnucash/gschemas/org.gnucash.GnuCash.dialogs.gschema.xml.in +++ b/gnucash/gschemas/org.gnucash.GnuCash.dialogs.gschema.xml.in @@ -1,10 +1,12 @@ + + @@ -37,6 +39,16 @@ + + + (-1,-1,-1,-1) + Last window position and size + This setting describes the size and position of the window when it was last closed. + The numbers are the X and Y coordinates of the top left corner of the window + followed by the width and height of the window. + + + (-1,-1,-1,-1) @@ -87,6 +99,16 @@ + + + (-1,-1,-1,-1) + Last window position and size + This setting describes the size and position of the window when it was last closed. + The numbers are the X and Y coordinates of the top left corner of the window + followed by the width and height of the window. + + + (-1,-1,-1,-1)