[gnome-flashback] desktop: add Empty Trash to icon menu



commit 50476cccdaa68bc68cf797150a1b24e02d11a892
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Nov 15 18:43:01 2019 +0200

    desktop: add Empty Trash to icon menu

 gnome-flashback/libdesktop/gf-icon-view.c | 31 ++++++++++++++++++++++++++
 gnome-flashback/libdesktop/gf-icon-view.h |  2 ++
 gnome-flashback/libdesktop/gf-icon.c      | 36 +++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index cb36a99..8d455ba 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -467,6 +467,25 @@ show_item_properties_cb (GObject      *object,
     }
 }
 
+static void
+empty_trash_cb (GObject      *object,
+                GAsyncResult *res,
+                gpointer      user_data)
+{
+  GError *error;
+
+  error = NULL;
+  gf_nautilus_gen_call_empty_trash_finish (GF_NAUTILUS_GEN (object),
+                                           res, &error);
+
+  if (error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Error creating new folder: %s", error->message);
+      g_error_free (error);
+    }
+}
+
 static GfIconInfo *
 create_icon_info (GfIconView *self,
                   GtkWidget  *icon)
@@ -2279,3 +2298,15 @@ gf_icon_view_show_item_properties (GfIconView         *self,
                                                  show_item_properties_cb,
                                                  NULL);
 }
+
+void
+gf_icon_view_empty_trash (GfIconView  *self)
+{
+  if (self->nautilus == NULL)
+    return;
+
+  gf_nautilus_gen_call_empty_trash (self->nautilus,
+                                    self->cancellable,
+                                    empty_trash_cb,
+                                    NULL);
+}
diff --git a/gnome-flashback/libdesktop/gf-icon-view.h b/gnome-flashback/libdesktop/gf-icon-view.h
index bcfc8ab..b72a32e 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.h
+++ b/gnome-flashback/libdesktop/gf-icon-view.h
@@ -39,6 +39,8 @@ GList     *gf_icon_view_get_selected_icons       (GfIconView         *self);
 void       gf_icon_view_show_item_properties     (GfIconView         *self,
                                                   const char * const *uris);
 
+void       gf_icon_view_empty_trash              (GfIconView         *self);
+
 G_END_DECLS
 
 #endif
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index 1472297..09c8919 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -23,6 +23,7 @@
 
 #include "gf-desktop-enums.h"
 #include "gf-desktop-enum-types.h"
+#include "gf-trash-icon.h"
 #include "gf-utils.h"
 
 typedef struct
@@ -133,6 +134,17 @@ open_cb (GtkMenuItem *item,
   icon_open (self);
 }
 
+static void
+empty_trash_cb (GtkMenuItem *item,
+                GfIcon      *self)
+{
+  GfIconPrivate *priv;
+
+  priv = gf_icon_get_instance_private (self);
+
+  gf_icon_view_empty_trash (priv->icon_view);
+}
+
 static void
 properties_cb (GtkMenuItem *item,
                GfIcon      *self)
@@ -178,15 +190,23 @@ properties_cb (GtkMenuItem *item,
 static GtkWidget *
 create_popup_menu (GfIcon *self)
 {
+  GfIconPrivate *priv;
   GtkWidget *popup_menu;
   GtkStyleContext *context;
+  GList *selected_icons;
+  int n_selected_icons;
   GtkWidget *item;
 
+  priv = gf_icon_get_instance_private (self);
+
   popup_menu = gtk_menu_new ();
 
   context = gtk_widget_get_style_context (popup_menu);
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_CONTEXT_MENU);
 
+  selected_icons = gf_icon_view_get_selected_icons (priv->icon_view);
+  n_selected_icons = g_list_length (selected_icons);
+
   item = gtk_menu_item_new_with_label (_("Open"));
   gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
   gtk_widget_show (item);
@@ -195,6 +215,22 @@ create_popup_menu (GfIcon *self)
                     G_CALLBACK (open_cb),
                     self);
 
+  if (GF_IS_TRASH_ICON (self) &&
+      n_selected_icons == 1)
+    {
+      item = gtk_separator_menu_item_new ();
+      gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
+      gtk_widget_show (item);
+
+      item = gtk_menu_item_new_with_label (_("Empty Trash"));
+      gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
+      gtk_widget_show (item);
+
+      g_signal_connect (item, "activate",
+                        G_CALLBACK (empty_trash_cb),
+                        self);
+    }
+
   item = gtk_separator_menu_item_new ();
   gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
   gtk_widget_show (item);


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