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 struct _GtkFileChooserEntry
50 GtkEntry parent_instance;
52 GtkFileChooserAction action;
55 GFile *current_folder_file;
59 GtkTreeModel *completion_store;
61 guint current_folder_loaded : 1;
62 guint complete_on_load : 1;
74 static void gtk_file_chooser_entry_finalize (GObject *object);
75 static void gtk_file_chooser_entry_dispose (GObject *object);
76 static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
77 static gboolean gtk_file_chooser_entry_tab_handler (GtkWidget *widget,
79 static gboolean gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
80 GdkEventFocus *event);
83 static gint insert_text_callback (GtkFileChooserEntry *widget,
84 const gchar *new_text,
88 static void delete_text_callback (GtkFileChooserEntry *widget,
94 static gboolean match_selected_callback (GtkEntryCompletion *completion,
97 GtkFileChooserEntry *chooser_entry);
99 static void set_complete_on_load (GtkFileChooserEntry *chooser_entry,
100 gboolean complete_on_load);
101 static void refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry);
102 static void set_completion_folder (GtkFileChooserEntry *chooser_entry,
104 static void finished_loading_cb (GtkFileSystemModel *model,
106 GtkFileChooserEntry *chooser_entry);
108 G_DEFINE_TYPE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY)
111 gtk_file_chooser_entry_get_completion_text (GtkFileChooserEntry *chooser_entry)
113 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
116 gtk_editable_get_selection_bounds (editable, &start, &end);
117 return gtk_editable_get_chars (editable, 0, MIN (start, end));
121 gtk_file_chooser_entry_dispatch_properties_changed (GObject *object,
125 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
128 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
130 /* What we are after: The text in front of the cursor was modified.
131 * Unfortunately, there's no other way to catch this. */
133 for (i = 0; i < n_pspecs; i++)
135 if (pspecs[i]->name == I_("cursor-position") ||
136 pspecs[i]->name == I_("selection-bound") ||
137 pspecs[i]->name == I_("text"))
139 set_complete_on_load (chooser_entry, FALSE);
140 refresh_current_folder_and_file_part (chooser_entry);
147 _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
149 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
150 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
152 gobject_class->finalize = gtk_file_chooser_entry_finalize;
153 gobject_class->dispose = gtk_file_chooser_entry_dispose;
154 gobject_class->dispatch_properties_changed = gtk_file_chooser_entry_dispatch_properties_changed;
156 widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
157 widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
161 _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
163 GtkEntryCompletion *comp;
164 GtkCellRenderer *cell;
166 chooser_entry->local_only = TRUE;
168 g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
170 comp = gtk_entry_completion_new ();
171 gtk_entry_completion_set_popup_single_match (comp, FALSE);
172 gtk_entry_completion_set_minimum_key_length (comp, 0);
173 /* see docs for gtk_entry_completion_set_text_column() */
174 g_object_set (comp, "text-column", FULL_PATH_COLUMN, NULL);
176 /* Need a match func here or entry completion uses a wrong one.
177 * We do our own filtering after all. */
178 gtk_entry_completion_set_match_func (comp,
179 (GtkEntryCompletionMatchFunc) gtk_true,
183 cell = gtk_cell_renderer_text_new ();
184 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp),
186 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
188 "text", DISPLAY_NAME_COLUMN);
190 g_signal_connect (comp, "match-selected",
191 G_CALLBACK (match_selected_callback), chooser_entry);
193 gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp);
194 g_object_unref (comp);
195 /* NB: This needs to happen after the completion is set, so this handler
196 * runs before the handler installed by entrycompletion */
197 g_signal_connect (chooser_entry, "key-press-event",
198 G_CALLBACK (gtk_file_chooser_entry_tab_handler), NULL);
201 g_signal_connect (chooser_entry, "insert-text",
202 G_CALLBACK (insert_text_callback), NULL);
203 g_signal_connect (chooser_entry, "delete-text",
204 G_CALLBACK (delete_text_callback), NULL);
209 gtk_file_chooser_entry_finalize (GObject *object)
211 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
213 if (chooser_entry->base_folder)
214 g_object_unref (chooser_entry->base_folder);
216 if (chooser_entry->current_folder_file)
217 g_object_unref (chooser_entry->current_folder_file);
219 g_free (chooser_entry->dir_part);
220 g_free (chooser_entry->file_part);
222 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
226 gtk_file_chooser_entry_dispose (GObject *object)
228 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
230 set_completion_folder (chooser_entry, NULL);
232 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
235 /* Match functions for the GtkEntryCompletion */
237 match_selected_callback (GtkEntryCompletion *completion,
240 GtkFileChooserEntry *chooser_entry)
244 gtk_tree_model_get (model, iter,
245 FULL_PATH_COLUMN, &path,
248 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
250 gtk_editable_get_position (GTK_EDITABLE (chooser_entry)));
251 gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
262 set_complete_on_load (GtkFileChooserEntry *chooser_entry,
263 gboolean complete_on_load)
265 /* a completion was triggered, but we couldn't do it.
266 * So no text was inserted when pressing tab, so we beep */
267 if (chooser_entry->complete_on_load && !complete_on_load)
268 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
270 chooser_entry->complete_on_load = complete_on_load;
274 is_valid_scheme_character (char c)
276 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
280 has_uri_scheme (const char *str)
286 if (!is_valid_scheme_character (*p))
291 while (is_valid_scheme_character (*p));
293 return (strncmp (p, "://", 3) == 0);
297 gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
302 if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
303 file = g_file_parse_name (str);
304 else if (chooser_entry->base_folder != NULL)
305 file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
313 gtk_file_chooser_get_directory_for_text (GtkFileChooserEntry *chooser_entry,
316 GFile *file, *parent;
318 file = gtk_file_chooser_get_file_for_text (chooser_entry, text);
323 if (text[0] == 0 || text[strlen (text) - 1] == G_DIR_SEPARATOR)
326 parent = g_file_get_parent (file);
327 g_object_unref (file);
332 /* Finds a common prefix based on the contents of the entry
333 * and mandatorily appends it
336 explicitly_complete (GtkFileChooserEntry *chooser_entry)
338 chooser_entry->complete_on_load = FALSE;
340 if (chooser_entry->completion_store)
342 char *completion, *text;
343 gsize completion_len, text_len;
345 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
346 text_len = strlen (text);
347 completion = gtk_entry_completion_compute_prefix (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), text);
348 completion_len = completion ? strlen (completion) : 0;
350 if (completion_len > text_len)
352 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
353 int pos = gtk_editable_get_position (editable);
355 gtk_editable_insert_text (editable,
356 completion + text_len,
357 completion_len - text_len,
359 gtk_editable_set_position (editable, pos);
364 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
368 gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
370 GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
371 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
375 start_explicit_completion (GtkFileChooserEntry *chooser_entry)
377 if (chooser_entry->current_folder_loaded)
378 explicitly_complete (chooser_entry);
380 set_complete_on_load (chooser_entry, TRUE);
384 gtk_file_chooser_entry_tab_handler (GtkWidget *widget,
387 GtkFileChooserEntry *chooser_entry;
388 GtkEditable *editable;
389 GdkModifierType state;
392 chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
393 editable = GTK_EDITABLE (widget);
395 if (!chooser_entry->eat_tabs)
398 if (event->keyval != GDK_KEY_Tab)
401 if (gtk_get_current_event_state (&state) &&
402 (state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
405 /* This is a bit evil -- it makes Tab never leave the entry. It basically
406 * makes it 'safe' for people to hit. */
407 gtk_editable_get_selection_bounds (editable, &start, &end);
410 gtk_editable_set_position (editable, MAX (start, end));
412 start_explicit_completion (chooser_entry);
418 gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
419 GdkEventFocus *event)
421 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
423 set_complete_on_load (chooser_entry, FALSE);
425 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->focus_out_event (widget, event);
429 update_inline_completion (GtkFileChooserEntry *chooser_entry)
431 GtkEntryCompletion *completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
433 if (!chooser_entry->current_folder_loaded)
435 gtk_entry_completion_set_inline_completion (completion, FALSE);
439 switch (chooser_entry->action)
441 case GTK_FILE_CHOOSER_ACTION_OPEN:
442 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
443 gtk_entry_completion_set_inline_completion (completion, TRUE);
445 case GTK_FILE_CHOOSER_ACTION_SAVE:
446 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
447 gtk_entry_completion_set_inline_completion (completion, FALSE);
453 discard_completion_store (GtkFileChooserEntry *chooser_entry)
455 if (!chooser_entry->completion_store)
458 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
459 update_inline_completion (chooser_entry);
460 g_object_unref (chooser_entry->completion_store);
461 chooser_entry->completion_store = NULL;
465 completion_store_set (GtkFileSystemModel *model,
472 GtkFileChooserEntry *chooser_entry = data;
474 const char *prefix = "";
475 const char *suffix = "";
479 case FULL_PATH_COLUMN:
480 prefix = chooser_entry->dir_part;
482 case DISPLAY_NAME_COLUMN:
483 if (_gtk_file_info_consider_as_directory (info))
484 suffix = G_DIR_SEPARATOR_S;
486 g_value_take_string (value, g_strconcat (
488 g_file_info_get_display_name (info),
493 g_assert_not_reached ();
500 /* Fills the completion store from the contents of the current folder */
502 populate_completion_store (GtkFileChooserEntry *chooser_entry)
504 chooser_entry->completion_store = GTK_TREE_MODEL (
505 _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
506 "standard::name,standard::display-name,standard::type",
507 completion_store_set,
512 g_signal_connect (chooser_entry->completion_store, "finished-loading",
513 G_CALLBACK (finished_loading_cb), chooser_entry);
515 _gtk_file_system_model_set_filter_folders (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
517 _gtk_file_system_model_set_show_files (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
518 chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
519 chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE);
520 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
521 DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
523 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
524 chooser_entry->completion_store);
527 /* Callback when the current folder finishes loading */
529 finished_loading_cb (GtkFileSystemModel *model,
531 GtkFileChooserEntry *chooser_entry)
533 GtkEntryCompletion *completion;
535 chooser_entry->current_folder_loaded = TRUE;
539 discard_completion_store (chooser_entry);
540 set_complete_on_load (chooser_entry, FALSE);
544 if (chooser_entry->complete_on_load)
545 explicitly_complete (chooser_entry);
547 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
549 completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
550 update_inline_completion (chooser_entry);
551 gtk_entry_completion_complete (completion);
552 gtk_entry_completion_insert_prefix (completion);
556 set_completion_folder (GtkFileChooserEntry *chooser_entry,
560 chooser_entry->local_only
561 && !g_file_is_native (folder_file))
564 if ((chooser_entry->current_folder_file
566 && g_file_equal (folder_file, chooser_entry->current_folder_file))
567 || chooser_entry->current_folder_file == folder_file)
570 if (chooser_entry->current_folder_file)
572 g_object_unref (chooser_entry->current_folder_file);
573 chooser_entry->current_folder_file = NULL;
576 chooser_entry->current_folder_loaded = FALSE;
578 discard_completion_store (chooser_entry);
582 chooser_entry->current_folder_file = g_object_ref (folder_file);
583 populate_completion_store (chooser_entry);
588 refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry)
591 char *text, *last_slash, *old_file_part;
593 old_file_part = chooser_entry->file_part;
594 g_free (chooser_entry->dir_part);
596 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
598 last_slash = strrchr (text, G_DIR_SEPARATOR);
601 chooser_entry->dir_part = g_strndup (text, last_slash - text + 1);
602 chooser_entry->file_part = g_strdup (last_slash + 1);
606 chooser_entry->dir_part = g_strdup ("");
607 chooser_entry->file_part = g_strdup (text);
610 folder_file = gtk_file_chooser_get_directory_for_text (chooser_entry, text);
611 set_completion_folder (chooser_entry, folder_file);
613 g_object_unref (folder_file);
615 if (chooser_entry->completion_store &&
616 (g_strcmp0 (old_file_part, chooser_entry->file_part) != 0))
618 GtkFileFilter *filter;
621 filter = gtk_file_filter_new ();
622 pattern = g_strconcat (chooser_entry->file_part, "*", NULL);
623 gtk_file_filter_add_pattern (filter, pattern);
625 _gtk_file_system_model_set_filter (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
629 g_object_unref (filter);
633 g_free (old_file_part);
638 insert_text_callback (GtkFileChooserEntry *chooser_entry,
639 const gchar *new_text,
640 gint new_text_length,
644 const gchar *colon = memchr (new_text, ':', new_text_length);
647 /* Disallow these characters altogether */
648 for (i = 0; i < new_text_length; i++)
650 if (new_text[i] == '<' ||
651 new_text[i] == '>' ||
652 new_text[i] == '"' ||
653 new_text[i] == '|' ||
654 new_text[i] == '*' ||
659 if (i < new_text_length ||
660 /* Disallow entering text that would cause a colon to be anywhere except
661 * after a drive letter.
664 *position + (colon - new_text) != 1) ||
665 (new_text_length > 0 &&
667 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
668 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':'))
670 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
671 g_signal_stop_emission_by_name (chooser_entry, "insert_text");
679 delete_text_callback (GtkFileChooserEntry *chooser_entry,
684 /* If deleting a drive letter, delete the colon, too */
685 if (start_pos == 0 && end_pos == 1 &&
686 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
687 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':')
689 g_signal_handlers_block_by_func (chooser_entry,
690 G_CALLBACK (delete_text_callback),
692 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry), 0, 1);
693 g_signal_handlers_unblock_by_func (chooser_entry,
694 G_CALLBACK (delete_text_callback),
701 * _gtk_file_chooser_entry_new:
702 * @eat_tabs: If %FALSE, allow focus navigation with the tab key.
704 * Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
705 * is an internal implementation widget for the GTK+ file chooser
706 * which is an entry with completion with respect to a
707 * #GtkFileSystem object.
709 * Return value: the newly created #GtkFileChooserEntry
712 _gtk_file_chooser_entry_new (gboolean eat_tabs)
714 GtkFileChooserEntry *chooser_entry;
716 chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
717 chooser_entry->eat_tabs = (eat_tabs != FALSE);
719 return GTK_WIDGET (chooser_entry);
723 * _gtk_file_chooser_entry_set_base_folder:
724 * @chooser_entry: a #GtkFileChooserEntry
725 * @file: file for a folder in the chooser entries current file system.
727 * Sets the folder with respect to which completions occur.
730 _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
733 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
734 g_return_if_fail (file == NULL || G_IS_FILE (file));
736 if (chooser_entry->base_folder == file ||
737 (file != NULL && chooser_entry->base_folder != NULL
738 && g_file_equal (chooser_entry->base_folder, file)))
744 if (chooser_entry->base_folder)
745 g_object_unref (chooser_entry->base_folder);
747 chooser_entry->base_folder = file;
749 refresh_current_folder_and_file_part (chooser_entry);
753 * _gtk_file_chooser_entry_get_current_folder:
754 * @chooser_entry: a #GtkFileChooserEntry
756 * Gets the current folder for the #GtkFileChooserEntry. If the
757 * user has only entered a filename, this will be in the base folder
758 * (see _gtk_file_chooser_entry_set_base_folder()), but if the
759 * user has entered a relative or absolute path, then it will
760 * be different. If the user has entered unparsable text, or text which
761 * the entry cannot handle, this will return %NULL.
763 * Return value: the file for the current folder - you must g_object_unref()
764 * the value after use.
767 _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
769 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
771 return gtk_file_chooser_get_directory_for_text (chooser_entry,
772 gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
776 * _gtk_file_chooser_entry_get_file_part:
777 * @chooser_entry: a #GtkFileChooserEntry
779 * Gets the non-folder portion of whatever the user has entered
780 * into the file selector. What is returned is a UTF-8 string,
781 * and if a filename path is needed, g_file_get_child_for_display_name()
784 * Return value: the entered filename - this value is owned by the
785 * chooser entry and must not be modified or freed.
788 _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
790 const char *last_slash, *text;
792 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
794 text = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
795 last_slash = strrchr (text, G_DIR_SEPARATOR);
797 return last_slash + 1;
803 * _gtk_file_chooser_entry_set_action:
804 * @chooser_entry: a #GtkFileChooserEntry
805 * @action: the action which is performed by the file selector using this entry
807 * Sets action which is performed by the file selector using this entry.
808 * The #GtkFileChooserEntry will use different completion strategies for
812 _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
813 GtkFileChooserAction action)
815 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
817 if (chooser_entry->action != action)
819 GtkEntryCompletion *comp;
821 chooser_entry->action = action;
823 comp = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
825 /* FIXME: do we need to actually set the following? */
829 case GTK_FILE_CHOOSER_ACTION_OPEN:
830 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
831 gtk_entry_completion_set_popup_single_match (comp, FALSE);
833 case GTK_FILE_CHOOSER_ACTION_SAVE:
834 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
835 gtk_entry_completion_set_popup_single_match (comp, TRUE);
839 if (chooser_entry->completion_store)
840 _gtk_file_system_model_set_show_files (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
841 action == GTK_FILE_CHOOSER_ACTION_OPEN ||
842 action == GTK_FILE_CHOOSER_ACTION_SAVE);
844 update_inline_completion (chooser_entry);
850 * _gtk_file_chooser_entry_get_action:
851 * @chooser_entry: a #GtkFileChooserEntry
853 * Gets the action for this entry.
855 * Returns: the action
858 _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry)
860 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry),
861 GTK_FILE_CHOOSER_ACTION_OPEN);
863 return chooser_entry->action;
867 _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
873 if (chooser_entry->completion_store == NULL ||
874 !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
879 info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
882 return _gtk_file_info_consider_as_directory (info);
887 * _gtk_file_chooser_entry_select_filename:
888 * @chooser_entry: a #GtkFileChooserEntry
890 * Selects the filename (without the extension) for user edition.
893 _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
895 const gchar *str, *ext;
898 if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE)
900 str = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
901 ext = g_strrstr (str, ".");
904 len = g_utf8_pointer_to_offset (str, ext);
907 gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
911 _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
914 chooser_entry->local_only = local_only;
915 refresh_current_folder_and_file_part (chooser_entry);
919 _gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry)
921 return chooser_entry->local_only;