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, see <http://www.gnu.org/licenses/>.
21 #include "gtkfilechooserentry.h"
25 #include "gtkcelllayout.h"
26 #include "gtkcellrenderertext.h"
28 #include "gtkfilesystemmodel.h"
31 #include "gtksizerequest.h"
32 #include "gtkwindow.h"
35 typedef struct _GtkFileChooserEntryClass GtkFileChooserEntryClass;
37 #define GTK_FILE_CHOOSER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_ENTRY, GtkFileChooserEntryClass))
38 #define GTK_IS_FILE_CHOOSER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_ENTRY))
39 #define GTK_FILE_CHOOSER_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_ENTRY, GtkFileChooserEntryClass))
41 struct _GtkFileChooserEntryClass
43 GtkEntryClass parent_class;
46 struct _GtkFileChooserEntry
48 GtkEntry parent_instance;
50 GtkFileChooserAction action;
53 GFile *current_folder_file;
57 GtkTreeModel *completion_store;
59 guint current_folder_loaded : 1;
60 guint complete_on_load : 1;
72 static void gtk_file_chooser_entry_finalize (GObject *object);
73 static void gtk_file_chooser_entry_dispose (GObject *object);
74 static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
75 static gboolean gtk_file_chooser_entry_tab_handler (GtkWidget *widget,
77 static gboolean gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
78 GdkEventFocus *event);
81 static gint insert_text_callback (GtkFileChooserEntry *widget,
82 const gchar *new_text,
86 static void delete_text_callback (GtkFileChooserEntry *widget,
92 static gboolean match_selected_callback (GtkEntryCompletion *completion,
95 GtkFileChooserEntry *chooser_entry);
97 static void set_complete_on_load (GtkFileChooserEntry *chooser_entry,
98 gboolean complete_on_load);
99 static void refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry);
100 static void set_completion_folder (GtkFileChooserEntry *chooser_entry,
102 static void finished_loading_cb (GtkFileSystemModel *model,
104 GtkFileChooserEntry *chooser_entry);
106 G_DEFINE_TYPE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY)
109 gtk_file_chooser_entry_get_completion_text (GtkFileChooserEntry *chooser_entry)
111 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
114 gtk_editable_get_selection_bounds (editable, &start, &end);
115 return gtk_editable_get_chars (editable, 0, MIN (start, end));
119 gtk_file_chooser_entry_dispatch_properties_changed (GObject *object,
123 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
126 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
128 /* What we are after: The text in front of the cursor was modified.
129 * Unfortunately, there's no other way to catch this. */
131 for (i = 0; i < n_pspecs; i++)
133 if (pspecs[i]->name == I_("cursor-position") ||
134 pspecs[i]->name == I_("selection-bound") ||
135 pspecs[i]->name == I_("text"))
137 set_complete_on_load (chooser_entry, FALSE);
138 refresh_current_folder_and_file_part (chooser_entry);
145 _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
147 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
148 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
150 gobject_class->finalize = gtk_file_chooser_entry_finalize;
151 gobject_class->dispose = gtk_file_chooser_entry_dispose;
152 gobject_class->dispatch_properties_changed = gtk_file_chooser_entry_dispatch_properties_changed;
154 widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
155 widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
159 _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
161 GtkEntryCompletion *comp;
162 GtkCellRenderer *cell;
164 chooser_entry->local_only = TRUE;
166 g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
168 comp = gtk_entry_completion_new ();
169 gtk_entry_completion_set_popup_single_match (comp, FALSE);
170 gtk_entry_completion_set_minimum_key_length (comp, 0);
171 /* see docs for gtk_entry_completion_set_text_column() */
172 g_object_set (comp, "text-column", FULL_PATH_COLUMN, NULL);
174 /* Need a match func here or entry completion uses a wrong one.
175 * We do our own filtering after all. */
176 gtk_entry_completion_set_match_func (comp,
177 (GtkEntryCompletionMatchFunc) gtk_true,
181 cell = gtk_cell_renderer_text_new ();
182 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp),
184 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
186 "text", DISPLAY_NAME_COLUMN);
188 g_signal_connect (comp, "match-selected",
189 G_CALLBACK (match_selected_callback), chooser_entry);
191 gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp);
192 g_object_unref (comp);
193 /* NB: This needs to happen after the completion is set, so this handler
194 * runs before the handler installed by entrycompletion */
195 g_signal_connect (chooser_entry, "key-press-event",
196 G_CALLBACK (gtk_file_chooser_entry_tab_handler), NULL);
199 g_signal_connect (chooser_entry, "insert-text",
200 G_CALLBACK (insert_text_callback), NULL);
201 g_signal_connect (chooser_entry, "delete-text",
202 G_CALLBACK (delete_text_callback), NULL);
207 gtk_file_chooser_entry_finalize (GObject *object)
209 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
211 if (chooser_entry->base_folder)
212 g_object_unref (chooser_entry->base_folder);
214 if (chooser_entry->current_folder_file)
215 g_object_unref (chooser_entry->current_folder_file);
217 g_free (chooser_entry->dir_part);
218 g_free (chooser_entry->file_part);
220 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
224 gtk_file_chooser_entry_dispose (GObject *object)
226 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
228 set_completion_folder (chooser_entry, NULL);
230 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
233 /* Match functions for the GtkEntryCompletion */
235 match_selected_callback (GtkEntryCompletion *completion,
238 GtkFileChooserEntry *chooser_entry)
242 gtk_tree_model_get (model, iter,
243 FULL_PATH_COLUMN, &path,
246 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
248 gtk_editable_get_position (GTK_EDITABLE (chooser_entry)));
249 gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
260 set_complete_on_load (GtkFileChooserEntry *chooser_entry,
261 gboolean complete_on_load)
263 /* a completion was triggered, but we couldn't do it.
264 * So no text was inserted when pressing tab, so we beep */
265 if (chooser_entry->complete_on_load && !complete_on_load)
266 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
268 chooser_entry->complete_on_load = complete_on_load;
272 is_valid_scheme_character (char c)
274 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
278 has_uri_scheme (const char *str)
284 if (!is_valid_scheme_character (*p))
289 while (is_valid_scheme_character (*p));
291 return (strncmp (p, "://", 3) == 0);
295 gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
300 if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
301 file = g_file_parse_name (str);
302 else if (chooser_entry->base_folder != NULL)
303 file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
311 gtk_file_chooser_get_directory_for_text (GtkFileChooserEntry *chooser_entry,
314 GFile *file, *parent;
316 file = gtk_file_chooser_get_file_for_text (chooser_entry, text);
321 if (text[0] == 0 || text[strlen (text) - 1] == G_DIR_SEPARATOR)
324 parent = g_file_get_parent (file);
325 g_object_unref (file);
330 /* Finds a common prefix based on the contents of the entry
331 * and mandatorily appends it
334 explicitly_complete (GtkFileChooserEntry *chooser_entry)
336 chooser_entry->complete_on_load = FALSE;
338 if (chooser_entry->completion_store)
340 char *completion, *text;
341 gsize completion_len, text_len;
343 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
344 text_len = strlen (text);
345 completion = gtk_entry_completion_compute_prefix (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), text);
346 completion_len = completion ? strlen (completion) : 0;
348 if (completion_len > text_len)
350 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
351 int pos = gtk_editable_get_position (editable);
353 gtk_editable_insert_text (editable,
354 completion + text_len,
355 completion_len - text_len,
357 gtk_editable_set_position (editable, pos);
362 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
366 gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
368 GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
369 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
373 start_explicit_completion (GtkFileChooserEntry *chooser_entry)
375 if (chooser_entry->current_folder_loaded)
376 explicitly_complete (chooser_entry);
378 set_complete_on_load (chooser_entry, TRUE);
382 gtk_file_chooser_entry_tab_handler (GtkWidget *widget,
385 GtkFileChooserEntry *chooser_entry;
386 GtkEditable *editable;
387 GdkModifierType state;
390 chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
391 editable = GTK_EDITABLE (widget);
393 if (!chooser_entry->eat_tabs)
396 if (event->keyval != GDK_KEY_Tab)
399 if (gtk_get_current_event_state (&state) &&
400 (state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
403 /* This is a bit evil -- it makes Tab never leave the entry. It basically
404 * makes it 'safe' for people to hit. */
405 gtk_editable_get_selection_bounds (editable, &start, &end);
408 gtk_editable_set_position (editable, MAX (start, end));
410 start_explicit_completion (chooser_entry);
416 gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
417 GdkEventFocus *event)
419 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
421 set_complete_on_load (chooser_entry, FALSE);
423 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->focus_out_event (widget, event);
427 update_inline_completion (GtkFileChooserEntry *chooser_entry)
429 GtkEntryCompletion *completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
431 if (!chooser_entry->current_folder_loaded)
433 gtk_entry_completion_set_inline_completion (completion, FALSE);
437 switch (chooser_entry->action)
439 case GTK_FILE_CHOOSER_ACTION_OPEN:
440 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
441 gtk_entry_completion_set_inline_completion (completion, TRUE);
443 case GTK_FILE_CHOOSER_ACTION_SAVE:
444 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
445 gtk_entry_completion_set_inline_completion (completion, FALSE);
451 discard_completion_store (GtkFileChooserEntry *chooser_entry)
453 if (!chooser_entry->completion_store)
456 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
457 update_inline_completion (chooser_entry);
458 g_object_unref (chooser_entry->completion_store);
459 chooser_entry->completion_store = NULL;
463 completion_store_set (GtkFileSystemModel *model,
470 GtkFileChooserEntry *chooser_entry = data;
472 const char *prefix = "";
473 const char *suffix = "";
477 case FULL_PATH_COLUMN:
478 prefix = chooser_entry->dir_part;
480 case DISPLAY_NAME_COLUMN:
481 if (_gtk_file_info_consider_as_directory (info))
482 suffix = G_DIR_SEPARATOR_S;
484 g_value_take_string (value, g_strconcat (
486 g_file_info_get_display_name (info),
491 g_assert_not_reached ();
498 /* Fills the completion store from the contents of the current folder */
500 populate_completion_store (GtkFileChooserEntry *chooser_entry)
502 chooser_entry->completion_store = GTK_TREE_MODEL (
503 _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
504 "standard::name,standard::display-name,standard::type",
505 completion_store_set,
510 g_signal_connect (chooser_entry->completion_store, "finished-loading",
511 G_CALLBACK (finished_loading_cb), chooser_entry);
513 _gtk_file_system_model_set_filter_folders (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
515 _gtk_file_system_model_set_show_files (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
516 chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
517 chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE);
518 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
519 DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
521 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
522 chooser_entry->completion_store);
525 /* Callback when the current folder finishes loading */
527 finished_loading_cb (GtkFileSystemModel *model,
529 GtkFileChooserEntry *chooser_entry)
531 GtkEntryCompletion *completion;
533 chooser_entry->current_folder_loaded = TRUE;
537 discard_completion_store (chooser_entry);
538 set_complete_on_load (chooser_entry, FALSE);
542 if (chooser_entry->complete_on_load)
543 explicitly_complete (chooser_entry);
545 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
547 completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
548 update_inline_completion (chooser_entry);
549 gtk_entry_completion_complete (completion);
550 gtk_entry_completion_insert_prefix (completion);
554 set_completion_folder (GtkFileChooserEntry *chooser_entry,
558 chooser_entry->local_only
559 && !g_file_is_native (folder_file))
562 if ((chooser_entry->current_folder_file
564 && g_file_equal (folder_file, chooser_entry->current_folder_file))
565 || chooser_entry->current_folder_file == folder_file)
568 if (chooser_entry->current_folder_file)
570 g_object_unref (chooser_entry->current_folder_file);
571 chooser_entry->current_folder_file = NULL;
574 chooser_entry->current_folder_loaded = FALSE;
576 discard_completion_store (chooser_entry);
580 chooser_entry->current_folder_file = g_object_ref (folder_file);
581 populate_completion_store (chooser_entry);
586 refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry)
589 char *text, *last_slash, *old_file_part;
591 old_file_part = chooser_entry->file_part;
592 g_free (chooser_entry->dir_part);
594 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
596 last_slash = strrchr (text, G_DIR_SEPARATOR);
599 chooser_entry->dir_part = g_strndup (text, last_slash - text + 1);
600 chooser_entry->file_part = g_strdup (last_slash + 1);
604 chooser_entry->dir_part = g_strdup ("");
605 chooser_entry->file_part = g_strdup (text);
608 folder_file = gtk_file_chooser_get_directory_for_text (chooser_entry, text);
609 set_completion_folder (chooser_entry, folder_file);
611 g_object_unref (folder_file);
613 if (chooser_entry->completion_store &&
614 (g_strcmp0 (old_file_part, chooser_entry->file_part) != 0))
616 GtkFileFilter *filter;
619 filter = gtk_file_filter_new ();
620 pattern = g_strconcat (chooser_entry->file_part, "*", NULL);
621 gtk_file_filter_add_pattern (filter, pattern);
623 _gtk_file_system_model_set_filter (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
627 g_object_unref (filter);
631 g_free (old_file_part);
636 insert_text_callback (GtkFileChooserEntry *chooser_entry,
637 const gchar *new_text,
638 gint new_text_length,
642 const gchar *colon = memchr (new_text, ':', new_text_length);
645 /* Disallow these characters altogether */
646 for (i = 0; i < new_text_length; i++)
648 if (new_text[i] == '<' ||
649 new_text[i] == '>' ||
650 new_text[i] == '"' ||
651 new_text[i] == '|' ||
652 new_text[i] == '*' ||
657 if (i < new_text_length ||
658 /* Disallow entering text that would cause a colon to be anywhere except
659 * after a drive letter.
662 *position + (colon - new_text) != 1) ||
663 (new_text_length > 0 &&
665 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
666 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':'))
668 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
669 g_signal_stop_emission_by_name (chooser_entry, "insert_text");
677 delete_text_callback (GtkFileChooserEntry *chooser_entry,
682 /* If deleting a drive letter, delete the colon, too */
683 if (start_pos == 0 && end_pos == 1 &&
684 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
685 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':')
687 g_signal_handlers_block_by_func (chooser_entry,
688 G_CALLBACK (delete_text_callback),
690 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry), 0, 1);
691 g_signal_handlers_unblock_by_func (chooser_entry,
692 G_CALLBACK (delete_text_callback),
699 * _gtk_file_chooser_entry_new:
700 * @eat_tabs: If %FALSE, allow focus navigation with the tab key.
702 * Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
703 * is an internal implementation widget for the GTK+ file chooser
704 * which is an entry with completion with respect to a
705 * #GtkFileSystem object.
707 * Return value: the newly created #GtkFileChooserEntry
710 _gtk_file_chooser_entry_new (gboolean eat_tabs)
712 GtkFileChooserEntry *chooser_entry;
714 chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
715 chooser_entry->eat_tabs = (eat_tabs != FALSE);
717 return GTK_WIDGET (chooser_entry);
721 * _gtk_file_chooser_entry_set_base_folder:
722 * @chooser_entry: a #GtkFileChooserEntry
723 * @file: file for a folder in the chooser entries current file system.
725 * Sets the folder with respect to which completions occur.
728 _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
731 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
732 g_return_if_fail (file == NULL || G_IS_FILE (file));
734 if (chooser_entry->base_folder == file ||
735 (file != NULL && chooser_entry->base_folder != NULL
736 && g_file_equal (chooser_entry->base_folder, file)))
742 if (chooser_entry->base_folder)
743 g_object_unref (chooser_entry->base_folder);
745 chooser_entry->base_folder = file;
747 refresh_current_folder_and_file_part (chooser_entry);
751 * _gtk_file_chooser_entry_get_current_folder:
752 * @chooser_entry: a #GtkFileChooserEntry
754 * Gets the current folder for the #GtkFileChooserEntry. If the
755 * user has only entered a filename, this will be in the base folder
756 * (see _gtk_file_chooser_entry_set_base_folder()), but if the
757 * user has entered a relative or absolute path, then it will
758 * be different. If the user has entered unparsable text, or text which
759 * the entry cannot handle, this will return %NULL.
761 * Return value: the file for the current folder - you must g_object_unref()
762 * the value after use.
765 _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
767 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
769 return gtk_file_chooser_get_directory_for_text (chooser_entry,
770 gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
774 * _gtk_file_chooser_entry_get_file_part:
775 * @chooser_entry: a #GtkFileChooserEntry
777 * Gets the non-folder portion of whatever the user has entered
778 * into the file selector. What is returned is a UTF-8 string,
779 * and if a filename path is needed, g_file_get_child_for_display_name()
782 * Return value: the entered filename - this value is owned by the
783 * chooser entry and must not be modified or freed.
786 _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
788 const char *last_slash, *text;
790 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
792 text = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
793 last_slash = strrchr (text, G_DIR_SEPARATOR);
795 return last_slash + 1;
801 * _gtk_file_chooser_entry_set_action:
802 * @chooser_entry: a #GtkFileChooserEntry
803 * @action: the action which is performed by the file selector using this entry
805 * Sets action which is performed by the file selector using this entry.
806 * The #GtkFileChooserEntry will use different completion strategies for
810 _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
811 GtkFileChooserAction action)
813 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
815 if (chooser_entry->action != action)
817 GtkEntryCompletion *comp;
819 chooser_entry->action = action;
821 comp = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
823 /* FIXME: do we need to actually set the following? */
827 case GTK_FILE_CHOOSER_ACTION_OPEN:
828 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
829 gtk_entry_completion_set_popup_single_match (comp, FALSE);
831 case GTK_FILE_CHOOSER_ACTION_SAVE:
832 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
833 gtk_entry_completion_set_popup_single_match (comp, TRUE);
837 if (chooser_entry->completion_store)
838 _gtk_file_system_model_set_show_files (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
839 action == GTK_FILE_CHOOSER_ACTION_OPEN ||
840 action == GTK_FILE_CHOOSER_ACTION_SAVE);
842 update_inline_completion (chooser_entry);
848 * _gtk_file_chooser_entry_get_action:
849 * @chooser_entry: a #GtkFileChooserEntry
851 * Gets the action for this entry.
853 * Returns: the action
856 _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry)
858 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry),
859 GTK_FILE_CHOOSER_ACTION_OPEN);
861 return chooser_entry->action;
865 _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
871 if (chooser_entry->completion_store == NULL ||
872 !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
877 info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
880 return _gtk_file_info_consider_as_directory (info);
885 * _gtk_file_chooser_entry_select_filename:
886 * @chooser_entry: a #GtkFileChooserEntry
888 * Selects the filename (without the extension) for user edition.
891 _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
893 const gchar *str, *ext;
896 if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE)
898 str = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
899 ext = g_strrstr (str, ".");
902 len = g_utf8_pointer_to_offset (str, ext);
905 gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
909 _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
912 chooser_entry->local_only = local_only;
913 refresh_current_folder_and_file_part (chooser_entry);
917 _gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry)
919 return chooser_entry->local_only;