From 4118dd893f66ed85565c06a1c2150c4dee8f4b92 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 12 Feb 2008 17:34:43 +0000 Subject: Skip exensions when selecting filenames in the save-as dialog. (#362516, 2008-02-12 Matthias Clasen 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. svn path=/trunk/; revision=19540 --- gtk/gtkfilechooserdefault.c | 8 ++++++-- gtk/gtkfilechooserentry.c | 37 ++++++++++++++++++++++++++++++++++++- gtk/gtkfilechooserentry.h | 1 + 3 files changed, 43 insertions(+), 3 deletions(-) (limited to 'gtk') diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 08971f8b9d..31978312f4 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -6860,8 +6860,12 @@ update_chooser_entry (GtkFileChooserDefault *impl) 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; } diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c index 24bbc5f32e..3704ccabce 100644 --- a/gtk/gtkfilechooserentry.c +++ b/gtk/gtkfilechooserentry.c @@ -75,6 +75,7 @@ static void gtk_file_chooser_entry_iface_init (GtkEditableClass *iface); 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 @@ _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class) 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 @@ gtk_file_chooser_entry_do_insert_text (GtkEditable *editable, 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 @@ _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry, 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 @@ _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry, 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); +} + diff --git a/gtk/gtkfilechooserentry.h b/gtk/gtkfilechooserentry.h index 19d06b87c9..755e043217 100644 --- a/gtk/gtkfilechooserentry.h +++ b/gtk/gtkfilechooserentry.h @@ -48,6 +48,7 @@ const GtkFilePath *_gtk_file_chooser_entry_get_current_folder (GtkFileChooserEnt 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 -- cgit v1.2.1