[gtk+] filechooserentry: Modify _gtk_file_chooser_entry_get_current_folder()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] filechooserentry: Modify _gtk_file_chooser_entry_get_current_folder()
- Date: Fri, 16 Dec 2011 19:13:14 +0000 (UTC)
commit e2105c2befc3c0a10ccb5223714f1a68ee1b4c0b
Author: Benjamin Otte <otte redhat com>
Date: Sat Nov 5 03:53:32 2011 +0100
filechooserentry: Modify _gtk_file_chooser_entry_get_current_folder()
The new version does not need to muck with the entry, it just extracts
the required information. It returns a reference to the folder though,
as we extract the information now instead of returning something stored.
gtk/gtkfilechooserdefault.c | 5 +++--
gtk/gtkfilechooserentry.c | 27 +++++++++++++++++++++++----
2 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 53a3b38..8616b76 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -7640,7 +7640,7 @@ check_save_entry (GtkFileChooserDefault *impl,
if (!file_part || file_part[0] == '\0')
{
- *file_ret = g_object_ref (current_folder);
+ *file_ret = current_folder;
*is_well_formed_ret = TRUE;
*is_file_part_empty_ret = TRUE;
*is_folder = TRUE;
@@ -7652,6 +7652,7 @@ check_save_entry (GtkFileChooserDefault *impl,
error = NULL;
file = g_file_get_child_for_display_name (current_folder, file_part, &error);
+ g_object_unref (current_folder);
if (!file)
{
@@ -8953,7 +8954,7 @@ gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
data = g_new0 (struct FileExistsData, 1);
data->impl = g_object_ref (impl);
data->file = g_object_ref (file);
- data->parent_file = g_object_ref (_gtk_file_chooser_entry_get_current_folder (entry));
+ data->parent_file = _gtk_file_chooser_entry_get_current_folder (entry);
if (impl->file_exists_get_info_cancellable)
g_cancellable_cancel (impl->file_exists_get_info_cancellable);
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c
index 11d1838..14f9318 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -440,6 +440,23 @@ gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
return file;
}
+static GFile *
+gtk_file_chooser_get_directory_for_text (GtkFileChooserEntry *chooser_entry,
+ const char * text)
+{
+ GFile *file, *parent;
+
+ file = gtk_file_chooser_get_file_for_text (chooser_entry, text);
+
+ if (text[0] == 0 || text[strlen (text) - 1] == G_DIR_SEPARATOR)
+ return file;
+
+ parent = g_file_get_parent (file);
+ g_object_unref (file);
+
+ return parent;
+}
+
static gboolean
gtk_file_chooser_entry_parse (GtkFileChooserEntry *chooser_entry,
const gchar *str,
@@ -1675,14 +1692,16 @@ _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
* be different. If the user has entered unparsable text, or text which
* the entry cannot handle, this will return %NULL.
*
- * Return value: the file for the current folder - this value is owned by the
- * chooser entry and must not be modified or freed.
+ * Return value: the file for the current folder - you must g_object_unref()
+ * the value after use.
**/
GFile *
_gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
{
- commit_completion_and_refresh (chooser_entry);
- return chooser_entry->current_folder_file;
+ g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
+
+ return gtk_file_chooser_get_directory_for_text (chooser_entry,
+ gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]