r23528 - gnucash/trunk/src - Ensure that opening an existing book never opens an empty main window.

Geert Janssens gjanssens at code.gnucash.org
Tue Dec 10 12:13:01 EST 2013


Author: gjanssens
Date: 2013-12-10 12:13:00 -0500 (Tue, 10 Dec 2013)
New Revision: 23528
Trac: http://svn.gnucash.org/trac/changeset/23528

Modified:
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.h
   gnucash/trunk/src/gnome/top-level.c
Log:
Ensure that opening an existing book never opens an empty main window.

If there's only one window, automatically add an account hierarchy page
to it. If it's a subsequent empty window, just ignore it (ie don't restore
it from the state file).

This commit deals with the secondary issue mentioned in
bug 436479 - Gnucash doesn't display the data file name in the title bar

Modified: gnucash/trunk/src/gnome/top-level.c
===================================================================
--- gnucash/trunk/src/gnome/top-level.c	2013-12-10 03:34:43 UTC (rev 23527)
+++ gnucash/trunk/src/gnome/top-level.c	2013-12-10 17:13:00 UTC (rev 23528)
@@ -263,7 +263,7 @@
                                       STATE_FILE_BOOK_GUID, &error);
     if (error)
     {
-        gnc_main_window_restore_default_state();
+        gnc_main_window_restore_default_state(NULL);
         g_warning("error reading group %s key %s: %s",
                   STATE_FILE_TOP, STATE_FILE_BOOK_GUID, error->message);
         LEAVE("no guid in state file");

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2013-12-10 03:34:43 UTC (rev 23527)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2013-12-10 17:13:00 UTC (rev 23528)
@@ -657,6 +657,29 @@
           window, data, data->key_file, data->window_num);
     window_group = g_strdup_printf(WINDOW_STRING, data->window_num + 1);
 
+    /* Deal with the uncommon case that the state file defines a window
+     * but no pages. An example to get in such a situation can be found
+     * here: https://bugzilla.gnome.org/show_bug.cgi?id=436479#c3
+     * If this happens on the first window, we will open an account hierarchy
+     * to avoid confusing the user by presenting a completely empty window.
+     * If it happens on a later window, we'll just skip restoring that window.
+     */
+    if (!g_key_file_has_group (data->key_file, window_group) ||
+        !g_key_file_has_key (data->key_file, window_group, WINDOW_PAGECOUNT, &error))
+    {
+        if (window)
+        {
+            gnc_main_window_restore_default_state (window);
+            PINFO ("saved state had an empty first main window\n"
+                   "an account hierarchy page was added automatically to avoid confusion");
+        }
+        else
+            PINFO ("saved state had an empty main window, skipping restore");
+
+        goto cleanup;
+    }
+
+
     /* Get this window's notebook info */
     page_count = g_key_file_get_integer(data->key_file,
                                         window_group, WINDOW_PAGECOUNT, &error);
@@ -668,7 +691,7 @@
     }
     if (page_count == 0)
     {
-        /* Shound never happen, but has during alpha testing. Having this
+        /* Should never happen, but has during alpha testing. Having this
          * check doesn't hurt anything. */
         goto cleanup;
     }
@@ -911,15 +934,15 @@
 }
 
 void
-gnc_main_window_restore_default_state(void)
+gnc_main_window_restore_default_state(GncMainWindow *window)
 {
     GtkAction *action;
-    GncMainWindow *window;
 
     /* The default state should be to have an Account Tree page open
      * in the window. */
     DEBUG("no saved state file");
-    window = g_list_nth_data(active_windows, 0);
+    if (!window)
+        window = g_list_nth_data(active_windows, 0);
     action = gnc_main_window_find_action(window, "ViewAccountTreeAction");
     gtk_action_activate(action);
 }

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.h	2013-12-10 03:34:43 UTC (rev 23527)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.h	2013-12-10 17:13:00 UTC (rev 23528)
@@ -336,7 +336,7 @@
 
 /** Restore the persistent state of one window to a sane default.
  */
-void gnc_main_window_restore_default_state(void);
+void gnc_main_window_restore_default_state(GncMainWindow *window);
 
 /**
  * gnc_gtk_action_group_set_translation_domain:



More information about the gnucash-changes mailing list