[Xfce4-commits] <ristretto:ristretto-0.3> Make a difference between delete and move-to-trash

Stephan Arts noreply at xfce.org
Sat Mar 10 22:32:03 CET 2012


Updating branch refs/heads/ristretto-0.3
         to fc1309f4d0a84a9c8f5f2e6804d316c3cc85a9bd (commit)
       from f8f3ff68b2eb2ff3be29602590a42bef60945136 (commit)

commit fc1309f4d0a84a9c8f5f2e6804d316c3cc85a9bd
Author: Stephan Arts <stephan at xfce.org>
Date:   Sat Mar 10 22:29:40 2012 +0100

    Make a difference between delete and move-to-trash

 src/main_window.c |   70 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/src/main_window.c b/src/main_window.c
index c1f4132..d25d65f 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -445,6 +445,7 @@ rstto_main_window_init (RsttoMainWindow *window)
     GClosure        *next_image_closure = g_cclosure_new ((GCallback)cb_rstto_main_window_next_image, window, NULL);
     GClosure        *previous_image_closure = g_cclosure_new ((GCallback)cb_rstto_main_window_previous_image, window, NULL);
     GClosure        *quit_closure = g_cclosure_new ((GCallback)cb_rstto_main_window_quit, window, NULL);
+    GClosure        *delete_closure = g_cclosure_new ((GCallback)cb_rstto_main_window_delete, window, NULL);
 
     guint navigationbar_position = 3;
 
@@ -515,6 +516,7 @@ rstto_main_window_init (RsttoMainWindow *window)
     gtk_accel_group_connect_by_path (accel_group, "<Window>/next-image", next_image_closure);
     gtk_accel_group_connect_by_path (accel_group, "<Window>/previous-image", previous_image_closure);
     gtk_accel_group_connect_by_path (accel_group, "<Window>/quit", quit_closure);
+    gtk_accel_group_connect_by_path (accel_group, "<Window>/delete", delete_closure);
 
     /* Set default accelerators */
     gtk_accel_map_change_entry ("<Window>/fullscreen", GDK_F, 0, FALSE);
@@ -522,6 +524,8 @@ rstto_main_window_init (RsttoMainWindow *window)
     gtk_accel_map_change_entry ("<Window>/next-image", GDK_Page_Down, 0, FALSE);
     gtk_accel_map_change_entry ("<Window>/previous-image", GDK_Page_Up, 0, FALSE);
     gtk_accel_map_change_entry ("<Window>/quit", GDK_q, 0, FALSE);
+
+    gtk_accel_map_change_entry ("<Window>/delete", GDK_Delete, GDK_SHIFT_MASK, FALSE);
     if (gtk_accel_map_lookup_entry ("<Actions>/RsttoWindow/play", NULL) == FALSE)
     {
         gtk_accel_map_change_entry ("<Actions>/RsttoWindow/play", GDK_F5, 0, FALSE);
@@ -3101,29 +3105,67 @@ cb_rstto_main_window_delete (
     RsttoFile *file = rstto_image_list_iter_get_file (window->priv->iter);
     const gchar *file_basename = rstto_file_get_display_name(file);
     GtkWidget *dialog;
+    GdkModifierType state;
+    gboolean delete_file = FALSE;
+
     g_return_if_fail (rstto_image_list_get_n_images (window->priv->image_list) > 0);
 
-    dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                                GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                GTK_MESSAGE_WARNING,
-                                                GTK_BUTTONS_OK_CANCEL,
-                                                _("Are you sure you want to delete image '%s' from disk?"),
-                                                file_basename);
+    if (gtk_get_current_event_state (&state))
+    {
+        if (state & GDK_SHIFT_MASK)
+        {
+            delete_file = TRUE;
+        }
+    }
 
-    g_object_ref (file);
-    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+    if (delete_file)
     {
-        if (g_file_trash (rstto_file_get_file(file), NULL, NULL) == TRUE)
+        dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                    GTK_MESSAGE_WARNING,
+                                                    GTK_BUTTONS_OK_CANCEL,
+                                                    _("Are you sure you want to delete image '%s' from disk?"),
+                                                    file_basename);
+
+        g_object_ref (file);
+        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
         {
-            rstto_image_list_remove_file (window->priv->image_list, file);
+            if (g_file_delete (rstto_file_get_file(file), NULL, NULL) == TRUE)
+            {
+                rstto_image_list_remove_file (window->priv->image_list, file);
+            }
+            else
+            {
+                
+            }
         }
-        else
+        gtk_widget_destroy (dialog);
+        g_object_unref (file);
+    }
+    else
+    {
+        dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                    GTK_MESSAGE_WARNING,
+                                                    GTK_BUTTONS_OK_CANCEL,
+                                                    _("Are you sure you want to send image '%s' to trash?"),
+                                                    file_basename);
+
+        g_object_ref (file);
+        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
         {
-            
+            if (g_file_trash (rstto_file_get_file(file), NULL, NULL) == TRUE)
+            {
+                rstto_image_list_remove_file (window->priv->image_list, file);
+            }
+            else
+            {
+                
+            }
         }
+        gtk_widget_destroy (dialog);
+        g_object_unref (file);
     }
-    gtk_widget_destroy (dialog);
-    g_object_unref (file);
 }
 
 static gboolean


More information about the Xfce4-commits mailing list