[gedit] Fix collapsion when managing several notebooks.



commit 5b53f571374d3c7bfd1768ade63f97f4713c9aa7
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Fri Mar 4 14:10:48 2011 +0100

    Fix collapsion when managing several notebooks.
    
    Update the collapse state when a notebook is added or removed.
    Also now is only removed the right border.

 gedit/gedit-multi-notebook.c |   51 +++++++++++++++++++++++++++++++++--------
 gedit/gedit-notebook.c       |    4 +-
 2 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/gedit/gedit-multi-notebook.c b/gedit/gedit-multi-notebook.c
index 535dcd8..9efddc5 100644
--- a/gedit/gedit-multi-notebook.c
+++ b/gedit/gedit-multi-notebook.c
@@ -36,6 +36,7 @@ struct _GeditMultiNotebookPrivate
 	GeditTab  *active_tab;
 
 	guint      removing_notebook : 1;
+	guint      collapse : 1;
 };
 
 enum
@@ -446,6 +447,9 @@ add_notebook (GeditMultiNotebook *mnb,
 	if (main_container)
 	{
 		gtk_box_pack_start (GTK_BOX (mnb), notebook, TRUE, TRUE, 0);
+
+		mnb->priv->notebooks = g_list_append (mnb->priv->notebooks,
+		                                      notebook);
 	}
 	else
 	{
@@ -453,6 +457,8 @@ add_notebook (GeditMultiNotebook *mnb,
 		GtkWidget *parent;
 		GtkAllocation allocation;
 		GtkWidget *active_notebook = mnb->priv->active_notebook;
+		gint active_nb_pos;
+		gboolean collapse_new_notebook = FALSE;
 
 		paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
 		gtk_widget_show (paned);
@@ -474,10 +480,28 @@ add_notebook (GeditMultiNotebook *mnb,
 		/* We need to set the new paned in the right place */
 		gtk_paned_set_position (GTK_PANED (paned),
 		                        allocation.width / 2);
-	}
 
-	mnb->priv->notebooks = g_list_append (mnb->priv->notebooks,
-					      notebook);
+		/* check if we need to uncollapse the active notebook */
+		if (active_notebook == g_list_last (mnb->priv->notebooks)->data &&
+		    mnb->priv->collapse)
+		{
+			collapse_new_notebook = TRUE;
+			gedit_notebook_collapse_border (GEDIT_NOTEBOOK (active_notebook),
+			                                FALSE);
+		}
+
+		active_nb_pos = g_list_index (mnb->priv->notebooks,
+		                              active_notebook);
+		mnb->priv->notebooks = g_list_insert (mnb->priv->notebooks,
+		                                      notebook,
+		                                      active_nb_pos + 1);
+
+		if (collapse_new_notebook)
+		{
+			gedit_notebook_collapse_border (GEDIT_NOTEBOOK (notebook),
+			                                TRUE);
+		}
+	}
 
 	gtk_widget_show (notebook);
 
@@ -506,10 +530,18 @@ remove_notebook (GeditMultiNotebook *mnb,
 			       notebook);
 
 	if (current->next != NULL)
+	{
 		new_notebook = GTK_WIDGET (current->next->data);
+	}
 	else
+	{
 		new_notebook = GTK_WIDGET (mnb->priv->notebooks->data);
 
+		/* we must check if we need to collapse the new last notebook */
+		gedit_notebook_collapse_border (GEDIT_NOTEBOOK (current->prev->data),
+		                                mnb->priv->collapse);
+	}
+
 	parent = gtk_widget_get_parent (notebook);
 
 	/* Now we destroy the widget, we get the children of parent and we destroy
@@ -519,7 +551,7 @@ remove_notebook (GeditMultiNotebook *mnb,
 	mnb->priv->removing_notebook = TRUE;
 
 	gtk_widget_destroy (notebook);
-	
+
 	mnb->priv->notebooks = g_list_remove (mnb->priv->notebooks,
 					      notebook);
 
@@ -877,16 +909,15 @@ void
 gedit_multi_notebook_collapse_notebook_border (GeditMultiNotebook *mnb,
 					       gboolean            collapse)
 {
-	GList *l;
+	GeditNotebook *notebook;
 
 	g_return_if_fail (GEDIT_IS_MULTI_NOTEBOOK (mnb));
 
-	for (l = mnb->priv->notebooks; l != NULL; l = g_list_next (l))
-	{
-		GeditNotebook *notebook = GEDIT_NOTEBOOK (l->data);
+	mnb->priv->collapse = (collapse != FALSE);
 
-		gedit_notebook_collapse_border (notebook, collapse);
-	}
+	notebook = GEDIT_NOTEBOOK (g_list_last (mnb->priv->notebooks)->data);
+
+	gedit_notebook_collapse_border (notebook, collapse);
 }
 
 void
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index 2e196f7..6a72f86 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -666,7 +666,7 @@ gedit_notebook_collapse_border (GeditNotebook *nb,
 	gchar *modified_style;
 	const gchar style[] =
 		".notebook {\n"
-		"	padding: %d 0 %d 0;\n"
+		"	padding: %d 0 %d %d;\n"
 		"}";
 
 	g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
@@ -677,7 +677,7 @@ gedit_notebook_collapse_border (GeditNotebook *nb,
 	gtk_style_context_get_padding (context, gtk_style_context_get_state (context),
 	                               &padding);
 
-	modified_style = g_strdup_printf (style, padding.top, padding.bottom);
+	modified_style = g_strdup_printf (style, padding.top, padding.bottom, padding.left);
 
 	if (collapse)
 	{



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