[gimp] app: gimp_session_info_book_restore(): don't set a non-existing current page



commit 68a56a861ef680a441f70f7932d05ceec95e2155
Author: Michael Natterer <mitch gimp org>
Date:   Thu May 12 20:29:05 2011 +0200

    app: gimp_session_info_book_restore(): don't set a non-existing current page
    
    Don't set the first page of the restored dockbook active if there are
    less than two pages. Also add a comment that explains why we return
    the dockbook even though we know that all its dockables failed to
    restore.

 app/widgets/gimpsessioninfo-book.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/app/widgets/gimpsessioninfo-book.c b/app/widgets/gimpsessioninfo-book.c
index 05c65da..6c87e36 100644
--- a/app/widgets/gimpsessioninfo-book.c
+++ b/app/widgets/gimpsessioninfo-book.c
@@ -251,6 +251,7 @@ gimp_session_info_book_restore (GimpSessionInfoBook *info,
 {
   GtkWidget *dockbook;
   GList     *pages;
+  gint       n_dockables = 0;
 
   g_return_val_if_fail (info != NULL, NULL);
   g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
@@ -267,7 +268,10 @@ gimp_session_info_book_restore (GimpSessionInfoBook *info,
       dockable = gimp_session_info_dockable_restore (dockable_info, dock);
 
       if (dockable)
-        gimp_dockbook_add (GIMP_DOCKBOOK (dockbook), dockable, -1);
+        {
+          gimp_dockbook_add (GIMP_DOCKBOOK (dockbook), dockable, -1);
+          n_dockables++;
+        }
     }
 
   if (info->current_page <
@@ -276,10 +280,17 @@ gimp_session_info_book_restore (GimpSessionInfoBook *info,
       gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook),
                                      info->current_page);
     }
-  else
+  else if (n_dockables > 1)
     {
       gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook), 0);
     }
 
+  /*  Return the dockbook even if no dockable could be restored
+   *  (n_dockables == 0) because otherwise we would have to remove it
+   *  from the dock right here, which could implicitly destroy the
+   *  dock and make catching restore errors much harder on higher
+   *  levels. Instead, we check for restored empty dockbooks in our
+   *  caller.
+   */
   return GIMP_DOCKBOOK (dockbook);
 }



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