[gimp] app: gimp_session_info_dock_restore(): remove empty dockbooks after restoring



commit 896e29c5f1326480aadd94ea98a89d6126cd5779
Author: Michael Natterer <mitch gimp org>
Date:   Thu May 12 21:21:26 2011 +0200

    app: gimp_session_info_dock_restore(): remove empty dockbooks after restoring
    
    so we don't end up with empty windows if restoring all dockables in
    the dock failed.

 app/widgets/gimpsessioninfo-dock.c |   64 ++++++++++++++++++++++++++++++------
 app/widgets/gimpsessioninfo-dock.h |    2 +-
 2 files changed, 55 insertions(+), 11 deletions(-)
---
diff --git a/app/widgets/gimpsessioninfo-dock.c b/app/widgets/gimpsessioninfo-dock.c
index 9bcb039..af9d557 100644
--- a/app/widgets/gimpsessioninfo-dock.c
+++ b/app/widgets/gimpsessioninfo-dock.c
@@ -28,6 +28,7 @@
 
 #include "gimpdialogfactory.h"
 #include "gimpdock.h"
+#include "gimpdockbook.h"
 #include "gimpdockwindow.h"
 #include "gimpsessioninfo.h"
 #include "gimpsessioninfo-aux.h"
@@ -188,7 +189,7 @@ gimp_session_info_dock_from_widget (GimpDock *dock)
   return dock_info;
 }
 
-void
+GimpDock *
 gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
                                 GimpDialogFactory   *factory,
                                 GdkScreen           *screen,
@@ -197,9 +198,10 @@ gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
   GtkWidget     *dock       = NULL;
   GList         *iter       = NULL;
   GimpUIManager *ui_manager = NULL;
+  gint           n_books    = 0;
 
-  g_return_if_fail (GIMP_IS_DIALOG_FACTORY (factory));
-  g_return_if_fail (GDK_IS_SCREEN (screen));
+  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (factory), NULL);
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
 
   ui_manager = gimp_dock_window_get_ui_manager (GIMP_DOCK_WINDOW (dock_window));
   dock       = gimp_dialog_factory_dialog_new (factory,
@@ -209,7 +211,7 @@ gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
                                                -1 /*view_size*/,
                                                FALSE /*present*/);
 
-  g_return_if_fail (GIMP_IS_DOCK (dock));
+  g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
 
   /* Add the dock to the dock window immediately so the stuff in the
    * dock has access to e.g. a dialog factory
@@ -227,20 +229,62 @@ gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
     {
       GimpSessionInfoBook *book_info = iter->data;
       GtkWidget           *dockbook;
-      GtkWidget           *parent;
 
       dockbook = GTK_WIDGET (gimp_session_info_book_restore (book_info,
                                                              GIMP_DOCK (dock)));
-      parent   = gtk_widget_get_parent (dockbook);
 
-      if (GTK_IS_VPANED (parent))
+      if (dockbook)
+        {
+          GtkWidget *parent = gtk_widget_get_parent (dockbook);
+
+          n_books++;
+
+          if (GTK_IS_PANED (parent))
+            {
+              GtkPaned *paned = GTK_PANED (parent);
+
+              if (dockbook == gtk_paned_get_child2 (paned))
+                gtk_paned_set_position (paned, book_info->position);
+            }
+        }
+    }
+
+  /* Now remove empty dockbooks from the list, check the comment in
+   * gimp_session_info_book_restore() which explains why the dock
+   * can contain empty dockbooks at all
+   */
+  if (dock_info && dock_info->books)
+    {
+      GList *books;
+
+      books = g_list_copy (gimp_dock_get_dockbooks (GIMP_DOCK (dock)));
+
+      while (books)
         {
-          GtkPaned *paned = GTK_PANED (parent);
+          GtkContainer *dockbook = books->data;
+          GList        *children = gtk_container_get_children (dockbook);
+
+          if (children)
+            {
+              g_list_free (children);
+            }
+          else
+            {
+              gimp_dock_remove_book (GIMP_DOCK (dock), GIMP_DOCKBOOK (dockbook));
+              n_books--;
+            }
 
-          if (dockbook == gtk_paned_get_child2 (paned))
-            gtk_paned_set_position (paned, book_info->position);
+          books = g_list_remove (books, dockbook);
         }
     }
 
+  /*  if we removed all books again, the dock was destroyed, so bail out  */
+  if (dock_info && dock_info->books && n_books == 0)
+    {
+      return NULL;
+    }
+
   gtk_widget_show (dock);
+
+  return GIMP_DOCK (dock);
 }
diff --git a/app/widgets/gimpsessioninfo-dock.h b/app/widgets/gimpsessioninfo-dock.h
index 89e004a..1e35140 100644
--- a/app/widgets/gimpsessioninfo-dock.h
+++ b/app/widgets/gimpsessioninfo-dock.h
@@ -47,7 +47,7 @@ GTokenType            gimp_session_info_dock_deserialize (GScanner             *
                                                           GimpSessionInfoDock **info,
                                                           const gchar          *dock_type);
 GimpSessionInfoDock * gimp_session_info_dock_from_widget (GimpDock             *dock);
-void                  gimp_session_info_dock_restore     (GimpSessionInfoDock  *dock_info,
+GimpDock            * gimp_session_info_dock_restore     (GimpSessionInfoDock  *dock_info,
                                                           GimpDialogFactory    *factory,
                                                           GdkScreen            *screen,
                                                           GimpDockWindow       *dock_window);



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