[nautilus/gnome-2-32: 47/283] Add a 'Restore Selected Items' button in the trashbar.
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gnome-2-32: 47/283] Add a 'Restore Selected Items' button in the trashbar.
- Date: Thu, 12 Aug 2010 11:07:58 +0000 (UTC)
commit 7e1dfd5ae54d093eea976ef0c77f1b85b63d0771
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Apr 28 16:33:47 2010 +0200
Add a 'Restore Selected Items' button in the trashbar.
This makes the restore function more visible in the UI (#616304).
src/nautilus-trash-bar.c | 122 +++++++++++++++++++++++++++++-------
src/nautilus-trash-bar.h | 5 +-
src/nautilus-window-manage-views.c | 7 +-
3 files changed, 108 insertions(+), 26 deletions(-)
---
diff --git a/src/nautilus-trash-bar.c b/src/nautilus-trash-bar.c
index 109714c..c8a11d2 100644
--- a/src/nautilus-trash-bar.c
+++ b/src/nautilus-trash-bar.c
@@ -26,17 +26,71 @@
#include <gtk/gtk.h>
#include "nautilus-trash-bar.h"
+
+#include "nautilus-window.h"
#include <libnautilus-private/nautilus-file-operations.h>
+#include <libnautilus-private/nautilus-file-utilities.h>
+#include <libnautilus-private/nautilus-file.h>
#include <libnautilus-private/nautilus-trash-monitor.h>
-#define NAUTILUS_TRASH_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
+#define NAUTILUS_TRASH_BAR_GET_PRIVATE(o)\
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
+
+enum {
+ PROP_WINDOW = 1,
+ NUM_PROPERTIES
+};
struct NautilusTrashBarPrivate
{
- GtkWidget *button;
+ GtkWidget *empty_button;
+ GtkWidget *restore_button;
+
+ NautilusWindow *window;
+ gulong selection_handler_id;
};
-G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_HBOX)
+G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_HBOX);
+
+static void
+restore_button_clicked_cb (GtkWidget *button,
+ NautilusTrashBar *bar)
+{
+ GList *locations, *files, *l;
+
+ locations = nautilus_window_info_get_selection (NAUTILUS_WINDOW_INFO (bar->priv->window));
+ files = NULL;
+
+ for (l = locations; l != NULL; l = l->next) {
+ files = g_list_prepend (files, nautilus_file_get (l->data));
+ }
+
+ nautilus_restore_files_from_trash (files, GTK_WINDOW (gtk_widget_get_toplevel (button)));
+
+ nautilus_file_list_free (files);
+ eel_g_object_list_free (locations);
+}
+
+static void
+selection_changed_cb (NautilusWindow *window,
+ NautilusTrashBar *bar)
+{
+ int count;
+
+ count = nautilus_window_info_get_selection_count (NAUTILUS_WINDOW_INFO (window));
+
+ gtk_widget_set_sensitive (bar->priv->restore_button, (count > 0));
+}
+
+static void
+connect_window_and_update_button (NautilusTrashBar *bar)
+{
+ bar->priv->selection_handler_id =
+ g_signal_connect (bar->priv->window, "selection_changed",
+ G_CALLBACK (selection_changed_cb), bar);
+
+ selection_changed_cb (bar->priv->window, bar);
+}
static void
nautilus_trash_bar_set_property (GObject *object,
@@ -49,6 +103,10 @@ nautilus_trash_bar_set_property (GObject *object,
bar = NAUTILUS_TRASH_BAR (object);
switch (prop_id) {
+ case PROP_WINDOW:
+ bar->priv->window = g_value_get_object (value);
+ connect_window_and_update_button (bar);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -56,20 +114,17 @@ nautilus_trash_bar_set_property (GObject *object,
}
static void
-nautilus_trash_bar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_trash_bar_finalize (GObject *obj)
{
NautilusTrashBar *bar;
- bar = NAUTILUS_TRASH_BAR (object);
+ bar = NAUTILUS_TRASH_BAR (obj);
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ if (bar->priv->selection_handler_id) {
+ g_signal_handler_disconnect (bar->priv->window, bar->priv->selection_handler_id);
}
+
+ G_OBJECT_CLASS (nautilus_trash_bar_parent_class)->finalize (obj);
}
static void
@@ -81,7 +136,7 @@ nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
bar = NAUTILUS_TRASH_BAR (data);
- gtk_widget_set_sensitive (bar->priv->button,
+ gtk_widget_set_sensitive (bar->priv->empty_button,
!nautilus_trash_monitor_is_empty ());
}
@@ -92,8 +147,18 @@ nautilus_trash_bar_class_init (NautilusTrashBarClass *klass)
object_class = G_OBJECT_CLASS (klass);
- object_class->get_property = nautilus_trash_bar_get_property;
object_class->set_property = nautilus_trash_bar_set_property;
+ object_class->finalize = nautilus_trash_bar_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_WINDOW,
+ g_param_spec_object ("window",
+ "window",
+ "the NautilusWindow",
+ NAUTILUS_TYPE_WINDOW,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
g_type_class_add_private (klass, sizeof (NautilusTrashBarPrivate));
}
@@ -122,20 +187,33 @@ nautilus_trash_bar_init (NautilusTrashBar *bar)
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (bar), label, FALSE, FALSE, 0);
- bar->priv->button = gtk_button_new_with_mnemonic (_("Empty _Trash"));
- gtk_widget_show (bar->priv->button);
- gtk_box_pack_end (GTK_BOX (hbox), bar->priv->button, FALSE, FALSE, 0);
+ bar->priv->empty_button = gtk_button_new_with_mnemonic (_("Empty _Trash"));
+ gtk_widget_show (bar->priv->empty_button);
+ gtk_box_pack_end (GTK_BOX (hbox), bar->priv->empty_button, FALSE, FALSE, 0);
- gtk_widget_set_sensitive (bar->priv->button,
+ gtk_widget_set_sensitive (bar->priv->empty_button,
!nautilus_trash_monitor_is_empty ());
- gtk_widget_set_tooltip_text (bar->priv->button,
+ gtk_widget_set_tooltip_text (bar->priv->empty_button,
_("Delete all items in the Trash"));
- g_signal_connect (bar->priv->button,
+ g_signal_connect (bar->priv->empty_button,
"clicked",
G_CALLBACK (empty_trash_callback),
bar);
+ bar->priv->restore_button = gtk_button_new_with_mnemonic (_("Restore Selected Items"));
+ gtk_widget_show (bar->priv->restore_button);
+ gtk_box_pack_end (GTK_BOX (hbox), bar->priv->restore_button, FALSE, FALSE, 6);
+
+ gtk_widget_set_sensitive (bar->priv->restore_button, FALSE);
+ gtk_widget_set_tooltip_text (bar->priv->restore_button,
+ _("Restore selected items to their original position"));
+
+ g_signal_connect (bar->priv->restore_button,
+ "clicked",
+ G_CALLBACK (restore_button_clicked_cb),
+ bar);
+
g_signal_connect_object (nautilus_trash_monitor_get (),
"trash_state_changed",
G_CALLBACK (nautilus_trash_bar_trash_state_changed),
@@ -144,11 +222,11 @@ nautilus_trash_bar_init (NautilusTrashBar *bar)
}
GtkWidget *
-nautilus_trash_bar_new (void)
+nautilus_trash_bar_new (NautilusWindow *window)
{
GObject *bar;
- bar = g_object_new (NAUTILUS_TYPE_TRASH_BAR, NULL);
+ bar = g_object_new (NAUTILUS_TYPE_TRASH_BAR, "window", window, NULL);
return GTK_WIDGET (bar);
}
diff --git a/src/nautilus-trash-bar.h b/src/nautilus-trash-bar.h
index 04795f6..fe8770c 100644
--- a/src/nautilus-trash-bar.h
+++ b/src/nautilus-trash-bar.h
@@ -23,6 +23,8 @@
#ifndef __NAUTILUS_TRASH_BAR_H
#define __NAUTILUS_TRASH_BAR_H
+#include "nautilus-window.h"
+
#include <gtk/gtk.h>
G_BEGIN_DECLS
@@ -50,7 +52,8 @@ typedef struct
GType nautilus_trash_bar_get_type (void) G_GNUC_CONST;
-GtkWidget *nautilus_trash_bar_new (void);
+GtkWidget *nautilus_trash_bar_new (NautilusWindow *window);
+
G_END_DECLS
diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c
index b57b973..bc873a2 100644
--- a/src/nautilus-window-manage-views.c
+++ b/src/nautilus-window-manage-views.c
@@ -1487,11 +1487,12 @@ nautilus_window_slot_show_x_content_bar (NautilusWindowSlot *slot, GMount *mount
}
static void
-nautilus_window_slot_show_trash_bar (NautilusWindowSlot *slot)
+nautilus_window_slot_show_trash_bar (NautilusWindowSlot *slot,
+ NautilusWindow *window)
{
GtkWidget *bar;
- bar = nautilus_trash_bar_new ();
+ bar = nautilus_trash_bar_new (window);
gtk_widget_show (bar);
nautilus_window_slot_add_extra_location_widget (slot, bar);
@@ -1624,7 +1625,7 @@ update_for_new_location (NautilusWindowSlot *slot)
nautilus_window_slot_update_query_editor (slot);
if (nautilus_directory_is_in_trash (directory)) {
- nautilus_window_slot_show_trash_bar (slot);
+ nautilus_window_slot_show_trash_bar (slot, window);
}
/* need the mount to determine if we should put up the x-content cluebar */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]