Re: "empty trash" bar



Il giorno ven, 15/12/2006 alle 17.04 +0100, Alexander Larsson ha
scritto:
> On Thu, 2006-12-14 at 23:28 +0100, Paolo Borelli wrote:
> > This patch adds an extra bar (similar to the ones os search and of
> > burn://) to the Trash directory.
> > 
> > screenshot: http://www.gnome.org/~pborelli/nautilus-trash-bar.png
> > 
> > I think it looks cool and is way more useful than having the "empty
> > trash" button in the Info side pane, since I rarely have the sidepane
> > open. Beside it's consistent with other contextual actions like "Burn
> > CD".
> 
> There was a previous version of this:
> http://pages.cpsc.ucalgary.ca/~weckerl/nautilus_patch.html
> 

D'oh! My bad... oh well, writing it kept me busy during the train
commute :-)

> I think i remember reviewing that, but don't know what came out of it.
> 
> Could you look at it and see which implementation seems best?
> 

The implementations are very similar: there are not many ways to create
an HBox with a button and the widget gets added at the same code spot,
where also the Search bar is added.

They only differ in the following:

* I do not emit a signal when the button is pressed, I simply empty the
trash. According to
http://mail.gnome.org/archives/nautilus-list/2006-April/msg00102.html
this is the way you prefer it.

* I did destroy the widget manually when leaving the trash, but
according to the above thread this is not needed, so I updated the
patch.

* I called the widget nautilus-trash-bar instead of
nautilus-directory-trash-bar... I prefer the shorter name, but I am
biased :-)


Apart from that, my patch also rips out the redundant "Empty Trash"
button from the sidepane. As said in the other mail this is orthogonal
to adding the bar, but I think it makes sense... up to you. If we remove
it, let me know if the same has to be done for "Burn CD".


Updated patch attached (I did not reattach the .c and .h, they are
unchanged).

ciao
	Paolo
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/nautilus/src/Makefile.am,v
retrieving revision 1.165
diff -u -p -u -p -r1.165 Makefile.am
--- src/Makefile.am	18 Oct 2006 12:37:48 -0000	1.165
+++ src/Makefile.am	16 Dec 2006 13:25:28 -0000
@@ -117,6 +117,8 @@ nautilus_SOURCES = \
 	nautilus-spatial-window.h               \
 	nautilus-throbber.c			\
 	nautilus-throbber.h			\
+	nautilus-trash-bar.c			\
+	nautilus-trash-bar.h			\
 	nautilus-window-bookmarks.c		\
 	nautilus-window-bookmarks.h		\
 	nautilus-window-manage-views.c		\
Index: src/nautilus-information-panel.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-information-panel.c,v
retrieving revision 1.235
diff -u -p -u -p -r1.235 nautilus-information-panel.c
--- src/nautilus-information-panel.c	24 May 2006 13:36:46 -0000	1.235
+++ src/nautilus-information-panel.c	16 Dec 2006 13:25:33 -0000
@@ -36,13 +36,8 @@
 #include <eel/eel-string.h>
 #include <eel/eel-vfs-extensions.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
-#include <libxml/parser.h>
-#include <gtk/gtkcheckmenuitem.h>
 #include <gtk/gtkdnd.h>
 #include <gtk/gtkhbox.h>
-#include <gtk/gtkpaned.h>
-#include <gtk/gtknotebook.h>
-#include <gtk/gtksignal.h>
 #include <glib/gi18n.h>
 #include <libgnomeui/gnome-uidefs.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
@@ -52,17 +47,14 @@
 #include <libnautilus-private/nautilus-dnd.h>
 #include <libnautilus-private/nautilus-directory.h>
 #include <libnautilus-private/nautilus-file-dnd.h>
-#include <libnautilus-private/nautilus-file-operations.h>
 #include <libnautilus-private/nautilus-file.h>
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <libnautilus-private/nautilus-keep-last-vertical-box.h>
 #include <libnautilus-private/nautilus-metadata.h>
 #include <libnautilus-private/nautilus-mime-actions.h>
 #include <libnautilus-private/nautilus-program-choosing.h>
-#include <libnautilus-private/nautilus-trash-monitor.h>
 #include <libnautilus-private/nautilus-sidebar-provider.h>
 #include <libnautilus-private/nautilus-module.h>
-#include <math.h>
 
 struct NautilusInformationPanelDetails {
 	GtkVBox *container;
@@ -87,7 +79,6 @@ struct NautilusInformationPanelDetails {
 
 static gboolean nautilus_information_panel_press_event           (GtkWidget                    *widget,
 								  GdkEventButton               *event);
-static void     nautilus_information_panel_destroy               (GtkObject                    *object);
 static void     nautilus_information_panel_finalize              (GObject                      *object);
 static void     nautilus_information_panel_drag_data_received    (GtkWidget                    *widget,
 								  GdkDragContext               *context,
@@ -100,7 +91,6 @@ static void     nautilus_information_pan
 static void     nautilus_information_panel_style_set             (GtkWidget                    *widget,
 								  GtkStyle                     *previous_style);
 static void     nautilus_information_panel_theme_changed         (gpointer                      user_data);
-static void     nautilus_information_panel_confirm_trash_changed (gpointer                      user_data);
 static void     nautilus_information_panel_update_appearance     (NautilusInformationPanel     *information_panel);
 static void     nautilus_information_panel_update_buttons        (NautilusInformationPanel     *information_panel);
 static void     add_command_buttons                              (NautilusInformationPanel     *information_panel,
@@ -111,8 +101,6 @@ static void     nautilus_information_pan
 static void     sidebar_provider_iface_init                      (NautilusSidebarProviderIface *iface);
 static GType    nautilus_information_panel_provider_get_type     (void);
 
-static gboolean confirm_trash_auto_value = TRUE;
-
 enum {
 	LOCATION_CHANGED,
 	LAST_SIGNAL
@@ -213,16 +201,12 @@ nautilus_information_panel_class_init (N
 {
 	GtkWidgetClass *widget_class;
 	GObjectClass *gobject_class;
-	GtkObjectClass *object_class;
 	
 	gobject_class = G_OBJECT_CLASS (klass);
-	object_class = GTK_OBJECT_CLASS (klass);
 	widget_class = GTK_WIDGET_CLASS (klass);
 	
 	gobject_class->finalize = nautilus_information_panel_finalize;
 
-	object_class->destroy = nautilus_information_panel_destroy;
-	
 	widget_class->drag_data_received  = nautilus_information_panel_drag_data_received;
 	widget_class->button_press_event  = nautilus_information_panel_press_event;
 	widget_class->style_set = nautilus_information_panel_style_set;
@@ -262,18 +246,10 @@ static void
 nautilus_information_panel_init (NautilusInformationPanel *information_panel)
 {
 	GtkWidget *widget;
-	static gboolean setup_autos = FALSE;
 
 	widget = GTK_WIDGET (information_panel);
 
 	information_panel->details = g_new0 (NautilusInformationPanelDetails, 1);
-
-	if (!setup_autos) {
-		setup_autos = TRUE;
-		eel_preferences_add_auto_boolean (
-			NAUTILUS_PREFERENCES_CONFIRM_TRASH,
-			&confirm_trash_auto_value);
-	}	
 	
 	/* load the default background */
 	nautilus_information_panel_read_defaults (information_panel);
@@ -303,9 +279,6 @@ nautilus_information_panel_init (Nautilu
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_SIDE_PANE_BACKGROUND_COLOR, nautilus_information_panel_theme_changed, information_panel);
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_SIDE_PANE_BACKGROUND_FILENAME, nautilus_information_panel_theme_changed, information_panel);
 
-	/* add a callback for when the preference whether to confirm trashing/deleting file changes */
-	eel_preferences_add_callback (NAUTILUS_PREFERENCES_CONFIRM_TRASH, nautilus_information_panel_confirm_trash_changed, information_panel);
-
 	/* prepare ourselves to receive dropped objects */
 	gtk_drag_dest_set (GTK_WIDGET (information_panel),
 			   GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, 
@@ -314,16 +287,6 @@ nautilus_information_panel_init (Nautilu
 }
 
 static void
-nautilus_information_panel_destroy (GtkObject *object)
-{
-	NautilusInformationPanel *information_panel;
-
-	information_panel = NAUTILUS_INFORMATION_PANEL (object);
-
-	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
-}
-
-static void
 nautilus_information_panel_finalize (GObject *object)
 {
 	NautilusInformationPanel *information_panel;
@@ -352,11 +315,6 @@ nautilus_information_panel_finalize (GOb
 					 nautilus_information_panel_theme_changed,
 					 information_panel);
 
-	eel_preferences_remove_callback (NAUTILUS_PREFERENCES_CONFIRM_TRASH,
-					 nautilus_information_panel_confirm_trash_changed,
-					 information_panel);
-
-
 	EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
 }
 
@@ -459,17 +417,6 @@ nautilus_information_panel_theme_changed
 	gtk_widget_queue_draw (GTK_WIDGET (information_panel)) ;	
 }
 
-/* handler for handling confirming trash preferences changes */
-
-static void
-nautilus_information_panel_confirm_trash_changed (gpointer user_data)
-{
-	NautilusInformationPanel *information_panel;
-	
-	information_panel = NAUTILUS_INFORMATION_PANEL (user_data);
-	nautilus_information_panel_update_buttons (information_panel);
-}
-
 /* hit testing */
 
 static InformationPanelPart
@@ -518,8 +465,8 @@ receive_dropped_uri_list (NautilusInform
 	char **uris;
 	gboolean exactly_one;
 	GtkWindow *window;
-	
-	uris = g_strsplit (selection_data->data, "\r\n", 0);
+
+	uris = g_uri_list_extract_uris ((gchar *) selection_data->data);
 	exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
 	window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (information_panel)));
 	
@@ -974,17 +921,6 @@ add_buttons_from_metadata (NautilusInfor
 	g_strfreev (terms);
 }
 
-/* handle the hacked-in empty trash command */
-static void
-empty_trash_callback (GtkWidget *button, gpointer data)
-{
-	GtkWidget *window;
-	
-	window = gtk_widget_get_toplevel (button);
-	nautilus_file_operations_empty_trash (window);
-}
-
-
 static void
 burn_cd_callback (GtkWidget *button, gpointer data)
 {
@@ -1004,13 +940,6 @@ burn_cd_callback (GtkWidget *button, gpo
 	}
 }
 
-static void
-nautilus_information_panel_trash_state_changed_callback (NautilusTrashMonitor *trash_monitor,
-						gboolean state, gpointer callback_data)
-{
-		gtk_widget_set_sensitive (GTK_WIDGET (callback_data), !nautilus_trash_monitor_is_empty ());
-}
-
 /*
  * nautilus_information_panel_update_buttons:
  * 
@@ -1039,24 +968,6 @@ nautilus_information_panel_update_button
 		g_free(button_data);
 	}
 
-	/* here is a hack to provide an "empty trash" button when displaying the trash.  Eventually, we
-	 * need a framework to allow protocols to add commands buttons */
-	if (eel_istr_has_prefix (information_panel->details->uri, "trash:")) {
-		/* FIXME: We don't use spaces to pad labels! */
-		temp_button = gtk_button_new_with_mnemonic (_("Empty _Trash"));
-
-		gtk_box_pack_start (GTK_BOX (information_panel->details->button_box), 
-					temp_button, FALSE, FALSE, 0);
-		gtk_widget_set_sensitive (temp_button, !nautilus_trash_monitor_is_empty ());
-		gtk_widget_show (temp_button);
-		information_panel->details->has_buttons = TRUE;
-					
-		g_signal_connect (temp_button, "clicked",
-				  G_CALLBACK (empty_trash_callback), NULL);
-		
-		g_signal_connect_object (nautilus_trash_monitor_get (), "trash_state_changed",
-					 G_CALLBACK (nautilus_information_panel_trash_state_changed_callback), temp_button, 0);
-	}
 	if (eel_istr_has_prefix (information_panel->details->uri, "burn:")) {
 		/* FIXME: We don't use spaces to pad labels! */
 		temp_button = gtk_button_new_with_mnemonic (_("_Write contents to CD"));
@@ -1298,7 +1209,6 @@ static void
 nautilus_information_panel_provider_class_init (NautilusInformationPanelProviderClass *class)
 {
 }
-
 
 void
 nautilus_information_panel_register (void)
Index: src/nautilus-spatial-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.c,v
retrieving revision 1.465
diff -u -p -u -p -r1.465 nautilus-spatial-window.c
--- src/nautilus-spatial-window.c	15 Dec 2006 09:02:26 -0000	1.465
+++ src/nautilus-spatial-window.c	16 Dec 2006 13:25:33 -0000
@@ -42,9 +42,6 @@
 #include "nautilus-search-bar.h"
 #include "nautilus-window-manage-views.h"
 #include "nautilus-zoom-control.h"
-#include <eel/eel-debug.h>
-#include <eel/eel-gdk-extensions.h>
-#include <eel/eel-gdk-pixbuf-extensions.h>
 #include <eel/eel-gtk-extensions.h>
 #include <eel/eel-gtk-macros.h>
 #include <eel/eel-string.h>
@@ -54,16 +51,11 @@
 #include <gtk/gtkmain.h>
 #include <gtk/gtkmenubar.h>
 #include <gtk/gtkmenuitem.h>
-#include <gtk/gtkoptionmenu.h>
-#include <gtk/gtktogglebutton.h>
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkuimanager.h>
 #include <glib/gi18n.h>
 #include <libgnome/gnome-macros.h>
-#include <libgnome/gnome-util.h>
-#include <libgnomeui/gnome-messagebox.h>
 #include <libgnomeui/gnome-uidefs.h>
-#include <libgnomeui/gnome-window-icon.h>
 #include <libgnomevfs/gnome-vfs-uri.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
 #include <libnautilus-private/nautilus-dnd.h>
@@ -76,13 +68,10 @@
 #include <libnautilus-private/nautilus-metadata.h>
 #include <libnautilus-private/nautilus-mime-actions.h>
 #include <libnautilus-private/nautilus-program-choosing.h>
-#include <libnautilus-private/nautilus-clipboard.h>
 #include <libnautilus-private/nautilus-undo.h>
 #include <libnautilus-private/nautilus-search-directory.h>
 #include <libnautilus-private/nautilus-search-engine.h>
 #include <libnautilus-private/nautilus-signaller.h>
-#include <math.h>
-#include <sys/time.h>
 
 #define MAX_TITLE_LENGTH 180
 #define MAX_SHORTNAME_PATH 16
Index: src/nautilus-window-manage-views.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-manage-views.c,v
retrieving revision 1.370
diff -u -p -u -p -r1.370 nautilus-window-manage-views.c
--- src/nautilus-window-manage-views.c	8 Dec 2006 09:49:40 -0000	1.370
+++ src/nautilus-window-manage-views.c	16 Dec 2006 13:25:33 -0000
@@ -35,6 +35,7 @@
 #include "nautilus-pathbar.h"
 #include "nautilus-main.h"
 #include "nautilus-window-private.h"
+#include "nautilus-trash-bar.h"
 #include "nautilus-zoom-control.h"
 #include <eel/eel-accessibility.h>
 #include <eel/eel-debug.h>
@@ -64,6 +65,7 @@
 #include <libnautilus-private/nautilus-module.h>
 #include <libnautilus-private/nautilus-monitor.h>
 #include <libnautilus-private/nautilus-search-directory.h>
+#include <libnautilus-private/nautilus-trash-directory.h>
 #include <libnautilus-private/nautilus-view-factory.h>
 #include <libnautilus-private/nautilus-window-info.h>
 
@@ -1173,7 +1175,19 @@ add_extension_extra_widgets (NautilusWin
 	}
 
 	nautilus_module_extension_list_free (providers);
-	
+}
+
+static void
+nautilus_window_show_trash_bar (NautilusWindow *window)
+{
+	GtkWidget *bar;
+
+	g_assert (NAUTILUS_IS_WINDOW (window));
+
+	bar = nautilus_trash_bar_new ();
+	gtk_widget_show (bar);
+
+	nautilus_window_add_extra_location_widget (window, bar);
 }
 
 /* Handle the changes for the NautilusWindow itself. */
@@ -1233,6 +1247,11 @@ update_for_new_location (NautilusWindow 
 		} else {
 			nautilus_window_set_search_mode (window, FALSE, NULL);
 		}
+
+		if (NAUTILUS_IS_TRASH_DIRECTORY (directory)) {
+			nautilus_window_show_trash_bar (window);
+		}
+
 		nautilus_directory_unref (directory);
 
 		add_extension_extra_widgets (window, window->details->location);


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