Egg recent view cleanup



Hello, I've made a patch that adds "clean" menu item and separator to
egg-recent-view-gtk. I think, it can be useful, especially in panel. 

Also fixed bug in egg-recent-view, that segfault on call of the function
egg_recent_view_set_trailing_sep. There was bug with tooltip
installation on separator:)

The patch is attached. Can it be commited?
Index: egg-recent-model.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/recent-files/egg-recent-model.c,v
retrieving revision 1.26
diff -u -p -r1.26 egg-recent-model.c
--- egg-recent-model.c	31 Jan 2004 16:05:43 -0000	1.26
+++ egg-recent-model.c	5 Apr 2004 10:54:47 -0000
@@ -1500,6 +1500,9 @@ egg_recent_model_clear (EggRecentModel *
 		g_warning ("Failed to unlock: %s", strerror (errno));
 
 	fclose (file);
+	
+	egg_recent_model_changed (model);
+
 }
 
 
Index: egg-recent-view-gtk.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/recent-files/egg-recent-view-gtk.c,v
retrieving revision 1.20
diff -u -p -r1.20 egg-recent-view-gtk.c
--- egg-recent-view-gtk.c	21 Jan 2003 11:06:16 -0000	1.20
+++ egg-recent-view-gtk.c	5 Apr 2004 10:54:47 -0000
@@ -45,6 +45,7 @@ struct _EggRecentViewGtk {
 
 	gboolean leading_sep;
 	gboolean trailing_sep;
+	gboolean clean_button;
 
 	gulong changed_cb_id;
 
@@ -182,102 +183,91 @@ egg_recent_view_gtk_destroy_cb (gpointer
 }
 
 static GtkWidget *
-egg_recent_view_gtk_new_menu_item (EggRecentViewGtk *view,
-				   EggRecentItem *item,
-				   gint index)
+egg_recent_view_gtk_new_menu_item (EggRecentViewGtk * view,
+				   EggRecentItem * item, gint index)
 {
 	GtkWidget *menu_item;
-	EggRecentViewGtkMenuData *md=(EggRecentViewGtkMenuData *)g_malloc (sizeof (EggRecentViewGtkMenuData));
+	EggRecentViewGtkMenuData *md =
+		(EggRecentViewGtkMenuData *) g_malloc (sizeof (EggRecentViewGtkMenuData));
 	gchar *text;
 	gchar *basename;
 	gchar *escaped;
 	gchar *uri;
 
+	gchar *mime_type;
+	GtkWidget *image;
+	GdkPixbuf *pixbuf;
+
 	g_return_val_if_fail (view, NULL);
+	g_return_val_if_fail (item, NULL);
 
-	if (item != NULL) {
-		gchar *mime_type;
-		GtkWidget *image;
-		GdkPixbuf *pixbuf;
-
-		uri = egg_recent_item_get_uri_for_display (item);
-		if (uri == NULL)
-			return NULL;
-		
-		basename = g_path_get_basename (uri);
-		escaped = egg_recent_util_escape_underlines (basename);
-		g_free (basename);
-		g_free (uri);
-
-		if (view->show_numbers) {
-			/* avoid having conflicting mnemonics */
-			if (index >= 10)
-				text = g_strdup_printf ("%d.  %s", index,
-							escaped);
-			else
-				text = g_strdup_printf ("_%d.  %s", index,
-							escaped);
-			g_free (escaped);
-		} else {
-			text = escaped;
-		}
+
+	uri = egg_recent_item_get_uri_for_display (item);
+	if (uri == NULL)
+		return NULL;
+
+	basename = g_path_get_basename (uri);
+	escaped = egg_recent_util_escape_underlines (basename);
+	g_free (basename);
+	g_free (uri);
+
+	if (view->show_numbers) {
+		/* avoid having conflicting mnemonics */
+		if (index >= 10)
+			text = g_strdup_printf ("%d.  %s", index, escaped);
+		else
+			text = g_strdup_printf ("_%d.  %s", index, escaped);
+		g_free (escaped);
+	}
+	else {
+		text = escaped;
+	}
 
 
-		mime_type = egg_recent_item_get_mime_type (item);
+	mime_type = egg_recent_item_get_mime_type (item);
 #ifndef USE_STABLE_LIBGNOMEUI
-		{
-			int width, height;
+	{
+		int width, height;
 
-			gtk_icon_size_lookup_for_settings
-					(gtk_widget_get_settings (view->menu),
-					 view->icon_size,
-					 &width, &height);
-
-			pixbuf = egg_recent_util_get_icon (view->theme, uri,
-							   mime_type,
-							   height);
-		}
+		gtk_icon_size_lookup_for_settings
+			(gtk_widget_get_settings (view->menu),
+			 view->icon_size, &width, &height);
+
+		pixbuf = egg_recent_util_get_icon (view->theme, uri, mime_type, height);
+	}
 #else
-		pixbuf = NULL;
+	pixbuf = NULL;
 #endif
-		image = gtk_image_new_from_pixbuf (pixbuf);
-		if (pixbuf)
-			g_object_unref (pixbuf);
-
-		if (view->show_icons)
-			gtk_widget_show (image);
-
-		menu_item = gtk_image_menu_item_new_with_mnemonic (text);
-		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
-					       image);
-
-		md->view = view;
-		md->item = item;
-
-		egg_recent_item_ref (md->item);
-
-		g_signal_connect_data (G_OBJECT (menu_item), "activate",
-				 G_CALLBACK (egg_recent_view_gtk_menu_cb),
-				 md,
-				 (GClosureNotify)egg_recent_view_gtk_destroy_cb,
-				 0);
+	image = gtk_image_new_from_pixbuf (pixbuf);
+	if (pixbuf)
+		g_object_unref (pixbuf);
+
+	if (view->show_icons)
+		gtk_widget_show (image);
+
+	menu_item = gtk_image_menu_item_new_with_mnemonic (text);
+	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
+
+	md->view = view;
+	md->item = item;
+
+	egg_recent_item_ref (md->item);
+
+	g_signal_connect_data (G_OBJECT (menu_item), "activate",
+			       G_CALLBACK (egg_recent_view_gtk_menu_cb),
+			       md,
+			       (GClosureNotify) egg_recent_view_gtk_destroy_cb, 0);
+
+	g_free (mime_type);
+	g_free (text);
 
-		g_free (mime_type);
-		g_free (text);
-	}
-	else {
-		menu_item = gtk_separator_menu_item_new ();
-	}
-	
 	g_return_val_if_fail (menu_item, NULL);
 
 	/**
 	 * this is a tag so we can distinguish our menu items
 	 * from others that may be in the menu.
 	 */
-	g_object_set_data (G_OBJECT (menu_item),
-			   view->uid,
-			   GINT_TO_POINTER (1));
+	g_object_set_data (G_OBJECT (menu_item), view->uid, GINT_TO_POINTER (1));
 
 
 	gtk_widget_show (menu_item);
@@ -286,54 +276,104 @@ egg_recent_view_gtk_new_menu_item (EggRe
 }
 
 static void
-egg_recent_view_gtk_add_to_menu (EggRecentViewGtk *view,
-				 EggRecentItem *item,
-				 gint display,
-				 gint index)
+egg_recent_view_gtk_add_separator (EggRecentViewGtk * view, gint index)
 {
 	GtkWidget *menu_item;
 	gint menu_offset;
-	
+
+	menu_offset = egg_recent_view_gtk_find_menu_offset (view);
+	menu_item = gtk_separator_menu_item_new ();
+	g_object_set_data (G_OBJECT (menu_item), view->uid, GINT_TO_POINTER (1));
+
+	gtk_widget_show (menu_item);
+
+	gtk_menu_shell_insert (GTK_MENU_SHELL (view->menu), menu_item,
+			       menu_offset + index);
+
+
+}
+
+static void
+egg_recent_view_gtk_clean_cb (GtkMenuItem * item, gpointer data)
+{
+	EggRecentView *view = EGG_RECENT_VIEW (data);
+	EggRecentModel *model;
+
+	model = egg_recent_view_get_model (view);
+	egg_recent_model_clear (model);
+
+	return;
+}
+
+static void
+egg_recent_view_gtk_add_cleanup (EggRecentViewGtk * view, gint index)
+{
+	GtkWidget *menu_item;
+	gint menu_offset;
+
+	menu_offset = egg_recent_view_gtk_find_menu_offset (view);
+	menu_item = gtk_image_menu_item_new_from_stock ("gtk-clear", NULL);
+	g_object_set_data (G_OBJECT (menu_item), view->uid, GINT_TO_POINTER (1));
+
+	g_signal_connect (G_OBJECT (menu_item), "activate",
+			  G_CALLBACK (egg_recent_view_gtk_clean_cb), view);
+
+	gtk_widget_show (menu_item);
+
+	gtk_menu_shell_insert (GTK_MENU_SHELL (view->menu), menu_item,
+			       menu_offset + index);
+
+}
+
+
+static void
+egg_recent_view_gtk_add_to_menu (EggRecentViewGtk * view,
+				 EggRecentItem * item,
+				 gint display, gint index)
+{
+	GtkWidget *menu_item;
+	gint menu_offset;
+
 	g_return_if_fail (view);
 	g_return_if_fail (view->menu);
+	g_return_if_fail (item);
 
 	menu_offset = egg_recent_view_gtk_find_menu_offset (view);
-
 	menu_item = egg_recent_view_gtk_new_menu_item (view, item, display);
 
 	if (view->tooltip_func != NULL && menu_item != NULL) {
 		view->tooltip_func (view->tooltips, menu_item,
 				    item, view->tooltip_func_data);
 	}
-	
+
 	if (menu_item)
 		gtk_menu_shell_insert (GTK_MENU_SHELL (view->menu), menu_item,
-			       menu_offset+index);
+				       menu_offset + index);
 }
 
 
 
 
 static void
-egg_recent_view_gtk_set_list (EggRecentViewGtk *view, GList *list)
+egg_recent_view_gtk_set_list (EggRecentViewGtk * view, GList * list)
 {
 	EggRecentItem *item;
 	GList *p;
-	gint display=1;
-	gint index=1;
+	gint display = 1;
+	gint index = 1;
 
 	g_return_if_fail (view);
 
 	egg_recent_view_gtk_clear (view);
 
 	if (view->leading_sep) {
-		egg_recent_view_gtk_add_to_menu (view, NULL, display, index);
+		egg_recent_view_gtk_add_separator (view, index);
 		index++;
 	}
 
 	p = list;
 	while (p != NULL) {
-		item = (EggRecentItem *)p->data;
+		item = (EggRecentItem *) p->data;
 
 		egg_recent_view_gtk_add_to_menu (view, item, display, index);
 
@@ -342,12 +382,20 @@ egg_recent_view_gtk_set_list (EggRecentV
 		index++;
 	}
 
+	if (view->clean_button) {
+		egg_recent_view_gtk_add_separator (view, index);
+		index++;
+		egg_recent_view_gtk_add_cleanup (view, index);
+		index++;
+	}
+
 	if (view->trailing_sep)
-		egg_recent_view_gtk_add_to_menu (view, NULL, display, index);
+		egg_recent_view_gtk_add_separator (view, index);
 }
 
 static void
-model_changed_cb (EggRecentModel *model, GList *list, EggRecentViewGtk *view)
+model_changed_cb (EggRecentModel * model, GList * list,
+		  EggRecentViewGtk * view)
 {
 	if (list != NULL)
 		egg_recent_view_gtk_set_list (view, list);
@@ -412,6 +460,18 @@ egg_recent_view_gtk_set_trailing_sep (Eg
 	if (view->model)
 		egg_recent_model_changed (view->model);
 }
+
+void
+egg_recent_view_gtk_set_clean_button (EggRecentViewGtk * view, gboolean val)
+{
+	view->clean_button = val;
+
+	egg_recent_view_gtk_clear (view);
+
+	if (view->model)
+		egg_recent_model_changed (view->model);
+}
+
 
 static void
 egg_recent_view_gtk_set_property (GObject *object,
Index: egg-recent-view-gtk.h
===================================================================
RCS file: /cvs/gnome/libegg/libegg/recent-files/egg-recent-view-gtk.h,v
retrieving revision 1.11
diff -u -p -r1.11 egg-recent-view-gtk.h
--- egg-recent-view-gtk.h	6 Jan 2003 04:15:51 -0000	1.11
+++ egg-recent-view-gtk.h	5 Apr 2004 10:54:47 -0000
@@ -45,6 +45,8 @@ void egg_recent_view_gtk_set_leading_sep
 
 void egg_recent_view_gtk_set_trailing_sep    (EggRecentViewGtk *view,
 						gboolean val);
+void egg_recent_view_gtk_set_clean_button    (EggRecentViewGtk *view,
+						gboolean val);
 
 void egg_recent_view_gtk_show_icons          (EggRecentViewGtk *view,
 					      gboolean show);
Index: gtk-view-test.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/recent-files/gtk-view-test.c,v
retrieving revision 1.12
diff -u -p -r1.12 gtk-view-test.c
--- gtk-view-test.c	22 Jan 2004 18:57:25 -0000	1.12
+++ gtk-view-test.c	5 Apr 2004 10:54:47 -0000
@@ -31,6 +31,7 @@ static void dump_list_cb (GtkWidget *but
 static void local_clear_cb (GtkButton *button, gpointer data);
 static void leading_sep_cb (GtkWidget *button, gpointer data);
 static void trailing_sep_cb (GtkWidget *button, gpointer data);
+static void clean_button_cb (GtkWidget *button, gpointer data);
 
 
 typedef struct _MyApp MyApp;
@@ -44,6 +45,7 @@ struct _MyApp {
 
 	GtkWidget *leading_check;
 	GtkWidget *trailing_check;
+	GtkWidget *cleanup_check;
 };
 
 MyApp *app;
@@ -55,6 +57,7 @@ static GtkItemFactoryEntry menu_items[] 
 	{ "/_File/_Open",        NULL, open_cb,       0, "<StockItem>", GTK_STOCK_OPEN },
 	{ "/_File/_Leading Separator", NULL, leading_sep_cb,0, "<CheckItem>"},
 	{ "/_File/_Trailing Separator", NULL, trailing_sep_cb,0, "<CheckItem>"},
+	{ "/_File/_Clean Button", NULL, clean_button_cb,0, "<CheckItem>"},
 	{ "/_File/_Quit",        NULL, gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT },
 	{ "/_List",              NULL, NULL,          0, "<Branch>" },
 	{ "/_List/foo",          NULL, NULL,          0, "<Tearoff>" },
@@ -84,6 +87,15 @@ trailing_sep_cb (GtkWidget *widget, gpoi
 }
 
 static void
+clean_button_cb (GtkWidget *widget, gpointer data)
+{
+	gboolean state;
+
+	state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (app->cleanup_check));
+	
+	egg_recent_view_gtk_set_clean_button (app->view, state);
+}
+static void
 local_clear_cb (GtkButton *button, gpointer data)
 {
 	egg_recent_model_clear (app->model);
@@ -261,6 +273,8 @@ construct_window (MyApp *app, gchar *tit
 						"/File/Leading Separator");
 	app->trailing_check = gtk_item_factory_get_widget (item_factory,
 						"/File/Trailing Separator");
+	app->cleanup_check = gtk_item_factory_get_widget (item_factory,
+						"/File/Clean Button");
 	
 	gtk_box_pack_end (GTK_BOX (vbox), content, TRUE, TRUE, 5);
 	


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