#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkentry.h"
+#include "gtkfilesystemmodel.h"
#include "gtklabel.h"
#include "gtkmain.h"
#include "gtksizerequest.h"
GtkFileChooserAction action;
- GtkFileSystem *file_system;
GFile *base_folder;
GFile *current_folder_file;
+ gchar *dir_part;
gchar *file_part;
gint file_part_pos;
- /* Folder being loaded or already loaded */
- GtkFolder *current_folder;
- GCancellable *load_folder_cancellable;
-
LoadCompleteAction load_complete_action;
- GtkListStore *completion_store;
-
- guint start_autocompletion_idle_id;
+ GtkTreeModel *completion_store;
GtkWidget *completion_feedback_window;
GtkWidget *completion_feedback_label;
enum
{
DISPLAY_NAME_COLUMN,
+ FULL_PATH_COLUMN,
FILE_COLUMN,
N_COLUMNS
};
const char *key,
GtkTreeIter *iter,
gpointer data);
-static char *maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry,
- GFile *file,
- gchar *display_name,
- gboolean *appended);
typedef enum {
REFRESH_UP_TO_CURSOR_POSITION,
static RefreshStatus refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
RefreshMode refresh_mode);
-static void finished_loading_cb (GtkFolder *folder,
- gpointer data);
+static void finished_loading_cb (GtkFileSystemModel *model,
+ GError *error,
+ GtkFileChooserEntry *chooser_entry);
static void autocomplete (GtkFileChooserEntry *chooser_entry);
-static void install_start_autocompletion_idle (GtkFileChooserEntry *chooser_entry);
+static void start_autocompletion (GtkFileChooserEntry *chooser_entry);
static void remove_completion_feedback (GtkFileChooserEntry *chooser_entry);
static void pop_up_completion_feedback (GtkFileChooserEntry *chooser_entry,
const gchar *feedback);
GtkCellRenderer *cell;
chooser_entry->local_only = TRUE;
+ chooser_entry->base_folder = g_file_new_for_path (g_get_home_dir ());
g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
{
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
- if (chooser_entry->base_folder)
- g_object_unref (chooser_entry->base_folder);
-
- if (chooser_entry->current_folder)
- g_object_unref (chooser_entry->current_folder);
+ g_object_unref (chooser_entry->base_folder);
if (chooser_entry->current_folder_file)
g_object_unref (chooser_entry->current_folder_file);
+ g_free (chooser_entry->dir_part);
g_free (chooser_entry->file_part);
G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
static void
discard_loading_and_current_folder_file (GtkFileChooserEntry *chooser_entry)
{
- if (chooser_entry->current_folder)
- {
- g_signal_handlers_disconnect_by_func (chooser_entry->current_folder,
- G_CALLBACK (finished_loading_cb), chooser_entry);
- g_object_unref (chooser_entry->current_folder);
- chooser_entry->current_folder = NULL;
- }
- if (chooser_entry->load_folder_cancellable)
- {
- g_cancellable_cancel (chooser_entry->load_folder_cancellable);
- chooser_entry->load_folder_cancellable = NULL;
- }
-
if (chooser_entry->current_folder_file)
{
g_object_unref (chooser_entry->current_folder_file);
remove_completion_feedback (chooser_entry);
discard_loading_and_current_folder_file (chooser_entry);
- if (chooser_entry->start_autocompletion_idle_id != 0)
- {
- g_source_remove (chooser_entry->start_autocompletion_idle_id);
- chooser_entry->start_autocompletion_idle_id = 0;
- }
-
if (chooser_entry->completion_store)
{
g_object_unref (chooser_entry->completion_store);
chooser_entry->completion_store = NULL;
}
- if (chooser_entry->file_system)
- {
- g_object_unref (chooser_entry->file_system);
- chooser_entry->file_system = NULL;
- }
-
G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
}
char *display_name;
GFile *file;
gint pos;
- gboolean dummy;
gtk_tree_model_get (model, iter,
DISPLAY_NAME_COLUMN, &display_name,
return FALSE;
}
- display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy);
-
pos = chooser_entry->file_part_pos;
/* We don't set in_change here as we want to update the current_folder
return FALSE;
}
- gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store), iter, DISPLAY_NAME_COLUMN, &name, -1);
+ gtk_tree_model_get (chooser_entry->completion_store, iter, DISPLAY_NAME_COLUMN, &name, -1);
if (!name)
{
return FALSE; /* Uninitialized row, ugh */
gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
}
-/* This function will append a directory separator to paths to
- * display_name iff the path associated with it is a directory.
- * maybe_append_separator_to_file will g_free the display_name and
- * return a new one if needed. Otherwise, it will return the old one.
- * You should be safe calling
- *
- * display_name = maybe_append_separator_to_file (entry, file, display_name, &appended);
- * ...
- * g_free (display_name);
- */
-static char *
-maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry,
- GFile *file,
- gchar *display_name,
- gboolean *appended)
+static gboolean
+is_valid_scheme_character (char c)
{
- *appended = FALSE;
+ return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
+}
- if (!g_str_has_suffix (display_name, G_DIR_SEPARATOR_S) && file)
- {
- GFileInfo *info;
+static gboolean
+has_uri_scheme (const char *str)
+{
+ const char *p;
- info = _gtk_folder_get_info (chooser_entry->current_folder, file);
+ p = str;
- if (info)
- {
- if (_gtk_file_info_consider_as_directory (info))
- {
- gchar *tmp = display_name;
- display_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL);
- *appended = TRUE;
- g_free (tmp);
- }
+ if (!is_valid_scheme_character (*p))
+ return FALSE;
- g_object_unref (info);
- }
- }
+ do
+ p++;
+ while (is_valid_scheme_character (*p));
+
+ return (strncmp (p, "://", 3) == 0);
+}
+
+static GFile *
+gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
+ const gchar *str)
+{
+ GFile *file;
+
+ if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
+ file = g_file_parse_name (str);
+ else
+ file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
+
+ return file;
+}
- return display_name;
+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 char *
-trim_dir_separator_suffix (const char *str)
+static gboolean
+gtk_file_chooser_entry_parse (GtkFileChooserEntry *chooser_entry,
+ const gchar *str,
+ GFile **folder,
+ gchar **file_part,
+ GError **error)
{
- int len;
+ GFile *file;
+ gboolean result = FALSE;
+ gboolean is_dir = FALSE;
+ gchar *last_slash = NULL;
+
+ if (str && *str)
+ is_dir = (str [strlen (str) - 1] == G_DIR_SEPARATOR);
+
+ last_slash = strrchr (str, G_DIR_SEPARATOR);
- len = strlen (str);
- if (len > 0 && G_IS_DIR_SEPARATOR (str[len - 1]))
- return g_strndup (str, len - 1);
+ file = gtk_file_chooser_get_file_for_text (chooser_entry, str);
+
+ if (g_file_equal (chooser_entry->base_folder, file))
+ {
+ /* this is when user types '.', could be the
+ * beginning of a hidden file, ./ or ../
+ */
+ *folder = g_object_ref (file);
+ *file_part = g_strdup (str);
+ result = TRUE;
+ }
+ else if (is_dir)
+ {
+ /* it's a dir, or at least it ends with the dir separator */
+ *folder = g_object_ref (file);
+ *file_part = g_strdup ("");
+ result = TRUE;
+ }
else
- return g_strdup (str);
+ {
+ GFile *parent_file;
+
+ parent_file = g_file_get_parent (file);
+
+ if (!parent_file)
+ {
+ g_set_error (error,
+ GTK_FILE_CHOOSER_ERROR,
+ GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
+ "Could not get parent file");
+ *folder = NULL;
+ *file_part = NULL;
+ }
+ else
+ {
+ *folder = parent_file;
+ result = TRUE;
+
+ if (last_slash)
+ *file_part = g_strdup (last_slash + 1);
+ else
+ *file_part = g_strdup (str);
+ }
+ }
+
+ g_object_unref (file);
+
+ return result;
}
/* Determines if the completion model has entries with a common prefix relative
text_up_to_cursor = gtk_editable_get_chars (editable, 0, gtk_editable_get_position (editable));
- parsed = _gtk_file_system_parse (chooser_entry->file_system,
- chooser_entry->base_folder,
- text_up_to_cursor,
- &parsed_folder_file,
- &parsed_file_part,
- error);
+ parsed = gtk_file_chooser_entry_parse (chooser_entry,
+ text_up_to_cursor,
+ &parsed_folder_file,
+ &parsed_file_part,
+ error);
g_free (text_up_to_cursor);
return FALSE;
g_assert (parsed_folder_file != NULL
- && chooser_entry->current_folder != NULL
&& g_file_equal (parsed_folder_file, chooser_entry->current_folder_file));
g_object_unref (parsed_folder_file);
/* First pass: find the common prefix */
- valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+ valid = gtk_tree_model_get_iter_first (chooser_entry->completion_store, &iter);
while (valid)
{
gchar *display_name;
GFile *file;
- gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store),
+ gtk_tree_model_get (chooser_entry->completion_store,
&iter,
DISPLAY_NAME_COLUMN, &display_name,
FILE_COLUMN, &file,
{
if (!*common_prefix_ret)
{
- *common_prefix_ret = trim_dir_separator_suffix (display_name);
+ *common_prefix_ret = g_strdup (display_name);
*unique_file_ret = g_object_ref (file);
}
else
g_free (display_name);
g_object_unref (file);
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+ valid = gtk_tree_model_iter_next (chooser_entry->completion_store, &iter);
}
/* Second pass: see if the prefix we found is a complete match */
if (*common_prefix_ret != NULL)
{
- valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+ valid = gtk_tree_model_get_iter_first (chooser_entry->completion_store, &iter);
while (valid)
{
gchar *display_name;
int len;
- gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store),
+ gtk_tree_model_get (chooser_entry->completion_store,
&iter,
DISPLAY_NAME_COLUMN, &display_name,
-1);
*is_complete_not_unique_ret = TRUE;
g_free (display_name);
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+ valid = gtk_tree_model_iter_next (chooser_entry->completion_store, &iter);
}
/* Finally: Did we generate a new completion, or was the user's input already completed as far as it could go? */
return TRUE;
}
-static gboolean
-char_after_cursor_is_directory_separator (GtkFileChooserEntry *chooser_entry)
-{
- int cursor_pos;
- gboolean result;
-
- result = FALSE;
-
- cursor_pos = gtk_editable_get_position (GTK_EDITABLE (chooser_entry));
- if (cursor_pos < gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)))
- {
- char *next_char_str;
-
- next_char_str = gtk_editable_get_chars (GTK_EDITABLE (chooser_entry), cursor_pos, cursor_pos + 1);
- if (G_IS_DIR_SEPARATOR (*next_char_str))
- result = TRUE;
-
- g_free (next_char_str);
- }
-
- return result;
-}
-
typedef enum {
INVALID_INPUT, /* what the user typed is bogus */
NO_MATCH, /* no matches based on what the user typed */
error = NULL;
if (!find_common_prefix (chooser_entry, &common_prefix, &unique_file, &is_complete_not_unique, &prefix_expands_the_file_part, &error))
{
- /* If the user types an incomplete hostname ("http://foo" without
- * a slash after that), it's not an error. We just don't want to
- * pop up a meaningless completion window in that state.
- */
- if (!g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_INCOMPLETE_HOSTNAME)
- && show_errors)
- {
- beep (chooser_entry);
- pop_up_completion_feedback (chooser_entry, _("Invalid path"));
- }
-
g_error_free (error);
return INVALID_INPUT;
if (unique_file)
{
- if (!char_after_cursor_is_directory_separator (chooser_entry))
- {
- gboolean appended;
-
- common_prefix = maybe_append_separator_to_file (chooser_entry,
- unique_file,
- common_prefix,
- &appended);
- if (appended)
- prefix_expands_the_file_part = TRUE;
- }
-
g_object_unref (unique_file);
if (prefix_expands_the_file_part)
if ((chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN
|| chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
&& insert_pos == old_text_len)
- install_start_autocompletion_idle (chooser_entry);
+ start_autocompletion (chooser_entry);
}
static void
{
CommonPrefixResult result;
- g_assert (chooser_entry->current_folder != NULL);
g_assert (chooser_entry->current_folder_loaded);
/* FIXME: see what Emacs does in case there is no common prefix, or there is more than one match:
case REFRESH_OK:
g_assert (chooser_entry->current_folder_file != NULL);
- if (chooser_entry->current_folder && chooser_entry->current_folder_loaded)
+ if (chooser_entry->current_folder_loaded)
explicitly_complete (chooser_entry);
else
{
chooser_entry->completion_store = NULL;
}
-/* Fills the completion store from the contents of the current folder */
-static void
-populate_completion_store (GtkFileChooserEntry *chooser_entry)
+static gboolean
+completion_store_set (GtkFileSystemModel *model,
+ GFile *file,
+ GFileInfo *info,
+ int column,
+ GValue *value,
+ gpointer data)
{
- GSList *files;
- GSList *tmp_list;
-
- discard_completion_store (chooser_entry);
-
- files = _gtk_folder_list_children (chooser_entry->current_folder);
+ GtkFileChooserEntry *chooser_entry = data;
- chooser_entry->completion_store = gtk_list_store_new (N_COLUMNS,
- G_TYPE_STRING,
- G_TYPE_FILE);
+ const char *prefix = "";
+ const char *suffix = "";
- for (tmp_list = files; tmp_list; tmp_list = tmp_list->next)
+ switch (column)
{
- GFileInfo *info;
- GFile *file;
-
- file = tmp_list->data;
-
- info = _gtk_folder_get_info (chooser_entry->current_folder, file);
-
- if (info)
- {
- gchar *display_name = g_strdup (g_file_info_get_display_name (info));
- GtkTreeIter iter;
- gboolean dummy;
-
- display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy);
+ case FILE_COLUMN:
+ g_value_set_object (value, file);
+ break;
+ case FULL_PATH_COLUMN:
+ prefix = chooser_entry->dir_part;
+ /* fall through */
+ case DISPLAY_NAME_COLUMN:
+ if (_gtk_file_info_consider_as_directory (info))
+ suffix = G_DIR_SEPARATOR_S;
+
+ g_value_take_string (value, g_strconcat (
+ prefix,
+ g_file_info_get_display_name (info),
+ suffix,
+ NULL));
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
- gtk_list_store_append (chooser_entry->completion_store, &iter);
- gtk_list_store_set (chooser_entry->completion_store, &iter,
- DISPLAY_NAME_COLUMN, display_name,
- FILE_COLUMN, file,
- -1);
+ return TRUE;
+}
- g_object_unref (info);
- g_free (display_name);
- }
- }
+/* Fills the completion store from the contents of the current folder */
+static void
+populate_completion_store (GtkFileChooserEntry *chooser_entry)
+{
+ discard_completion_store (chooser_entry);
- g_slist_foreach (files, (GFunc) g_object_unref, NULL);
- g_slist_free (files);
+ chooser_entry->completion_store = GTK_TREE_MODEL (
+ _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
+ "standard::name,standard::display-name,standard::type",
+ completion_store_set,
+ chooser_entry,
+ N_COLUMNS,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_FILE));
+ g_signal_connect (chooser_entry->completion_store, "finished-loading",
+ G_CALLBACK (finished_loading_cb), chooser_entry);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
- GTK_TREE_MODEL (chooser_entry->completion_store));
+ chooser_entry->completion_store);
}
/* When we finish loading the current folder, this function should get called to
static void
finish_folder_load (GtkFileChooserEntry *chooser_entry)
{
- populate_completion_store (chooser_entry);
perform_load_complete_action (chooser_entry);
gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
/* Callback when the current folder finishes loading */
static void
-finished_loading_cb (GtkFolder *folder,
- gpointer data)
+finished_loading_cb (GtkFileSystemModel *model,
+ GError *error,
+ GtkFileChooserEntry *chooser_entry)
{
- GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
-
chooser_entry->current_folder_loaded = TRUE;
- finish_folder_load (chooser_entry);
-}
-
-/* Callback when the current folder's handle gets obtained (not necessarily loaded completely) */
-static void
-load_directory_get_folder_callback (GCancellable *cancellable,
- GtkFolder *folder,
- const GError *error,
- gpointer data)
-{
- gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GtkFileChooserEntry *chooser_entry = data;
-
- if (cancellable != chooser_entry->load_folder_cancellable)
- goto out;
-
- chooser_entry->load_folder_cancellable = NULL;
if (error)
{
beep (chooser_entry);
pop_up_completion_feedback (chooser_entry, error->message);
}
- }
-
- if (cancelled || error)
- goto out;
-
- g_assert (folder != NULL);
- chooser_entry->current_folder = g_object_ref (folder);
-
- discard_completion_store (chooser_entry);
-
- chooser_entry->current_folder_loaded = _gtk_folder_is_finished_loading (chooser_entry->current_folder);
- if (chooser_entry->current_folder_loaded)
- finish_folder_load (chooser_entry);
- else
- g_signal_connect (chooser_entry->current_folder, "finished-loading",
- G_CALLBACK (finished_loading_cb), chooser_entry);
-
-out:
- g_object_unref (chooser_entry);
- g_object_unref (cancellable);
-}
-
-static RefreshStatus
-start_loading_current_folder (GtkFileChooserEntry *chooser_entry)
-{
- g_assert (chooser_entry->current_folder_file != NULL);
- g_assert (chooser_entry->current_folder == NULL);
- g_assert (chooser_entry->load_folder_cancellable == NULL);
- if (chooser_entry->local_only
- && !g_file_is_native (chooser_entry->current_folder_file))
- {
- discard_loading_and_current_folder_file (chooser_entry);
-
- return REFRESH_NOT_LOCAL;
+ return;
}
- chooser_entry->load_folder_cancellable =
- _gtk_file_system_get_folder (chooser_entry->file_system,
- chooser_entry->current_folder_file,
- "standard::name,standard::display-name,standard::type",
- load_directory_get_folder_callback,
- g_object_ref (chooser_entry));
-
- return REFRESH_OK;
+ finish_folder_load (chooser_entry);
}
static RefreshStatus
g_assert (folder_file != NULL);
if (chooser_entry->current_folder_file
- && g_file_equal (folder_file, chooser_entry->current_folder_file)
- && chooser_entry->load_folder_cancellable)
+ && g_file_equal (folder_file, chooser_entry->current_folder_file))
return REFRESH_OK;
if (chooser_entry->current_folder_file)
discard_loading_and_current_folder_file (chooser_entry);
}
+ if (chooser_entry->local_only
+ && !g_file_is_native (folder_file))
+ return REFRESH_NOT_LOCAL;
+
chooser_entry->current_folder_file = g_object_ref (folder_file);
+ chooser_entry->current_folder_loaded = FALSE;
+
+ populate_completion_store (chooser_entry);
- return start_loading_current_folder (chooser_entry);
+ return REFRESH_OK;
}
static RefreshStatus
text = gtk_editable_get_chars (editable, 0, end_pos);
error = NULL;
- if (!_gtk_file_system_parse (chooser_entry->file_system,
- chooser_entry->base_folder, text,
- &folder_file, &file_part, &error))
+ if (!gtk_file_chooser_entry_parse (chooser_entry,
+ text, &folder_file, &file_part, &error))
{
- if (g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_INCOMPLETE_HOSTNAME))
- {
- folder_file = NULL;
- result = REFRESH_INCOMPLETE_HOSTNAME;
- }
- else
- {
- folder_file = (chooser_entry->base_folder) ? g_object_ref (chooser_entry->base_folder) : NULL;
+ folder_file = g_object_ref (chooser_entry->base_folder);
- if (g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_NONEXISTENT))
- result = REFRESH_NONEXISTENT;
- else
- result = REFRESH_INVALID_INPUT;
- }
+ if (g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_NONEXISTENT))
+ result = REFRESH_NONEXISTENT;
+ else
+ result = REFRESH_INVALID_INPUT;
if (error)
g_error_free (error);
result = REFRESH_OK;
}
- g_free (text);
-
g_free (chooser_entry->file_part);
+ g_free (chooser_entry->dir_part);
+ chooser_entry->dir_part = file_part_pos > 0 ? g_strndup (text, file_part_pos) : g_strdup ("");
chooser_entry->file_part = file_part;
chooser_entry->file_part_pos = file_part_pos;
+ g_free (text);
+
if (result == REFRESH_OK)
{
result = reload_current_folder (chooser_entry, folder_file);
g_assert (/* we are OK and we have a current folder file and (loading process or folder handle)... */
((result == REFRESH_OK)
- && (chooser_entry->current_folder_file != NULL)
- && (((chooser_entry->load_folder_cancellable != NULL) && (chooser_entry->current_folder == NULL))
- || ((chooser_entry->load_folder_cancellable == NULL) && (chooser_entry->current_folder != NULL))))
+ && (chooser_entry->current_folder_file != NULL))
/* ... OR we have an error, and we don't have a current folder file nor a loading process nor a folder handle */
|| ((result != REFRESH_OK)
- && (chooser_entry->current_folder_file == NULL)
- && (chooser_entry->load_folder_cancellable == NULL)
- && (chooser_entry->current_folder == NULL)));
+ && (chooser_entry->current_folder_file == NULL)));
return result;
}
static void
autocomplete (GtkFileChooserEntry *chooser_entry)
{
- if (!(chooser_entry->current_folder != NULL
- && chooser_entry->current_folder_loaded
+ if (!(chooser_entry->current_folder_loaded
&& gtk_editable_get_position (GTK_EDITABLE (chooser_entry)) == gtk_entry_get_text_length (GTK_ENTRY (chooser_entry))))
return;
case REFRESH_OK:
g_assert (chooser_entry->current_folder_file != NULL);
- if (chooser_entry->current_folder && chooser_entry->current_folder_loaded)
+ if (chooser_entry->current_folder_loaded)
autocomplete (chooser_entry);
else
chooser_entry->load_complete_action = LOAD_COMPLETE_AUTOCOMPLETE;
}
}
-static gboolean
-start_autocompletion_idle_handler (gpointer data)
-{
- GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
-
- start_autocompletion (chooser_entry);
-
- chooser_entry->start_autocompletion_idle_id = 0;
-
- return FALSE;
-}
-
-static void
-install_start_autocompletion_idle (GtkFileChooserEntry *chooser_entry)
-{
- if (chooser_entry->start_autocompletion_idle_id != 0)
- return;
-
- chooser_entry->start_autocompletion_idle_id = gdk_threads_add_idle (start_autocompletion_idle_handler, chooser_entry);
-}
-
#ifdef G_OS_WIN32
static gint
insert_text_callback (GtkFileChooserEntry *chooser_entry,
/**
* _gtk_file_chooser_entry_new:
- * @filesystem: The #GtkFileSystem to use
* @eat_tabs: If %FALSE, allow focus navigation with the tab key.
*
* Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
* Return value: the newly created #GtkFileChooserEntry
**/
GtkWidget *
-_gtk_file_chooser_entry_new (GtkFileSystem *file_system,
- gboolean eat_tabs)
+_gtk_file_chooser_entry_new (gboolean eat_tabs)
{
GtkFileChooserEntry *chooser_entry;
- g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
-
chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
- chooser_entry->file_system = g_object_ref (file_system);
chooser_entry->eat_tabs = (eat_tabs != FALSE);
return GTK_WIDGET (chooser_entry);
_gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
GFile *file)
{
+ if (file)
+ g_object_ref (file);
+ else
+ file = g_file_new_for_path (g_get_home_dir ());
+
+ if (g_file_equal (chooser_entry->base_folder, file))
+ {
+ g_object_unref (file);
+ return;
+ }
+
if (chooser_entry->base_folder)
g_object_unref (chooser_entry->base_folder);
chooser_entry->base_folder = file;
- if (chooser_entry->base_folder)
- g_object_ref (chooser_entry->base_folder);
-
clear_completions (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)));
}
/**
const gchar *
_gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
{
- commit_completion_and_refresh (chooser_entry);
- return chooser_entry->file_part;
+ const char *last_slash, *text;
+
+ g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
+
+ text = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
+ last_slash = strrchr (text, G_DIR_SEPARATOR);
+ if (last_slash)
+ return last_slash + 1;
+ else
+ return text;
}
/**
_gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
GFile *file)
{
- gboolean retval = FALSE;
-
- if (chooser_entry->current_folder)
- {
- GFileInfo *file_info;
+ GtkTreeIter iter;
+ GFileInfo *info;
- file_info = _gtk_folder_get_info (chooser_entry->current_folder, file);
+ if (chooser_entry->completion_store == NULL ||
+ !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
+ &iter,
+ file))
+ return FALSE;
- if (file_info)
- {
- retval = _gtk_file_info_consider_as_directory (file_info);
- g_object_unref (file_info);
- }
- }
+ info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
+ &iter);
- return retval;
+ return _gtk_file_info_consider_as_directory (info);
}