[gnumeric] GUI: Fix dialog reuse problem.



commit f96a0d4f83f46d25e68160c265c2bcb195abb0c1
Author: Morten Welinder <terra gnome org>
Date:   Wed Aug 24 12:16:08 2022 -0400

    GUI: Fix dialog reuse problem.
    
    Something changed in gtk or gobject, and what we did no longer works.
    This simplified version ought to work either way.

 ChangeLog      |  5 +++++
 NEWS           |  1 +
 src/gui-util.c | 32 +++++++++++++++++++-------------
 3 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ab9464288..8dabc8963 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-08-24  Morten Welinder  <terra gnome org>
+
+       * src/gui-util.c (gnm_keyed_dialog): Simplify signal handling.
+       Fixes #657, I hope.
+
 2022-08-17  Morten Welinder  <terra gnome org>
 
        * src/gutils.c (gnm_utf8_strto): Handle near-denormal case.
diff --git a/NEWS b/NEWS
index 72ef8611e..de0751f12 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Morten:
        * Fix problems with complex number rendering.  [#638]
        * Fix near-denormal parsing case.  [#656]
        * Fix midly crazy ROUND edge cases.  [#661]
+       * Fix dialog reuse problem.  [#657]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.52
diff --git a/src/gui-util.c b/src/gui-util.c
index 957d7d4ee..bc8f1f84e 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -201,17 +201,17 @@ cb_free_keyed_dialog_context (KeyedDialogContext *ctxt)
                return;
        ctxt->freed = TRUE;
 
-       /*
-        * One of these causes a recursive call which will do nothing due to
-        * ->freed.
-        */
-       g_object_set_data (G_OBJECT (ctxt->wbcg), ctxt->key, NULL);
-       g_object_set_data (G_OBJECT (ctxt->dialog), "KeyedDialog", NULL);
+       if (ctxt->wbcg) {
+               WBCGtk *wbcg = ctxt->wbcg;
+               ctxt->wbcg = NULL;
+               g_object_set_data (G_OBJECT (wbcg), ctxt->key, NULL);
+       }
+
        g_free (ctxt);
 }
 
 static void
-cb_keyed_dialog_destroy (GtkDialog *dialog)
+cb_keyed_dialog_destroy (GtkDialog *dialog, KeyedDialogContext *ctxt)
 {
        /*
         * gtk-builder likes to hold refs on objects.  That interferes
@@ -219,6 +219,14 @@ cb_keyed_dialog_destroy (GtkDialog *dialog)
         * Trigger this now.
         */
        g_object_set_data (G_OBJECT (dialog), "state", NULL);
+
+       ctxt->dialog = NULL;
+
+       if (ctxt->wbcg) {
+               WBCGtk *wbcg = ctxt->wbcg;
+               ctxt->wbcg = NULL;
+               g_object_set_data (G_OBJECT (wbcg), ctxt->key, NULL);
+       }
 }
 
 static gint
@@ -329,18 +337,16 @@ gnm_keyed_dialog (WBCGtk *wbcg, GtkWindow *dialog, char const *key)
        go_dialog_guess_alternative_button_order (GTK_DIALOG (dialog));
 
        ctxt = g_new (KeyedDialogContext, 1);
-       ctxt->wbcg   = wbcg;
+       ctxt->wbcg = wbcg;
        ctxt->dialog = GTK_WIDGET (dialog);
-       ctxt->key  = key;
+       ctxt->key = key;
        ctxt->freed = FALSE;
        g_object_set_data_full (G_OBJECT (wbcg), key, ctxt,
                                (GDestroyNotify)cb_free_keyed_dialog_context);
-       g_object_set_data_full (G_OBJECT (dialog), "KeyedDialog", ctxt,
-                               (GDestroyNotify)cb_free_keyed_dialog_context);
        g_signal_connect (G_OBJECT (dialog), "key_press_event",
                          G_CALLBACK (cb_keyed_dialog_keypress), NULL);
        g_signal_connect (G_OBJECT (dialog), "destroy",
-                         G_CALLBACK (cb_keyed_dialog_destroy), NULL);
+                         G_CALLBACK (cb_keyed_dialog_destroy), ctxt);
 
        gnm_restore_window_geometry (dialog, key);
 }
@@ -364,7 +370,7 @@ gnm_dialog_raise_if_exists (WBCGtk *wbcg, char const *key)
 
        /* Ensure we only pop up one copy per workbook */
        ctxt = g_object_get_data (G_OBJECT (wbcg), key);
-       if (ctxt && GTK_IS_WINDOW (ctxt->dialog)) {
+       if (ctxt && ctxt->dialog && GTK_IS_WINDOW (ctxt->dialog)) {
                gdk_window_raise (gtk_widget_get_window (ctxt->dialog));
                return ctxt->dialog;
        } else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]