[gtk+/gtk-2-24] filechooserentry: Modify _gtk_file_chooser_entry_get_current_folder()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2-24] filechooserentry: Modify _gtk_file_chooser_entry_get_current_folder()
- Date: Thu, 10 Mar 2016 21:29:33 +0000 (UTC)
commit 877e2381331885bff2db81b32bcbcdd8ac56b784
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 8332cca..95fee55 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -7505,7 +7505,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;
@@ -7517,6 +7517,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)
{
@@ -8816,7 +8817,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 2ba65e0..455e239 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -453,6 +453,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,
@@ -1673,14 +1690,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]