? panel-recent.c.clear
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/ChangeLog,v
retrieving revision 1.2380
diff -p -u -r1.2380 ChangeLog
--- ChangeLog	2 Jun 2004 13:36:28 -0000	1.2380
+++ ChangeLog	2 Jun 2004 19:20:32 -0000
@@ -1,0 +1,10 @@
+2004-06-02  William Jon McCann  <mccann@jhu.edu>
+
+	* panel-recent.c (clear_dialog_response): 
+	(clear_dialog_destroy): 
+	(recent_documents_clear_cb):
+	(panel_recent_append_documents_menu): 
+	Add item to Recent Documents menu to clear the history.
+	(panel_recent_model_changed_cb): Make the menu insensitive
+	if no recent items are available.
+
Index: panel-recent.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/panel-recent.c,v
retrieving revision 1.15
diff -p -u -r1.15 panel-recent.c
--- panel-recent.c	28 May 2004 09:59:57 -0000	1.15
+++ panel-recent.c	2 Jun 2004 19:20:32 -0000
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * panel-recent.c
  *
@@ -163,6 +164,92 @@ recent_documents_activate_cb (EggRecentV
 	g_free (mime_type);
 }
 
+static void
+panel_recent_model_changed_cb (EggRecentModel *model,
+                               GList          *list,
+                               GtkWidget      *menu_item)
+{
+	GList *recent_list = NULL;
+
+	recent_list = egg_recent_model_get_list (model);
+	if (recent_list)
+		gtk_widget_set_sensitive (menu_item, TRUE);
+	else
+		gtk_widget_set_sensitive (menu_item, FALSE);
+}
+
+static void
+clear_dialog_response (GtkWidget     *widget,
+		      int             response,
+		      EggRecentModel *model)
+{
+        if (response == GTK_RESPONSE_ACCEPT)
+		egg_recent_model_clear (model);
+
+	gtk_widget_destroy (widget);
+}
+
+
+static GtkWidget *clear_recent_dialog = NULL;
+
+static void
+clear_dialog_destroy (GtkWidget *widget)
+{
+	clear_recent_dialog = NULL;
+}
+
+static void
+recent_documents_clear_cb (GtkMenuItem    *menuitem,
+                           EggRecentModel *model)
+{
+	GtkWidget        *button;
+	GtkWidget        *hbox;
+	GtkWidget        *label;
+
+	if (!clear_recent_dialog) {
+		clear_recent_dialog = gtk_message_dialog_new_with_markup (NULL,
+									  0 /* flags */,
+									  GTK_MESSAGE_QUESTION,
+									  GTK_BUTTONS_NONE,
+									  "<big><b>%s</b></big>\n\n%s",
+									  _("Clear recent document history?"),
+									  _("This will clear the contents of the Recent Documents menu."));
+
+		gtk_dialog_add_button (GTK_DIALOG (clear_recent_dialog),
+				       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+
+		/* Cannot use GTK_STOCK_CLEAR because it also uses the mnemonic c */
+		button = gtk_button_new ();
+		label = gtk_alignment_new (0.5, 0.5, 0, 0);
+		gtk_container_add (GTK_CONTAINER (button), label);
+		hbox = gtk_hbox_new (FALSE, 2);
+		gtk_container_add (GTK_CONTAINER (label), hbox);
+		label = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON);
+		gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+		label = gtk_label_new_with_mnemonic (_("C_lear"));
+		gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+		GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+		gtk_widget_show_all (button);
+		gtk_dialog_add_action_widget (GTK_DIALOG (clear_recent_dialog),
+					      button,
+					      GTK_RESPONSE_ACCEPT);
+
+		gtk_container_set_border_width (GTK_CONTAINER (clear_recent_dialog), 6);
+
+		gtk_dialog_set_default_response (GTK_DIALOG (clear_recent_dialog), GTK_RESPONSE_ACCEPT);
+
+		g_signal_connect (clear_recent_dialog, "response",
+				  G_CALLBACK (clear_dialog_response), model);
+		g_signal_connect (clear_recent_dialog, "destroy",
+				  G_CALLBACK (clear_dialog_destroy), NULL);
+	}
+
+	gtk_window_set_screen (GTK_WINDOW (clear_recent_dialog),
+			       gtk_widget_get_screen (GTK_WIDGET (menuitem)));
+
+	gtk_window_present (GTK_WINDOW (clear_recent_dialog));
+}
+
 void
 panel_recent_append_documents_menu (GtkWidget *top_menu)
 {
@@ -188,8 +275,26 @@ panel_recent_append_documents_menu (GtkW
 	
 	/* a model that shows the global recent doc list */
 	model = egg_recent_model_new (EGG_RECENT_MODEL_SORT_MRU);
+	g_signal_connect (model, "changed",
+			  G_CALLBACK (panel_recent_model_changed_cb),
+			  menu_item);
 
 	view = egg_recent_view_gtk_new (menu, NULL);
+
+	menu_item = gtk_separator_menu_item_new ();
+	gtk_menu_append (menu, menu_item);
+
+	menu_item = gtk_image_menu_item_new ();
+	setup_stock_menu_item (menu_item,
+			       panel_menu_icon_get_size (),
+			       GTK_STOCK_CLEAR,
+			       _("Clear Recent Documents"),
+			       TRUE);
+	gtk_menu_append (menu, menu_item);
+
+	g_signal_connect (menu_item, "activate",
+			  G_CALLBACK (recent_documents_clear_cb),
+			  model);
 
 	g_signal_connect (view, "activate",
 			  G_CALLBACK (recent_documents_activate_cb),
