gnome-commander r2455 - in branches/gcmd-1-3: . src



Author: epiotr
Date: Tue Feb 10 21:49:39 2009
New Revision: 2455
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2455&view=rev

Log:
Toggle path/basename/filename selections in F5/F6 dialogs

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/src/gnome-cmd-prepare-xfer-dialog.cc
   branches/gcmd-1-3/src/gnome-cmd-rename-dialog.cc
   branches/gcmd-1-3/src/utils.cc
   branches/gcmd-1-3/src/utils.h

Modified: branches/gcmd-1-3/src/gnome-cmd-prepare-xfer-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-prepare-xfer-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-prepare-xfer-dialog.cc	Tue Feb 10 21:49:39 2009
@@ -246,10 +246,16 @@
 
 static gboolean on_dest_dir_entry_keypressed (GtkEntry *entry, GdkEventKey *event, GnomeCmdPrepareXferDialog *dialog)
 {
-    if (event->keyval == GDK_Return)
+    switch (event->keyval)
     {
-        gtk_signal_emit_by_name (GTK_OBJECT (dialog->ok_button), "clicked", dialog, NULL);
-        return TRUE;
+        case GDK_Return:
+            gtk_signal_emit_by_name (GTK_OBJECT (dialog->ok_button), "clicked", dialog, NULL);
+            return TRUE;
+
+        case GDK_F5:
+        case GDK_F6:
+            gnome_cmd_toggle_file_name_selection (dialog->dest_dir_entry);
+            return TRUE;
     }
 
     return FALSE;

Modified: branches/gcmd-1-3/src/gnome-cmd-rename-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-rename-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-rename-dialog.cc	Tue Feb 10 21:49:39 2009
@@ -44,7 +44,7 @@
 {
     GnomeCmdRenameDialog *dialog = GNOME_CMD_RENAME_DIALOG(widget);
 
-    if (dialog->priv->textbox->editable && event->type == GDK_KEY_PRESS) 
+    if (dialog->priv->textbox->editable && event->type == GDK_KEY_PRESS)
         if (gtk_im_context_filter_keypress (dialog->priv->textbox->im_context, event))
             return TRUE;
 
@@ -74,6 +74,11 @@
             }
             return TRUE;
 
+        case GDK_F5:
+        case GDK_F6:
+            gnome_cmd_toggle_file_name_selection (GTK_WIDGET (dialog->priv->textbox));
+            return TRUE;
+
         default:
             return FALSE;
     }
@@ -157,16 +162,8 @@
 
     gtk_entry_set_text (dialog->priv->textbox, fname);
 
-    if (!GNOME_CMD_IS_DIR (finfo))
-    {
-        gchar *ext = g_utf8_strrchr (fname, -1, '.');
-
-        if (ext && ext[1])      // if fname doesn't end with '.'
-            end_selection = (gint) g_utf8_pointer_to_offset (fname, ext);
-    }
-
     gtk_widget_grab_focus (GTK_WIDGET (dialog->priv->textbox));
-    gtk_entry_select_region (dialog->priv->textbox, 0, end_selection);
+    gtk_entry_select_region (dialog->priv->textbox, 0, -1);
     gtk_widget_show (GTK_WIDGET (dialog->priv->textbox));
 
     g_free (fname);

Modified: branches/gcmd-1-3/src/utils.cc
==============================================================================
--- branches/gcmd-1-3/src/utils.cc	(original)
+++ branches/gcmd-1-3/src/utils.cc	Tue Feb 10 21:49:39 2009
@@ -1345,6 +1345,48 @@
 }
 
 
+void gnome_cmd_toggle_file_name_selection (GtkWidget *entry)
+{
+    const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry));
+    const char *s = strrchr(text,G_DIR_SEPARATOR);                  // G_DIR_SEPARATOR is ASCII, g_utf8_strrchr() is not needed here
+    glong base = s ? g_utf8_pointer_to_offset (text, ++s) : 0;
+
+    gint beg;
+    gint end;
+
+    if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &beg, &end))
+    {
+        beg = base;
+        end = -1;
+    }
+    else
+    {
+        glong text_len = g_utf8_strlen (text, -1);
+
+        s = strrchr(text,'.');                                      // '.' is ASCII, g_utf8_strrchr() is not needed here
+        glong ext = s ? g_utf8_pointer_to_offset (text, s) : -1;
+
+        if (beg==0 && end==text_len)
+        {
+            beg = base;
+            end = ext;
+        }
+        else
+        {
+            if (beg!=base)
+                beg = beg>base ? base : 0;
+            else
+                if (end!=ext || end==text_len)
+                    beg = 0;
+
+            end = -1;
+        }
+    }
+
+    gtk_editable_select_region (GTK_EDITABLE (entry), beg, end);
+}
+
+
 int split(const string &s, vector<string> &coll, const char *sep)
 {
   coll.clear();

Modified: branches/gcmd-1-3/src/utils.h
==============================================================================
--- branches/gcmd-1-3/src/utils.h	(original)
+++ branches/gcmd-1-3/src/utils.h	Tue Feb 10 21:49:39 2009
@@ -230,6 +230,7 @@
 void patlist_free (GList *pattern_list);
 gboolean patlist_matches (GList *pattern_list, const gchar *s);
 
+void gnome_cmd_toggle_file_name_selection (GtkWidget *entry);
 
 inline void gnome_cmd_show_message (GtkWindow *parent, std::string message, const gchar *secondary_text=NULL)
 {



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