1 /* GTK - The GIMP Toolkit
2 * gtkfilechooserentry.c: Entry with filename completion
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gtkfilechooserentry.h"
27 #include "gtkcelllayout.h"
28 #include "gtkcellrenderertext.h"
30 #include "gtkfilesystemmodel.h"
33 #include "gtksizerequest.h"
34 #include "gtkwindow.h"
37 typedef struct _GtkFileChooserEntryClass GtkFileChooserEntryClass;
39 #define GTK_FILE_CHOOSER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_ENTRY, GtkFileChooserEntryClass))
40 #define GTK_IS_FILE_CHOOSER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_ENTRY))
41 #define GTK_FILE_CHOOSER_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_ENTRY, GtkFileChooserEntryClass))
43 struct _GtkFileChooserEntryClass
45 GtkEntryClass parent_class;
48 /* Action to take when the current folder finishes loading (for explicit or automatic completion) */
50 LOAD_COMPLETE_NOTHING,
51 LOAD_COMPLETE_EXPLICIT_COMPLETION
54 struct _GtkFileChooserEntry
56 GtkEntry parent_instance;
58 GtkFileChooserAction action;
61 GFile *current_folder_file;
65 LoadCompleteAction load_complete_action;
67 GtkTreeModel *completion_store;
69 guint current_folder_loaded : 1;
81 static void gtk_file_chooser_entry_finalize (GObject *object);
82 static void gtk_file_chooser_entry_dispose (GObject *object);
83 static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
84 static gboolean gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
86 static gboolean gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
87 GdkEventFocus *event);
90 static gint insert_text_callback (GtkFileChooserEntry *widget,
91 const gchar *new_text,
95 static void delete_text_callback (GtkFileChooserEntry *widget,
101 static gboolean match_selected_callback (GtkEntryCompletion *completion,
104 GtkFileChooserEntry *chooser_entry);
105 static gboolean completion_match_func (GtkEntryCompletion *comp,
110 static void refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry);
111 static void set_completion_folder (GtkFileChooserEntry *chooser_entry,
113 static void finished_loading_cb (GtkFileSystemModel *model,
115 GtkFileChooserEntry *chooser_entry);
117 G_DEFINE_TYPE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY)
120 gtk_file_chooser_entry_get_completion_text (GtkFileChooserEntry *chooser_entry)
122 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
125 gtk_editable_get_selection_bounds (editable, &start, &end);
126 return gtk_editable_get_chars (editable, 0, MIN (start, end));
130 gtk_file_chooser_entry_dispatch_properties_changed (GObject *object,
134 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
137 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
139 /* What we are after: The text in front of the cursor was modified.
140 * Unfortunately, there's no other way to catch this. */
142 for (i = 0; i < n_pspecs; i++)
144 if (pspecs[i]->name == I_("cursor-position") ||
145 pspecs[i]->name == I_("selection-bound") ||
146 pspecs[i]->name == I_("text"))
148 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
150 refresh_current_folder_and_file_part (chooser_entry);
158 _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
160 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
161 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
163 gobject_class->finalize = gtk_file_chooser_entry_finalize;
164 gobject_class->dispose = gtk_file_chooser_entry_dispose;
165 gobject_class->dispatch_properties_changed = gtk_file_chooser_entry_dispatch_properties_changed;
167 widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
168 widget_class->key_press_event = gtk_file_chooser_entry_key_press_event;
169 widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
173 _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
175 GtkEntryCompletion *comp;
176 GtkCellRenderer *cell;
178 chooser_entry->local_only = TRUE;
179 chooser_entry->base_folder = g_file_new_for_path (g_get_home_dir ());
181 g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
183 comp = gtk_entry_completion_new ();
184 gtk_entry_completion_set_popup_single_match (comp, FALSE);
185 gtk_entry_completion_set_minimum_key_length (comp, 0);
186 /* see docs for gtk_entry_completion_set_text_column() */
187 g_object_set (comp, "text-column", FULL_PATH_COLUMN, NULL);
189 gtk_entry_completion_set_match_func (comp,
190 completion_match_func,
194 cell = gtk_cell_renderer_text_new ();
195 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp),
197 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
199 "text", DISPLAY_NAME_COLUMN);
201 g_signal_connect (comp, "match-selected",
202 G_CALLBACK (match_selected_callback), chooser_entry);
204 gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp);
205 g_object_unref (comp);
208 g_signal_connect (chooser_entry, "insert-text",
209 G_CALLBACK (insert_text_callback), NULL);
210 g_signal_connect (chooser_entry, "delete-text",
211 G_CALLBACK (delete_text_callback), NULL);
216 gtk_file_chooser_entry_finalize (GObject *object)
218 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
220 g_object_unref (chooser_entry->base_folder);
222 if (chooser_entry->current_folder_file)
223 g_object_unref (chooser_entry->current_folder_file);
225 g_free (chooser_entry->dir_part);
226 g_free (chooser_entry->file_part);
228 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
232 gtk_file_chooser_entry_dispose (GObject *object)
234 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
236 set_completion_folder (chooser_entry, NULL);
238 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
241 /* Match functions for the GtkEntryCompletion */
243 match_selected_callback (GtkEntryCompletion *completion,
246 GtkFileChooserEntry *chooser_entry)
250 gtk_tree_model_get (model, iter,
251 FULL_PATH_COLUMN, &path,
254 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
256 gtk_editable_get_position (GTK_EDITABLE (chooser_entry)));
257 gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
267 /* Match function for the GtkEntryCompletion */
269 completion_match_func (GtkEntryCompletion *comp,
270 const char *key_unused,
274 GtkFileChooserEntry *chooser_entry;
277 char *norm_file_part;
280 chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
282 /* We ignore the key because it is the contents of the entry. Instead, we
283 * just use our precomputed file_part.
285 if (!chooser_entry->file_part)
290 gtk_tree_model_get (chooser_entry->completion_store, iter, DISPLAY_NAME_COLUMN, &name, -1);
293 return FALSE; /* Uninitialized row, ugh */
296 /* If we have an empty file_part, then we're at the root of a directory. In
297 * that case, we want to match all non-dot files. We might want to match
298 * dot_files too if show_hidden is TRUE on the fileselector in the future.
300 /* Additionally, support for gnome .hidden files would be sweet, too */
301 if (chooser_entry->file_part[0] == '\000')
313 norm_file_part = g_utf8_normalize (chooser_entry->file_part, -1, G_NORMALIZE_ALL);
314 norm_name = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
316 #ifdef G_PLATFORM_WIN32
320 temp = norm_file_part;
321 norm_file_part = g_utf8_casefold (norm_file_part, -1);
325 norm_name = g_utf8_casefold (norm_name, -1);
330 result = (strncmp (norm_file_part, norm_name, strlen (norm_file_part)) == 0);
332 g_free (norm_file_part);
340 clear_completions (GtkFileChooserEntry *chooser_entry)
342 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
346 beep (GtkFileChooserEntry *chooser_entry)
348 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
352 is_valid_scheme_character (char c)
354 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
358 has_uri_scheme (const char *str)
364 if (!is_valid_scheme_character (*p))
369 while (is_valid_scheme_character (*p));
371 return (strncmp (p, "://", 3) == 0);
375 gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
380 if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
381 file = g_file_parse_name (str);
383 file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
389 gtk_file_chooser_get_directory_for_text (GtkFileChooserEntry *chooser_entry,
392 GFile *file, *parent;
394 file = gtk_file_chooser_get_file_for_text (chooser_entry, text);
396 if (text[0] == 0 || text[strlen (text) - 1] == G_DIR_SEPARATOR)
399 parent = g_file_get_parent (file);
400 g_object_unref (file);
405 /* Finds a common prefix based on the contents of the entry
406 * and mandatorily appends it
409 explicitly_complete (GtkFileChooserEntry *chooser_entry)
411 clear_completions (chooser_entry);
413 if (chooser_entry->completion_store)
415 char *completion, *text;
416 gsize completion_len, text_len;
418 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
419 text_len = strlen (text);
420 completion = gtk_entry_completion_compute_prefix (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), text);
421 completion_len = completion ? strlen (completion) : 0;
423 if (completion_len > text_len)
425 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
426 int pos = gtk_editable_get_position (editable);
428 gtk_editable_insert_text (editable,
429 completion + text_len,
430 completion_len - text_len,
432 gtk_editable_set_position (editable, pos);
437 beep (chooser_entry);
441 gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
443 GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
444 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
448 start_explicit_completion (GtkFileChooserEntry *chooser_entry)
450 if (chooser_entry->current_folder_loaded)
451 explicitly_complete (chooser_entry);
453 chooser_entry->load_complete_action = LOAD_COMPLETE_EXPLICIT_COMPLETION;
457 gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
460 GtkFileChooserEntry *chooser_entry;
461 GtkEditable *editable;
462 GdkModifierType state;
463 gboolean control_pressed;
465 chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
466 editable = GTK_EDITABLE (widget);
468 if (!chooser_entry->eat_tabs)
469 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
471 control_pressed = FALSE;
473 if (gtk_get_current_event_state (&state))
475 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
476 control_pressed = TRUE;
479 /* This is a bit evil -- it makes Tab never leave the entry. It basically
480 * makes it 'safe' for people to hit. */
481 if (event->keyval == GDK_KEY_Tab && !control_pressed)
485 gtk_editable_get_selection_bounds (editable, &start, &end);
488 gtk_editable_set_position (editable, MAX (start, end));
490 start_explicit_completion (chooser_entry);
495 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
500 gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
501 GdkEventFocus *event)
503 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
505 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
507 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->focus_out_event (widget, event);
511 discard_completion_store (GtkFileChooserEntry *chooser_entry)
513 if (!chooser_entry->completion_store)
516 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
517 gtk_entry_completion_set_inline_completion (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), FALSE);
518 g_object_unref (chooser_entry->completion_store);
519 chooser_entry->completion_store = NULL;
523 completion_store_set (GtkFileSystemModel *model,
530 GtkFileChooserEntry *chooser_entry = data;
532 const char *prefix = "";
533 const char *suffix = "";
537 case FULL_PATH_COLUMN:
538 prefix = chooser_entry->dir_part;
540 case DISPLAY_NAME_COLUMN:
541 if (_gtk_file_info_consider_as_directory (info))
542 suffix = G_DIR_SEPARATOR_S;
544 g_value_take_string (value, g_strconcat (
546 g_file_info_get_display_name (info),
551 g_assert_not_reached ();
558 /* Fills the completion store from the contents of the current folder */
560 populate_completion_store (GtkFileChooserEntry *chooser_entry)
562 chooser_entry->completion_store = GTK_TREE_MODEL (
563 _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
564 "standard::name,standard::display-name,standard::type",
565 completion_store_set,
570 g_signal_connect (chooser_entry->completion_store, "finished-loading",
571 G_CALLBACK (finished_loading_cb), chooser_entry);
573 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
574 DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
576 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
577 chooser_entry->completion_store);
580 /* When we finish loading the current folder, this function should get called to
581 * perform the deferred explicit completion.
584 perform_load_complete_action (GtkFileChooserEntry *chooser_entry)
586 switch (chooser_entry->load_complete_action)
588 case LOAD_COMPLETE_NOTHING:
591 case LOAD_COMPLETE_EXPLICIT_COMPLETION:
592 explicitly_complete (chooser_entry);
596 g_assert_not_reached ();
601 /* Callback when the current folder finishes loading */
603 finished_loading_cb (GtkFileSystemModel *model,
605 GtkFileChooserEntry *chooser_entry)
607 GtkEntryCompletion *completion;
609 chooser_entry->current_folder_loaded = TRUE;
613 LoadCompleteAction old_load_complete_action;
615 old_load_complete_action = chooser_entry->load_complete_action;
617 discard_completion_store (chooser_entry);
618 clear_completions (chooser_entry);
620 if (old_load_complete_action == LOAD_COMPLETE_EXPLICIT_COMPLETION)
622 /* Since this came from explicit user action (Tab completion), we'll present errors visually */
624 beep (chooser_entry);
630 perform_load_complete_action (chooser_entry);
632 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
634 completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
635 gtk_entry_completion_set_inline_completion (completion, TRUE);
636 gtk_entry_completion_complete (completion);
637 gtk_entry_completion_insert_prefix (completion);
641 set_completion_folder (GtkFileChooserEntry *chooser_entry,
645 chooser_entry->local_only
646 && !g_file_is_native (folder_file))
649 if ((chooser_entry->current_folder_file
651 && g_file_equal (folder_file, chooser_entry->current_folder_file))
652 || chooser_entry->current_folder_file == folder_file)
655 if (chooser_entry->current_folder_file)
657 g_object_unref (chooser_entry->current_folder_file);
658 chooser_entry->current_folder_file = NULL;
661 chooser_entry->current_folder_loaded = FALSE;
663 discard_completion_store (chooser_entry);
667 chooser_entry->current_folder_file = g_object_ref (folder_file);
668 populate_completion_store (chooser_entry);
673 refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry)
676 char *text, *last_slash;
678 g_free (chooser_entry->file_part);
679 g_free (chooser_entry->dir_part);
681 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
683 last_slash = strrchr (text, G_DIR_SEPARATOR);
686 chooser_entry->dir_part = g_strndup (text, last_slash - text + 1);
687 chooser_entry->file_part = g_strdup (last_slash + 1);
691 chooser_entry->dir_part = g_strdup ("");
692 chooser_entry->file_part = g_strdup (text);
695 folder_file = gtk_file_chooser_get_directory_for_text (chooser_entry, text);
696 set_completion_folder (chooser_entry, folder_file);
698 g_object_unref (folder_file);
705 insert_text_callback (GtkFileChooserEntry *chooser_entry,
706 const gchar *new_text,
707 gint new_text_length,
711 const gchar *colon = memchr (new_text, ':', new_text_length);
714 /* Disallow these characters altogether */
715 for (i = 0; i < new_text_length; i++)
717 if (new_text[i] == '<' ||
718 new_text[i] == '>' ||
719 new_text[i] == '"' ||
720 new_text[i] == '|' ||
721 new_text[i] == '*' ||
726 if (i < new_text_length ||
727 /* Disallow entering text that would cause a colon to be anywhere except
728 * after a drive letter.
731 *position + (colon - new_text) != 1) ||
732 (new_text_length > 0 &&
734 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
735 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':'))
737 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
738 g_signal_stop_emission_by_name (chooser_entry, "insert_text");
746 delete_text_callback (GtkFileChooserEntry *chooser_entry,
751 /* If deleting a drive letter, delete the colon, too */
752 if (start_pos == 0 && end_pos == 1 &&
753 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
754 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':')
756 g_signal_handlers_block_by_func (chooser_entry,
757 G_CALLBACK (delete_text_callback),
759 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry), 0, 1);
760 g_signal_handlers_unblock_by_func (chooser_entry,
761 G_CALLBACK (delete_text_callback),
768 * _gtk_file_chooser_entry_new:
769 * @eat_tabs: If %FALSE, allow focus navigation with the tab key.
771 * Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
772 * is an internal implementation widget for the GTK+ file chooser
773 * which is an entry with completion with respect to a
774 * #GtkFileSystem object.
776 * Return value: the newly created #GtkFileChooserEntry
779 _gtk_file_chooser_entry_new (gboolean eat_tabs)
781 GtkFileChooserEntry *chooser_entry;
783 chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
784 chooser_entry->eat_tabs = (eat_tabs != FALSE);
786 return GTK_WIDGET (chooser_entry);
790 * _gtk_file_chooser_entry_set_base_folder:
791 * @chooser_entry: a #GtkFileChooserEntry
792 * @file: file for a folder in the chooser entries current file system.
794 * Sets the folder with respect to which completions occur.
797 _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
803 file = g_file_new_for_path (g_get_home_dir ());
805 if (g_file_equal (chooser_entry->base_folder, file))
807 g_object_unref (file);
811 if (chooser_entry->base_folder)
812 g_object_unref (chooser_entry->base_folder);
814 chooser_entry->base_folder = file;
816 clear_completions (chooser_entry);
820 * _gtk_file_chooser_entry_get_current_folder:
821 * @chooser_entry: a #GtkFileChooserEntry
823 * Gets the current folder for the #GtkFileChooserEntry. If the
824 * user has only entered a filename, this will be in the base folder
825 * (see _gtk_file_chooser_entry_set_base_folder()), but if the
826 * user has entered a relative or absolute path, then it will
827 * be different. If the user has entered unparsable text, or text which
828 * the entry cannot handle, this will return %NULL.
830 * Return value: the file for the current folder - you must g_object_unref()
831 * the value after use.
834 _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
836 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
838 return gtk_file_chooser_get_directory_for_text (chooser_entry,
839 gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
843 * _gtk_file_chooser_entry_get_file_part:
844 * @chooser_entry: a #GtkFileChooserEntry
846 * Gets the non-folder portion of whatever the user has entered
847 * into the file selector. What is returned is a UTF-8 string,
848 * and if a filename path is needed, g_file_get_child_for_display_name()
851 * Return value: the entered filename - this value is owned by the
852 * chooser entry and must not be modified or freed.
855 _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
857 const char *last_slash, *text;
859 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
861 text = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
862 last_slash = strrchr (text, G_DIR_SEPARATOR);
864 return last_slash + 1;
870 * _gtk_file_chooser_entry_set_action:
871 * @chooser_entry: a #GtkFileChooserEntry
872 * @action: the action which is performed by the file selector using this entry
874 * Sets action which is performed by the file selector using this entry.
875 * The #GtkFileChooserEntry will use different completion strategies for
879 _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
880 GtkFileChooserAction action)
882 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
884 if (chooser_entry->action != action)
886 GtkEntryCompletion *comp;
888 chooser_entry->action = action;
890 comp = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
892 /* FIXME: do we need to actually set the following? */
896 case GTK_FILE_CHOOSER_ACTION_OPEN:
897 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
898 gtk_entry_completion_set_popup_single_match (comp, FALSE);
900 case GTK_FILE_CHOOSER_ACTION_SAVE:
901 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
902 gtk_entry_completion_set_popup_single_match (comp, TRUE);
910 * _gtk_file_chooser_entry_get_action:
911 * @chooser_entry: a #GtkFileChooserEntry
913 * Gets the action for this entry.
915 * Returns: the action
918 _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry)
920 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry),
921 GTK_FILE_CHOOSER_ACTION_OPEN);
923 return chooser_entry->action;
927 _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
933 if (chooser_entry->completion_store == NULL ||
934 !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
939 info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
942 return _gtk_file_info_consider_as_directory (info);
947 * _gtk_file_chooser_entry_select_filename:
948 * @chooser_entry: a #GtkFileChooserEntry
950 * Selects the filename (without the extension) for user edition.
953 _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
955 const gchar *str, *ext;
958 if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE)
960 str = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
961 ext = g_strrstr (str, ".");
964 len = g_utf8_pointer_to_offset (str, ext);
967 gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
971 _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
974 chooser_entry->local_only = local_only;
975 clear_completions (chooser_entry);
979 _gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry)
981 return chooser_entry->local_only;