summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2008-02-12 17:34:43 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2008-02-12 17:34:43 +0000
commit4118dd893f66ed85565c06a1c2150c4dee8f4b92 (patch)
treeb5d8ab0ec7d607ca7fb0296e7659b9bd67ee02a5 /gtk
parent0c2788943f6ecff1de7baeb23e958d02661ef60e (diff)
downloadgtk+-4118dd893f66ed85565c06a1c2150c4dee8f4b92.tar.gz
Skip exensions when selecting filenames in the save-as dialog. (#362516,
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. svn path=/trunk/; revision=19540
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkfilechooserdefault.c8
-rw-r--r--gtk/gtkfilechooserentry.c37
-rw-r--r--gtk/gtkfilechooserentry.h1
3 files changed, 43 insertions, 3 deletions
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