diff options
author | Andre Miranda <andreldm@xfce.org> | 2018-12-16 01:42:24 -0300 |
---|---|---|
committer | Andre Miranda <andreldm@xfce.org> | 2018-12-16 01:58:49 -0300 |
commit | a7d40e5f57b6e5255696a09a95738c0dd2ee4642 (patch) | |
tree | fd1158328f6c341c3c913e45de63942a4e53bda0 /thunar | |
parent | 95925eb023144ebe199234b65bafc1f08696f5de (diff) | |
download | thunar-a7d40e5f57b6e5255696a09a95738c0dd2ee4642.tar.gz |
Add support for CTRL+Z in rename dialog (Bug #14956)
Diffstat (limited to 'thunar')
-rw-r--r-- | thunar/thunar-dialogs.c | 85 |
1 files changed, 67 insertions, 18 deletions
diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c index f902ad76..e4932ec8 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; +} |