[Xfce4-commits] [xfce/thunar] 01/01: Add support for CTRL+Z in rename dialog (Bug #14956)

noreply at xfce.org noreply at xfce.org
Sun Dec 16 05:58:59 CET 2018


This is an automated email from the git hooks/post-receive script.

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       x   f   c   e   -   4   .   1   2   
   in repository xfce/thunar.

commit a7d40e5f57b6e5255696a09a95738c0dd2ee4642
Author: Andre Miranda <andreldm at xfce.org>
Date:   Sun Dec 16 01:42:24 2018 -0300

    Add support for CTRL+Z in rename dialog (Bug #14956)
---
 thunar/thunar-dialogs.c | 85 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 67 insertions(+), 18 deletions(-)

diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c
index f902ad7..e4932ec 100644
--- a/thunar/thunar-dialogs.c
+++ b/thunar/thunar-dialogs.c
@@ -41,6 +41,16 @@
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-util.h>
 
+#include <gdk/gdkkeysyms.h>
+
+
+
+static void          thunar_dialogs_select_filename      (GtkWidget   *entry,
+                                                          ThunarFile  *file);
+static gboolean      thunar_dialogs_entry_undo           (GtkWidget   *widget,
+                                                          GdkEventKey *event,
+                                                          ThunarFile  *file);
+
 
 
 /**
@@ -72,7 +82,6 @@ thunar_dialogs_show_rename_file (gpointer    parent,
   GtkWindow         *window;
   GdkPixbuf         *icon;
   GdkScreen         *screen;
-  glong              offset;
   gchar             *title;
   gint               response;
   PangoLayout       *layout;
@@ -134,24 +143,12 @@ thunar_dialogs_show_rename_file (gpointer    parent,
   /* setup the old filename */
   gtk_entry_set_text (GTK_ENTRY (entry), filename);
 
-  /* check if we don't have a directory here */
-  if (!thunar_file_is_directory (file))
-    {
-      /* check if the filename contains an extension */
-      text = thunar_util_str_get_extension (filename);
-      if (G_LIKELY (text != NULL))
-        {
-          /* grab focus to the entry first, else the selection will be altered later */
-          gtk_widget_grab_focus (entry);
-
-          /* determine the UTF-8 char offset */
-          offset = g_utf8_pointer_to_offset (filename, text);
+  /* allow reverting the filename with ctrl + z */
+  g_signal_connect (entry, "key-press-event",
+                    G_CALLBACK (thunar_dialogs_entry_undo), file);
 
-          /* select the text prior to the dot */
-          if (G_LIKELY (offset > 0))
-            gtk_editable_select_region (GTK_EDITABLE (entry), 0, offset);
-        }
-    }
+  /* select the filename without the extension */
+  thunar_dialogs_select_filename (entry, file);
 
   /* get the size the entry requires to render the full text */
   layout = gtk_entry_get_layout (GTK_ENTRY (entry));
@@ -839,3 +836,55 @@ thunar_dialogs_show_insecure_program (gpointer     parent,
 
   return (response == GTK_RESPONSE_OK);
 }
+
+
+
+static void thunar_dialogs_select_filename (GtkWidget  *entry,
+                                            ThunarFile *file)
+{
+  const gchar *filename;
+  const gchar *ext;
+  glong        offset;
+
+  /* check if we have a directory here */
+  if (thunar_file_is_directory (file))
+    {
+      gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
+      return;
+    }
+
+  filename = thunar_file_get_display_name (file);
+
+  /* check if the filename contains an extension */
+  ext = thunar_util_str_get_extension (filename);
+  if (G_UNLIKELY (ext == NULL))
+    return;
+
+  /* grab focus to the entry first, else the selection will be altered later */
+  gtk_widget_grab_focus (entry);
+
+  /* determine the UTF-8 char offset */
+  offset = g_utf8_pointer_to_offset (filename, ext);
+
+  /* select the text prior to the dot */
+  if (G_LIKELY (offset > 0))
+    gtk_editable_select_region (GTK_EDITABLE (entry), 0, offset);
+}
+
+
+
+static gboolean thunar_dialogs_entry_undo (GtkWidget   *widget,
+                                           GdkEventKey *event,
+                                           ThunarFile  *file)
+{
+  if ((event->state & GDK_CONTROL_MASK) != 0 && event->keyval == GDK_z)
+    {
+      gtk_entry_set_text (GTK_ENTRY (widget),
+                          thunar_file_get_display_name (file));
+      thunar_dialogs_select_filename (widget, file);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list