[gedit] Revert "Remove hack to collapse the right border."



commit 7e7500af04422080a527d6fda2bca88711182bfa
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Fri Dec 23 22:56:20 2011 +0100

    Revert "Remove hack to collapse the right border."
    
    This reverts commit 8c7f5cf43b8d2caf46e37b377de26e867db54cf9.

 gedit/gedit-multi-notebook.c |   36 ++++++++++++++++++++++++
 gedit/gedit-multi-notebook.h |    3 ++
 gedit/gedit-notebook.c       |   62 ++++++++++++++++++++++++++++++++++++++++++
 gedit/gedit-notebook.h       |    3 ++
 gedit/gedit-window.c         |   17 +++++++++++-
 5 files changed, 120 insertions(+), 1 deletions(-)
---
diff --git a/gedit/gedit-multi-notebook.c b/gedit/gedit-multi-notebook.c
index 55a172e..af18848 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
@@ -451,6 +452,7 @@ add_notebook (GeditMultiNotebook *mnb,
 		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);
@@ -473,11 +475,26 @@ add_notebook (GeditMultiNotebook *mnb,
 		gtk_paned_set_position (GTK_PANED (paned),
 		                        allocation.width / 2);
 
+		/* 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);
@@ -513,6 +530,10 @@ remove_notebook (GeditMultiNotebook *mnb,
 	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);
@@ -882,6 +903,21 @@ gedit_multi_notebook_next_notebook (GeditMultiNotebook *mnb)
 }
 
 void
+gedit_multi_notebook_collapse_notebook_border (GeditMultiNotebook *mnb,
+					       gboolean            collapse)
+{
+	GeditNotebook *notebook;
+
+	g_return_if_fail (GEDIT_IS_MULTI_NOTEBOOK (mnb));
+
+	mnb->priv->collapse = (collapse != FALSE);
+
+	notebook = GEDIT_NOTEBOOK (g_list_last (mnb->priv->notebooks)->data);
+
+	gedit_notebook_collapse_border (notebook, collapse);
+}
+
+void
 gedit_multi_notebook_foreach_notebook (GeditMultiNotebook *mnb,
 				       GtkCallback         callback,
 				       gpointer            callback_data)
diff --git a/gedit/gedit-multi-notebook.h b/gedit/gedit-multi-notebook.h
index be3c253..d954aad 100644
--- a/gedit/gedit-multi-notebook.h
+++ b/gedit/gedit-multi-notebook.h
@@ -124,6 +124,9 @@ void			 gedit_multi_notebook_remove_active_notebook	(GeditMultiNotebook *mnb);
 void			 gedit_multi_notebook_previous_notebook		(GeditMultiNotebook *mnb);
 void			 gedit_multi_notebook_next_notebook		(GeditMultiNotebook *mnb);
 
+void			 gedit_multi_notebook_collapse_notebook_border	(GeditMultiNotebook *mnb,
+									 gboolean            collapse);
+
 void			 gedit_multi_notebook_foreach_notebook		(GeditMultiNotebook *mnb,
 									 GtkCallback         callback,
 									 gpointer            callback_data);
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index 92cf494..5e6b7db 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -741,4 +741,66 @@ gedit_notebook_get_close_buttons_sensitive (GeditNotebook *nb)
 	return nb->priv->close_buttons_sensitive;
 }
 
+static void
+remove_right_padding (GeditNotebook *nb)
+{
+	GtkStyleContext *context;
+	GtkBorder padding;
+	gchar *modified_style;
+	GError *error = NULL;
+	const gchar style[] =
+		".notebook {\n"
+		  "padding: %d 0 %d %d;\n"
+		"}";
+
+	/* FIXME: find out a css like way to do this, right now padding-right/left
+	  doesn't work */
+	context = gtk_widget_get_style_context (GTK_WIDGET (nb));
+	gtk_style_context_get_padding (context, gtk_style_context_get_state (context),
+	                               &padding);
+
+	modified_style = g_strdup_printf (style, padding.top, padding.bottom, padding.left);
+
+	/* make it as small as possible */
+	if (nb->priv->css == NULL)
+	{
+		nb->priv->css = gtk_css_provider_new ();
+	}
+
+	if (gtk_css_provider_load_from_data (nb->priv->css, modified_style, -1, &error))
+	{
+		gtk_style_context_add_provider (context,
+		                                GTK_STYLE_PROVIDER (nb->priv->css),
+		                                GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+	}
+	else
+	{
+		g_warning ("%s", error->message);
+		g_error_free (error);
+	}
+
+	g_free (modified_style);
+}
+
+void
+gedit_notebook_collapse_border (GeditNotebook *nb,
+                                gboolean       collapse)
+{
+	g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
+
+	if (collapse)
+	{
+		remove_right_padding (nb);
+	}
+	/* if we made some modification put it back to the default state */
+	else if (nb->priv->css != NULL)
+	{
+		GtkStyleContext *context;
+
+		context = gtk_widget_get_style_context (GTK_WIDGET (nb));
+		gtk_style_context_remove_provider (context,
+		                                   GTK_STYLE_PROVIDER (nb->priv->css));
+	}
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gedit/gedit-notebook.h b/gedit/gedit-notebook.h
index 7c81f83..e2765e7 100644
--- a/gedit/gedit-notebook.h
+++ b/gedit/gedit-notebook.h
@@ -120,6 +120,9 @@ void		gedit_notebook_set_close_buttons_sensitive
 gboolean	gedit_notebook_get_close_buttons_sensitive
 						(GeditNotebook *nb);
 
+void		gedit_notebook_collapse_border	(GeditNotebook *nb,
+						 gboolean       collapse);
+
 G_END_DECLS
 
 #endif /* GEDIT_NOTEBOOK_H */
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 854a63f..5a2363d 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -348,7 +348,22 @@ gedit_window_window_state_event (GtkWidget           *widget,
 	g_settings_set_int (window->priv->window_settings, GEDIT_SETTINGS_WINDOW_STATE,
 			    window->priv->window_state);
 
-	return GTK_WIDGET_CLASS (gedit_window_parent_class)->window_state_event (widget, event);
+	if ((event->changed_mask &
+	    (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) != 0)
+	{
+		gboolean show;
+
+		show = !(event->new_window_state &
+			(GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN));
+
+		gedit_multi_notebook_collapse_notebook_border (window->priv->multi_notebook,
+							       !show);
+	}
+
+	if (GTK_WIDGET_CLASS (gedit_window_parent_class)->window_state_event)
+		return GTK_WIDGET_CLASS (gedit_window_parent_class)->window_state_event (widget, event);
+
+	return FALSE;
 }
 
 static gboolean



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