Commit bb320fcb authored by Owen Taylor's avatar Owen Taylor

Add GtkFileSystem::parse, and a chooser entry with completion

parent 74cb697e
/* GTK - The GIMP Toolkit
* gtkfilechooserwidget.c: Embeddable file selector widget
* gtkfilechooserimpldefault.c: Default implementation of GtkFileChooser
* Copyright (C) 2003, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
......@@ -19,12 +19,15 @@
*/
#include "gtkfilechooserimpldefault.h"
#include "gtkfilechooserentry.h"
#include "gtkfilechooserenums.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "gtkfilesystemmodel.h"
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkhpaned.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkscrolledwindow.h>
......@@ -69,12 +72,14 @@ struct _GtkFileChooserImplDefault
GtkWidget *tree;
GtkWidget *list_scrollwin;
GtkWidget *list;
GtkWidget *entry;
GtkWidget *preview_widget;
};
static void gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class);
static void gtk_file_chooser_impl_default_iface_init (GtkFileChooserIface *iface);
static void gtk_file_chooser_impl_default_init (GtkFileChooserImplDefault *impl);
static void gtk_file_chooser_impl_default_finalize (GObject *object);
static void gtk_file_chooser_impl_default_set_property (GObject *object,
guint prop_id,
const GValue *value,
......@@ -99,6 +104,8 @@ static void tree_selection_changed (GtkTreeSelection *tree_selection,
GtkFileChooserImplDefault *impl);
static void list_selection_changed (GtkTreeSelection *tree_selection,
GtkFileChooserImplDefault *impl);
static void entry_activate (GtkEntry *entry,
GtkFileChooserImplDefault *impl);
GType
_gtk_file_chooser_impl_default_get_type (void)
......@@ -142,6 +149,7 @@ gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = gtk_file_chooser_impl_default_finalize;
gobject_class->set_property = gtk_file_chooser_impl_default_set_property;
gobject_class->get_property = gtk_file_chooser_impl_default_get_property;
......@@ -164,13 +172,20 @@ static void
gtk_file_chooser_impl_default_init (GtkFileChooserImplDefault *impl)
{
GtkWidget *hpaned;
GtkWidget *hbox;
GtkWidget *label;
GtkTreeSelection *selection;
#if 0
GList *focus_chain;
#endif
impl->folder_mode = FALSE;
impl->local_only = TRUE;
impl->preview_widget_active = TRUE;
impl->select_multiple = FALSE;
impl->show_hidden = FALSE;
gtk_container_set_border_width (GTK_CONTAINER (impl), 5);
gtk_widget_push_composite_child ();
......@@ -181,6 +196,8 @@ gtk_file_chooser_impl_default_init (GtkFileChooserImplDefault *impl)
impl->tree_scrollwin = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
GTK_SHADOW_IN);
gtk_paned_add1 (GTK_PANED (hpaned), impl->tree_scrollwin);
gtk_widget_show (impl->tree_scrollwin);
......@@ -199,6 +216,8 @@ gtk_file_chooser_impl_default_init (GtkFileChooserImplDefault *impl)
impl->list_scrollwin = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
GTK_SHADOW_IN);
gtk_paned_add2 (GTK_PANED (hpaned), impl->list_scrollwin);
gtk_widget_show (impl->list_scrollwin);
......@@ -210,10 +229,44 @@ gtk_file_chooser_impl_default_init (GtkFileChooserImplDefault *impl)
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
g_signal_connect (selection, "changed",
G_CALLBACK (list_selection_changed), impl);
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (impl), hbox, FALSE, FALSE, 6);
gtk_widget_show (hbox);
label = gtk_label_new_with_mnemonic ("_Location:");
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
impl->entry = _gtk_file_chooser_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (impl->entry), TRUE);
g_signal_connect (impl->entry, "activate",
G_CALLBACK (entry_activate), impl);
gtk_box_pack_start (GTK_BOX (hbox), impl->entry, TRUE, TRUE, 0);
gtk_widget_show (impl->entry);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), impl->entry);
#if 0
focus_chain = g_list_append (NULL, impl->entry);
focus_chain = g_list_append (focus_chain, impl->tree);
focus_chain = g_list_append (focus_chain, impl->list);
gtk_container_set_focus_chain (GTK_CONTAINER (impl), focus_chain);
g_list_free (focus_chain);
#endif
gtk_widget_pop_composite_child ();
}
static void
gtk_file_chooser_impl_default_finalize (GObject *object)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (object);
g_object_unref (impl->file_system);
}
static void
set_preview_widget (GtkFileChooserImplDefault *impl,
GtkWidget *preview_widget)
......@@ -356,7 +409,7 @@ expand_and_select_func (GtkFileSystemModel *model,
gtk_tree_view_expand_to_path (tree_view, path);
gtk_tree_view_expand_row (tree_view, path, FALSE);
gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), path, NULL, TRUE, 0.3, 0.0);
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), path, NULL, TRUE, 0.3, 0.5);
}
static void
......@@ -364,6 +417,7 @@ gtk_file_chooser_impl_default_set_current_folder (GtkFileChooser *chooser,
const char *uri)
{
GtkFileChooserImplDefault *impl = GTK_FILE_CHOOSER_IMPL_DEFAULT (chooser);
_gtk_file_system_model_uri_do (impl->tree_model, uri,
expand_and_select_func, impl);
}
......@@ -592,6 +646,27 @@ open_and_close (GtkTreeView *tree_view,
gtk_tree_path_free (path);
}
static void
update_chooser_entry (GtkFileChooserImplDefault *impl)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
const GtkFileInfo *info;
GtkTreeIter iter;
GtkTreeIter child_iter;
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
&child_iter,
&iter);
info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
_gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->entry),
gtk_file_info_get_display_name (info));
}
static void
tree_selection_changed (GtkTreeSelection *selection,
GtkFileChooserImplDefault *impl)
......@@ -610,6 +685,7 @@ tree_selection_changed (GtkTreeSelection *selection,
if (impl->current_folder)
g_free (impl->current_folder);
impl->current_folder = g_strdup (uri);
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->entry), uri);
if (impl->list_model)
{
......@@ -647,18 +723,85 @@ tree_selection_changed (GtkTreeSelection *selection,
GTK_TREE_MODEL (impl->sort_model));
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->list),
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
g_signal_emit_by_name (impl, "current_folder_changed", 0);
update_chooser_entry (impl);
g_signal_emit_by_name (impl, "selection_changed", 0);
}
static void
list_selection_changed (GtkTreeSelection *selection,
GtkFileChooserImplDefault *impl)
{
update_chooser_entry (impl);
g_signal_emit_by_name (impl, "selection_changed", 0);
}
static void
entry_activate (GtkEntry *entry,
GtkFileChooserImplDefault *impl)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (entry);
const gchar *folder_uri = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
const gchar *file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
gchar *new_folder = NULL;
/* If the file part is non-empty, we need to figure out if it
* refers to a folder within folder. We could optimize the case
* here where the folder is already loaded for one of our tree models.
*/
if (file_part[0] == '\0' && strcmp (impl->current_folder, folder_uri) != 0)
new_folder = g_strdup (folder_uri);
else
{
GtkFileFolder *folder = NULL;
gchar *subfolder_uri = NULL;
GtkFileInfo *info = NULL;
folder = gtk_file_system_get_folder (impl->file_system,
folder_uri,
GTK_FILE_INFO_IS_FOLDER,
NULL); /* NULL-GError */
if (folder)
subfolder_uri = gtk_file_system_make_uri (impl->file_system,
folder_uri,
file_part,
NULL); /* NULL-GError */
if (subfolder_uri)
info = gtk_file_folder_get_info (folder,
subfolder_uri,
NULL); /* NULL-GError */
if (info && gtk_file_info_get_is_folder (info))
new_folder = g_strdup (subfolder_uri);
if (folder)
g_object_unref (folder);
if (subfolder_uri)
g_free (subfolder_uri);
if (info)
gtk_file_info_free (info);
}
if (new_folder)
{
g_signal_stop_emission_by_name (entry, "activate");
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (impl), new_folder);
_gtk_file_chooser_entry_set_file_part (chooser_entry, "");
g_free (new_folder);
}
}
const GtkFileInfo *
get_list_file_info (GtkFileChooserImplDefault *impl,
GtkTreeIter *iter)
......@@ -749,7 +892,7 @@ _gtk_file_chooser_impl_default_new (GtkFileSystem *file_system)
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
impl->file_system = file_system;
impl->file_system = g_object_ref(file_system);
impl->tree_model = _gtk_file_system_model_new (file_system, NULL, -1,
GTK_FILE_INFO_DISPLAY_NAME);
_gtk_file_system_model_set_show_files (impl->tree_model, FALSE);
......@@ -782,5 +925,8 @@ _gtk_file_chooser_impl_default_new (GtkFileSystem *file_system)
gtk_tree_view_column_set_sort_column_id (column, 1);
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->entry),
file_system);
return result;
}
/* GTK - The GIMP Toolkit
* gtkfilechooserwidget.h: Embeddable file selector widget
* gtkfilechooserimpldefault.h: Default implementation of GtkFileChooser
* Copyright (C) 2003, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
......
/* GTK - The GIMP Toolkit
* gtkfilechooserentry.c: Entry with filename completion
* Copyright (C) 2003, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gtkfilechooserentry.h"
#include <gtk/gtkentry.h>
#include <string.h>
typedef struct _GtkFileChooserEntryClass GtkFileChooserEntryClass;
#define GTK_FILE_CHOOSER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_ENTRY, GtkFileChooserEntryClass))
#define GTK_IS_FILE_CHOOSER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_ENTRY))
#define GTK_FILE_CHOOSER_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_ENTRY, GtkFileChooserEntryClass))
struct _GtkFileChooserEntryClass
{
GtkEntryClass parent_class;
};
struct _GtkFileChooserEntry
{
GtkEntry parent_instance;
GtkFileSystem *file_system;
gchar *base_folder;
gchar *current_folder_uri;
gchar *file_part;
GSource *completion_idle;
GtkFileFolder *current_folder;
guint in_change : 1;
guint has_completion : 1;
};
static void gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class);
static void gtk_file_chooser_entry_iface_init (GtkEditableClass *iface);
static void gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry);
static void gtk_file_chooser_entry_finalize (GObject *object);
static gboolean gtk_file_chooser_entry_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_file_chooser_entry_changed (GtkEditable *editable);
static void gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
const gchar *new_text,
gint new_text_length,
gint *position);
static void clear_completion_callback (GtkFileChooserEntry *chooser_entry,
GParamSpec *pspec);
GObjectClass *parent_class;
GtkEditableClass *parent_editable_iface;
GType
_gtk_file_chooser_entry_get_type (void)
{
static GType file_chooser_entry_type = 0;
if (!file_chooser_entry_type)
{
static const GTypeInfo file_chooser_entry_info =
{
sizeof (GtkFileChooserEntryClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_file_chooser_entry_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkFileChooserEntry),
0, /* n_preallocs */
(GInstanceInitFunc) gtk_file_chooser_entry_init,
};
static const GInterfaceInfo editable_info =
{
(GInterfaceInitFunc) gtk_file_chooser_entry_iface_init, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
};
file_chooser_entry_type = g_type_register_static (GTK_TYPE_ENTRY, "GtkFileChooserEntry",
&file_chooser_entry_info, 0);
g_type_add_interface_static (file_chooser_entry_type,
GTK_TYPE_EDITABLE,
&editable_info);
}
return file_chooser_entry_type;
}
static void
gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
parent_class = g_type_class_peek_parent (class);
gobject_class->finalize = gtk_file_chooser_entry_finalize;
widget_class->focus = gtk_file_chooser_entry_focus;
}
static void
gtk_file_chooser_entry_iface_init (GtkEditableClass *iface)
{
parent_editable_iface = g_type_interface_peek_parent (iface);
iface->do_insert_text = gtk_file_chooser_entry_do_insert_text;
iface->changed = gtk_file_chooser_entry_changed;
}
static void
gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
{
g_signal_connect (chooser_entry, "notify::cursor-position",
G_CALLBACK (clear_completion_callback), NULL);
g_signal_connect (chooser_entry, "notify::selection-bound",
G_CALLBACK (clear_completion_callback), NULL);
}
static void
gtk_file_chooser_entry_finalize (GObject *object)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
if (chooser_entry->current_folder)
g_object_unref (chooser_entry->current_folder);
if (chooser_entry->file_system)
g_object_unref (chooser_entry->file_system);
g_free (chooser_entry->base_folder);
g_free (chooser_entry->current_folder_uri);
g_free (chooser_entry->file_part);
parent_class->finalize (object);
}
static gboolean
completion_idle_callback (GtkFileChooserEntry *chooser_entry)
{
GtkEditable *editable = GTK_EDITABLE (chooser_entry);
GSList *child_uris = NULL;
GSList *tmp_list;
gchar *common_prefix = NULL;
gchar *unique_uri = NULL;
chooser_entry->completion_idle = NULL;
if (!chooser_entry->current_folder &&
chooser_entry->file_system &&
chooser_entry->current_folder_uri)
chooser_entry->current_folder = gtk_file_system_get_folder (chooser_entry->file_system,
chooser_entry->current_folder_uri,
GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_FOLDER,
NULL); /* NULL-GError */
if (chooser_entry->current_folder)
gtk_file_folder_list_children (chooser_entry->current_folder,
&child_uris,
NULL); /* NULL-GError */
for (tmp_list = child_uris; tmp_list; tmp_list = tmp_list->next)
{
GtkFileInfo *info;
info = gtk_file_folder_get_info (chooser_entry->current_folder,
tmp_list->data,
NULL); /* NULL-GError */
if (info)
{
const gchar *display_name = gtk_file_info_get_display_name (info);
if (g_str_has_prefix (display_name, chooser_entry->file_part))
{
if (!common_prefix)
{
common_prefix = g_strdup (display_name);
unique_uri = g_strdup (tmp_list->data);
}
else
{
gchar *p = common_prefix;
const gchar *q = display_name;
while (*p && *p == *q)
{
p++;
q++;
}
*p = '\0';
g_free (unique_uri);
unique_uri = NULL;
}
}
gtk_file_info_free (info);
}
}
if (unique_uri)
{
GtkFileInfo *info;
info = gtk_file_folder_get_info (chooser_entry->current_folder,
unique_uri,
NULL); /* NULL-GError */
if (info)
{
if (gtk_file_info_get_is_folder (info))
{
gchar *tmp = common_prefix;
common_prefix = g_strconcat (tmp, "/", NULL);
g_free (tmp);
}
gtk_file_info_free (info);
}
g_free (unique_uri);
}
g_slist_foreach (child_uris, (GFunc)g_free, NULL);
g_slist_free (child_uris);
if (common_prefix)
{
gint total_len;
gint file_part_len;
gint common_prefix_len;
gint pos;
total_len = g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (chooser_entry)), -1);
file_part_len = g_utf8_strlen (chooser_entry->file_part, -1);
common_prefix_len = g_utf8_strlen (common_prefix, -1);
if (common_prefix_len > file_part_len)
{
chooser_entry->in_change = TRUE;
pos = total_len - file_part_len;
gtk_editable_delete_text (editable,
pos, -1);
gtk_editable_insert_text (editable,
common_prefix, -1,
&pos);
gtk_editable_select_region (editable,
total_len,
total_len - file_part_len + common_prefix_len);
chooser_entry->in_change = FALSE;
chooser_entry->has_completion = TRUE;
}
g_free (common_prefix);
}
return FALSE;
}
static void
gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
const gchar *new_text,
gint new_text_length,
gint *position)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
parent_editable_iface->do_insert_text (editable, new_text, new_text_length, position);
if (!chooser_entry->in_change &&
*position == GTK_ENTRY (editable)->text_length &&
!chooser_entry->completion_idle)
{
chooser_entry->completion_idle = g_idle_source_new ();
g_source_set_priority (chooser_entry->completion_idle, G_PRIORITY_HIGH);
g_source_set_closure (chooser_entry->completion_idle,
g_cclosure_new_object (G_CALLBACK (completion_idle_callback),
G_OBJECT (chooser_entry)));
g_source_attach (chooser_entry->completion_idle, NULL);
}
}
static gboolean
gtk_file_chooser_entry_focus (GtkWidget *widget,
GtkDirectionType direction)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
if (direction == GTK_DIR_TAB_FORWARD &&
GTK_WIDGET_HAS_FOCUS (widget) &&
chooser_entry->has_completion)
{
gtk_editable_set_position (GTK_EDITABLE (widget),
GTK_ENTRY (widget)->text_length);
return TRUE;
}
else
return GTK_WIDGET_CLASS (parent_class)->focus (widget, direction);
}
static void
gtk_file_chooser_entry_changed (GtkEditable *editable)
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
const gchar *text;
gchar *folder_uri;
gchar *file_part;
text = gtk_entry_get_text (GTK_ENTRY (editable));
if (!chooser_entry->file_system ||
!chooser_entry->base_folder ||
!gtk_file_system_parse (chooser_entry->file_system,
chooser_entry->base_folder, text,
&folder_uri, &file_part, NULL)) /* NULL-GError */
{
folder_uri = g_strdup (chooser_entry->base_folder);
file_part = g_strdup ("");
}
if (chooser_entry->current_folder_uri &&
strcmp (folder_uri, chooser_entry->current_folder_uri) != 0)
{
if (chooser_entry->current_folder_uri)
g_free (chooser_entry->current_folder_uri);
if (chooser_entry->current_folder)
{
g_object_unref (chooser_entry->current_folder);
chooser_entry->current_folder = NULL;
}
}
chooser_entry->current_folder_uri = folder_uri;
if (chooser_entry->file_part)
g_free (chooser_entry->file_part);
chooser_entry->file_part = file_part;
}
static void
clear_completion_callback (GtkFileChooserEntry *chooser_entry,
GParamSpec *pspec)
{
chooser_entry->has_completion = FALSE;
}
/**
* _gtk_file_chooser_entry_new:
*
* Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
* is an internal implementation widget for the GTK+ file chooser
* which is an entry with completion with respect to a
* #GtkFileSystem object.
*
* Return value: the newly created #GtkFileChooserEntry
**/
GtkWidget *
_gtk_file_chooser_entry_new (void)
{
return g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
}
/**
* _gtk_file_chooser_entry_set_file_system:
* @chooser_entry: a #GtkFileChooser
* @file_system: an object implementing #GtkFileSystem
*
* Sets the file system for @chooser_entry.
**/
void
_gtk_file_chooser_entry_set_file_system (GtkFileChooserEntry *chooser_entry,
GtkFileSystem *file_system)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
g_return_if_fail (GTK_IS_FILE_SYSTEM (file_system));
if (file_system != chooser_entry->file_system)
{
if (chooser_entry->file_system)
g_object_unref (chooser_entry->file_system);
chooser_entry->file_system = g_object_ref (file_system);
}
}
/**
* _gtk_file_chooser_entry_set_base_folder:
* @chooser_entry: a #GtkFileChooserEntry
* @uri: URI of a folder in the chooser entries current file system.
*
* Sets the folder with respect to which completions occur.
**/
void
_gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
const gchar *uri)
{
if (chooser_entry->base_folder)
g_free (chooser_entry->base_folder);
chooser_entry->base_folder = g_strdup (uri);
}
/**
* _gtk_file_chooser_entry_get_current_folder:
* @chooser_entry: a #GtkFileChooserEntry
*
* Gets the current folder for the #GtkFileChooserEntry. If the
* user has only entered a filename, this will be the base folder
* (see _gtk_file_chooser_entry_set_base_folder()), but if the
* user has entered a relative or absolute path, then it will
* be different. If the user has entered a relative or absolute
* path that doesn't point to a folder in the file system, it will
* be %NULL.
*
* Return value: the URI of current folder - this value is owned by the
* chooser entry and must not be modified or freed.
**/
const gchar *
_gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
{
return chooser_entry->current_folder_uri;
}
/**
* _gtk_file_chooser_entry_get_file_part:
* @chooser_entry: a #GtkFileChooserEntry