reduced the gimp_dock_remove_book() if () {} else if () {} ... paned

2002-03-21  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpdock.c: reduced the gimp_dock_remove_book()
	if () {} else if () {} ... paned removal madness to two cases.
This commit is contained in:
Michael Natterer 2002-03-21 22:49:29 +00:00 committed by Michael Natterer
parent 41e61fa93c
commit 0e789e0630
2 changed files with 20 additions and 72 deletions

View File

@ -1,7 +1,7 @@
2002-03-21 Michael Natterer <mitch@gimp.org> 2002-03-21 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdock.c: reduced the gimp_dock_remove_book() * app/widgets/gimpdock.c: reduced the gimp_dock_remove_book()
if() {} else if () {} ... paned removal madness to two cases. if () {} else if () {} ... paned removal madness to two cases.
2002-03-21 Michael Natterer <mitch@gimp.org> 2002-03-21 Michael Natterer <mitch@gimp.org>

View File

@ -436,7 +436,7 @@ void
gimp_dock_remove_book (GimpDock *dock, gimp_dock_remove_book (GimpDock *dock,
GimpDockbook *dockbook) GimpDockbook *dockbook)
{ {
gint length; gint old_length;
gint index; gint index;
g_return_if_fail (GIMP_IS_DOCK (dock)); g_return_if_fail (GIMP_IS_DOCK (dock));
@ -444,13 +444,13 @@ gimp_dock_remove_book (GimpDock *dock,
g_return_if_fail (dockbook->dock == dock); g_return_if_fail (dockbook->dock == dock);
length = g_list_length (dock->dockbooks); old_length = g_list_length (dock->dockbooks);
index = g_list_index (dock->dockbooks, dockbook); index = g_list_index (dock->dockbooks, dockbook);
dockbook->dock = NULL; dockbook->dock = NULL;
dock->dockbooks = g_list_remove (dock->dockbooks, dockbook); dock->dockbooks = g_list_remove (dock->dockbooks, dockbook);
if (length == 1) if (old_length == 1)
{ {
GtkWidget *separator; GtkWidget *separator;
GList *children; GList *children;
@ -464,88 +464,36 @@ gimp_dock_remove_book (GimpDock *dock,
g_list_free (children); g_list_free (children);
} }
else if (length == 2)
{
GtkWidget *other_book;
GtkWidget *parent;
other_book = g_list_nth_data (dock->dockbooks, 0);
parent = other_book->parent;
g_object_ref (G_OBJECT (other_book));
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (dockbook));
gtk_container_remove (GTK_CONTAINER (parent), other_book);
gtk_container_remove (GTK_CONTAINER (dock->vbox), parent);
gtk_box_pack_start (GTK_BOX (dock->vbox), other_book, TRUE, TRUE, 0);
g_object_unref (G_OBJECT (other_book));
}
else else
{ {
GtkWidget *other_book; GtkWidget *other_book;
GtkWidget *parent; GtkWidget *parent;
GtkWidget *grandparent; GtkWidget *grandparent;
parent = GTK_WIDGET (dockbook)->parent;
grandparent = parent->parent;
if (index == 0) if (index == 0)
{ other_book = GTK_PANED (parent)->child2;
other_book = g_list_nth_data (dock->dockbooks, 0);
parent = other_book->parent;
grandparent = parent->parent;
g_object_ref (G_OBJECT (other_book));
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (dockbook));
gtk_container_remove (GTK_CONTAINER (parent), other_book);
gtk_container_remove (GTK_CONTAINER (grandparent), parent);
gtk_paned_pack1 (GTK_PANED (grandparent), other_book, TRUE, FALSE);
g_object_unref (G_OBJECT (other_book));
}
else if (index == (length - 1))
{
parent = GTK_WIDGET (dockbook)->parent;
other_book = GTK_PANED (parent)->child1;
g_object_ref (G_OBJECT (other_book));
gtk_container_remove (GTK_CONTAINER (parent), other_book);
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (dockbook));
gtk_container_remove (GTK_CONTAINER (dock->vbox), parent);
gtk_box_pack_start (GTK_BOX (dock->vbox), other_book, TRUE, TRUE, 0);
g_object_unref (G_OBJECT (other_book));
}
else else
{ other_book = GTK_PANED (parent)->child1;
parent = GTK_WIDGET (dockbook)->parent;
grandparent = parent->parent;
other_book = GTK_PANED (parent)->child1; g_object_ref (G_OBJECT (other_book));
g_object_ref (G_OBJECT (other_book)); gtk_container_remove (GTK_CONTAINER (parent), other_book);
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (dockbook));
gtk_container_remove (GTK_CONTAINER (parent), other_book); gtk_container_remove (GTK_CONTAINER (grandparent), parent);
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (dockbook));
gtk_container_remove (GTK_CONTAINER (grandparent), parent); if (GTK_IS_VPANED (grandparent))
gtk_paned_pack1 (GTK_PANED (grandparent), other_book, TRUE, FALSE);
else
gtk_box_pack_start (GTK_BOX (dock->vbox), other_book, TRUE, TRUE, 0);
gtk_paned_pack1 (GTK_PANED (grandparent), other_book, TRUE, FALSE); g_object_unref (G_OBJECT (other_book));
g_object_unref (G_OBJECT (other_book));
}
} }
if ((length == 1) && (dock->destroy_if_empty)) if ((old_length == 1) && (dock->destroy_if_empty))
{ {
gtk_widget_destroy (GTK_WIDGET (dock)); gtk_widget_destroy (GTK_WIDGET (dock));
} }