gtk+ r19540 - in trunk: . gtk



Author: matthiasc
Date: Tue Feb 12 17:34:43 2008
New Revision: 19540
URL: http://svn.gnome.org/viewvc/gtk+?rev=19540&view=rev

Log:
2008-02-12  Matthias Clasen  <mclasen redhat com>

        Skip exensions when selecting filenames in the save-as dialog.
        (#362516, Carlos Garnacho)

        * gtk/gtkfilechooserentry.h:
        * gtk/gtkfilechooserentry.c (_gtk_file_chooser_entry_select_filename):
        New function to skip the extension part when selecting a filename.
        (_gtk_file_chooser_entry_set_base_folder): Use it here.

        * gtk/gtkfilechooserdefault.c (gtk_file_chooser_entry_grab_focus):
        ...and here.



Modified:
   trunk/ChangeLog
   trunk/gtk/gtkfilechooserdefault.c
   trunk/gtk/gtkfilechooserentry.c
   trunk/gtk/gtkfilechooserentry.h

Modified: trunk/gtk/gtkfilechooserdefault.c
==============================================================================
--- trunk/gtk/gtkfilechooserdefault.c	(original)
+++ trunk/gtk/gtkfilechooserdefault.c	Tue Feb 12 17:34:43 2008
@@ -6860,8 +6860,12 @@
 	    change_entry = TRUE;                                /* ... unless we are in one of the folder modes */
 
           if (change_entry)
-	    _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
-                                                   impl->browse_files_last_selected_name);
+            {
+              _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->browse_files_last_selected_name);
+
+              if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+                _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (impl->location_entry));
+            }
 
           return;
         }

Modified: trunk/gtk/gtkfilechooserentry.c
==============================================================================
--- trunk/gtk/gtkfilechooserentry.c	(original)
+++ trunk/gtk/gtkfilechooserentry.c	Tue Feb 12 17:34:43 2008
@@ -75,6 +75,7 @@
 
 static void     gtk_file_chooser_entry_finalize       (GObject          *object);
 static void     gtk_file_chooser_entry_dispose        (GObject          *object);
+static void     gtk_file_chooser_entry_grab_focus     (GtkWidget        *widget);
 static gboolean gtk_file_chooser_entry_focus          (GtkWidget        *widget,
 						       GtkDirectionType  direction);
 static void     gtk_file_chooser_entry_activate       (GtkEntry         *entry);
@@ -120,6 +121,7 @@
   gobject_class->finalize = gtk_file_chooser_entry_finalize;
   gobject_class->dispose = gtk_file_chooser_entry_dispose;
 
+  widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
   widget_class->focus = gtk_file_chooser_entry_focus;
 
   entry_class->activate = gtk_file_chooser_entry_activate;
@@ -696,6 +698,13 @@
     add_completion_idle (GTK_FILE_CHOOSER_ENTRY (editable));
 }
 
+static void
+gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
+  _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
+}
+
 static gboolean
 gtk_file_chooser_entry_focus (GtkWidget        *widget,
 			      GtkDirectionType  direction)
@@ -929,7 +938,7 @@
   chooser_entry->base_folder = gtk_file_path_copy (path);
 
   gtk_file_chooser_entry_changed (GTK_EDITABLE (chooser_entry));
-  gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, -1);
+  _gtk_file_chooser_entry_select_filename (chooser_entry);
 }
 
 /**
@@ -1074,3 +1083,29 @@
 
   return retval;
 }
+
+
+/*
+ * _gtk_file_chooser_entry_select_filename:
+ * @chooser_entry: a #GtkFileChooserEntry
+ *
+ * Selects the filename (without the extension) for user edition.
+ */
+void
+_gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
+{
+  const gchar *str, *ext;
+  glong len = -1;
+
+  if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+    {
+      str = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
+      ext = g_strrstr (str, ".");
+
+      if (ext)
+       len = g_utf8_pointer_to_offset (str, ext);
+    }
+
+  gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
+}
+

Modified: trunk/gtk/gtkfilechooserentry.h
==============================================================================
--- trunk/gtk/gtkfilechooserentry.h	(original)
+++ trunk/gtk/gtkfilechooserentry.h	Tue Feb 12 17:34:43 2008
@@ -48,6 +48,7 @@
 const gchar *      _gtk_file_chooser_entry_get_file_part      (GtkFileChooserEntry *chooser_entry);
 gboolean           _gtk_file_chooser_entry_get_is_folder      (GtkFileChooserEntry *chooser_entry,
 							       const GtkFilePath   *path);
+void               _gtk_file_chooser_entry_select_filename    (GtkFileChooserEntry *chooser_entry);
 
 G_END_DECLS
 



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