? gedit/.gedit-mdi-child.c.swp
Index: gedit/ChangeLog
===================================================================
RCS file: /cvs/gnome/gedit/gedit/ChangeLog,v
retrieving revision 1.660
diff -u -p -r1.660 ChangeLog
--- gedit/ChangeLog	2 Oct 2004 17:06:30 -0000	1.660
+++ gedit/ChangeLog	2 Oct 2004 18:13:44 -0000
@@ -1,5 +1,12 @@
 2004-10-02  Paolo Maggi  <paolo@gnome.org>
 
+	* gedit-mdi-child.c (gedit_mdi_child_tab_close_clicked): If a view is closed 
+	while another one is active, re-activate the previous active view (fixes
+	bug #149811: after closing a document jump to document which has been 
+	open before)
+
+2004-10-02  Paolo Maggi  <paolo@gnome.org>
+
 	* gedit-mdi.c (gedit_mdi_drag_data_received_handler): always opens the 
 	dropped files in the right target gedit window (fixes bug #150485: 
 	Dragging and dropping doesn't choose the right window)
Index: gedit/gedit-file.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-file.c,v
retrieving revision 1.72
diff -u -p -r1.72 gedit-file.c
--- gedit/gedit-file.c	30 Sep 2004 19:07:40 -0000	1.72
+++ gedit/gedit-file.c	2 Oct 2004 18:13:45 -0000
@@ -141,26 +141,27 @@ gedit_file_new (void)
 	gtk_widget_grab_focus (GTK_WIDGET (gedit_get_active_view ()));
 }
 
-void 
+gboolean
 gedit_file_close (GtkWidget *view)
 {
 	BonoboMDIChild* child;
+	gboolean closed;
 
 	gedit_debug (DEBUG_FILE, "");
 
-	g_return_if_fail (view != NULL);
+	g_return_val_if_fail (view != NULL, FALSE);
 
 	child = bonobo_mdi_get_child_from_view (view);
 	g_return_if_fail (child != NULL);
 
 	if (g_list_length (bonobo_mdi_child_get_views (child)) > 1)
 	{		
-		bonobo_mdi_remove_view (BONOBO_MDI (gedit_mdi), view, FALSE);
+		closed = bonobo_mdi_remove_view (BONOBO_MDI (gedit_mdi), view, FALSE);
 		gedit_debug (DEBUG_COMMANDS, "View removed.");
 	}
 	else
 	{
-		bonobo_mdi_remove_child (BONOBO_MDI (gedit_mdi), child, FALSE);
+		closed = bonobo_mdi_remove_child (BONOBO_MDI (gedit_mdi), child, FALSE);
 		gedit_debug (DEBUG_COMMANDS, "Child removed.");
 	}
 
@@ -172,6 +173,8 @@ gedit_file_close (GtkWidget *view)
 	}
 
 	gedit_debug (DEBUG_FILE, "END");
+
+	return closed;
 }
 
 void
Index: gedit/gedit-file.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-file.h,v
retrieving revision 1.14
diff -u -p -r1.14 gedit-file.h
--- gedit/gedit-file.h	16 Jul 2004 10:07:04 -0000	1.14
+++ gedit/gedit-file.h	2 Oct 2004 18:13:45 -0000
@@ -38,7 +38,7 @@
 
 void 		gedit_file_new 		(void);
 void 		gedit_file_open 	(GeditMDIChild *active_child);
-void 		gedit_file_close 	(GtkWidget *view);
+gboolean	gedit_file_close 	(GtkWidget *view);
 gboolean	gedit_file_save 	(GeditMDIChild *child, gboolean force);
 gboolean 	gedit_file_save_as 	(GeditMDIChild *child);
 void		gedit_file_save_all 	(void);
Index: gedit/gedit-mdi-child.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-mdi-child.c,v
retrieving revision 1.29
diff -u -p -r1.29 gedit-mdi-child.c
--- gedit/gedit-mdi-child.c	14 Jul 2004 15:16:14 -0000	1.29
+++ gedit/gedit-mdi-child.c	2 Oct 2004 18:13:45 -0000
@@ -457,13 +457,26 @@ gedit_mdi_child_get_config_string (Bonob
 static void
 gedit_mdi_child_tab_close_clicked (GtkWidget *button, GtkWidget *view)
 {
+	GtkWidget *active_view;
+	gboolean closed;
+
 	gedit_debug (DEBUG_MDI, "");
 
 	g_return_if_fail (GEDIT_IS_VIEW (view));
 
-	bonobo_mdi_set_active_view (BONOBO_MDI (gedit_mdi), view);
+	active_view = gedit_get_active_view();
+
+	if (active_view != view)
+		bonobo_mdi_set_active_view (BONOBO_MDI (gedit_mdi), view);
+	else
+		active_view = NULL;
 	
-	gedit_file_close (view);
+	closed = gedit_file_close (view);
+
+	/* If a view is closed while another one is active, re-activate the previous
+	 * active view */
+	if ((active_view != NULL) && closed)
+		bonobo_mdi_set_active_view (BONOBO_MDI (gedit_mdi), active_view);
 }
 
 static void
