Index: gedit/bonobo-mdi.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/bonobo-mdi.c,v
retrieving revision 1.38
diff -p -u -u -p -r1.38 bonobo-mdi.c
--- gedit/bonobo-mdi.c	13 Nov 2004 12:53:34 -0000	1.38
+++ gedit/bonobo-mdi.c	4 Jan 2005 15:49:47 -0000
@@ -874,6 +874,56 @@ book_button_release (GtkWidget *widget, 
 	return FALSE;
 }
 
+static void
+menu_position_under_widget (GtkMenu *menu, int *x, int *y,
+			    gboolean *push_in, gpointer user_data)
+{
+	GtkWidget *w;
+	int screen_width, screen_height;
+	GtkRequisition requisition;
+
+	w = GTK_WIDGET (user_data);
+	
+	gdk_window_get_origin (w->window, x, y);
+	*x += w->allocation.x;
+	*y += w->allocation.y + w->allocation.height;
+
+	gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
+
+	screen_width = gdk_screen_width ();
+	screen_height = gdk_screen_height ();
+
+	*x = CLAMP (*x, 0, MAX (0, screen_width - requisition.width));
+	*y = CLAMP (*y, 0, MAX (0, screen_height - requisition.height));
+}
+
+static gboolean
+book_popup_menu (GtkWidget *widget, gpointer data)
+{
+	GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+	GtkWidget *view, *tab_label, *menu;
+	int cur_page;
+
+	cur_page = gtk_notebook_get_current_page (notebook);
+	if (cur_page < 0) return FALSE;
+
+	view = gtk_notebook_get_nth_page (notebook, cur_page);
+	g_return_val_if_fail (view != NULL, FALSE);
+
+	tab_label = gtk_notebook_get_tab_label (notebook, view);
+	g_return_val_if_fail (tab_label != NULL, FALSE);
+
+	menu = GTK_WIDGET (g_object_get_data (G_OBJECT (tab_label), "gedit-mdi-child-popup-menu"));
+	if (menu == NULL) return FALSE;
+
+	gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+			menu_position_under_widget, tab_label,
+			0, gtk_get_current_event_time ());
+	gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
+
+	return TRUE;
+}
+
 gint 
 bonobo_mdi_n_views_for_window (BonoboWindow *win)
 {
@@ -971,6 +1021,9 @@ book_create (BonoboMDI *mdi)
 	g_signal_connect (G_OBJECT (us), "button_release_event",
 			  G_CALLBACK (book_button_release), mdi);
 
+	g_signal_connect (G_OBJECT (us), "popup_menu",
+			  G_CALLBACK (book_popup_menu), mdi);
+	
 	gtk_notebook_set_scrollable (GTK_NOTEBOOK (us), TRUE);
 	
 	gedit_debug (DEBUG_MDI, "END");
Index: gedit/gedit-mdi-child.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-mdi-child.c,v
retrieving revision 1.35
diff -p -u -u -p -r1.35 gedit-mdi-child.c
--- gedit/gedit-mdi-child.c	6 Dec 2004 18:13:36 -0000	1.35
+++ gedit/gedit-mdi-child.c	4 Jan 2005 15:49:48 -0000
@@ -872,6 +872,8 @@ gedit_mdi_child_set_label (BonoboMDIChil
 		gnome_popup_menu_attach (popup_menu, event_box, NULL);
 		GTK_WIDGET_SET_FLAGS (event_box, GTK_NO_WINDOW);
 
+		g_object_set_data (G_OBJECT (hbox), "gedit-mdi-child-popup-menu", popup_menu);
+
 		/* setup the tooltip */
 		set_tooltip (tooltips, event_box, child);
 		
