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_key_press_event (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->key_press_event = gtk_file_chooser_entry_key_press_event;
158 widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
162 _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
164 GtkEntryCompletion *comp;
165 GtkCellRenderer *cell;
167 chooser_entry->local_only = TRUE;
169 g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
171 comp = gtk_entry_completion_new ();
172 gtk_entry_completion_set_popup_single_match (comp, FALSE);
173 gtk_entry_completion_set_minimum_key_length (comp, 0);
174 /* see docs for gtk_entry_completion_set_text_column() */
175 g_object_set (comp, "text-column", FULL_PATH_COLUMN, NULL);
177 /* Need a match func here or entry completion uses a wrong one.
178 * We do our own filtering after all. */
179 gtk_entry_completion_set_match_func (comp,
180 (GtkEntryCompletionMatchFunc) gtk_true,
184 cell = gtk_cell_renderer_text_new ();
185 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp),
187 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
189 "text", DISPLAY_NAME_COLUMN);
191 g_signal_connect (comp, "match-selected",
192 G_CALLBACK (match_selected_callback), chooser_entry);
194 gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp);
195 g_object_unref (comp);
198 g_signal_connect (chooser_entry, "insert-text",
199 G_CALLBACK (insert_text_callback), NULL);
200 g_signal_connect (chooser_entry, "delete-text",
201 G_CALLBACK (delete_text_callback), NULL);
206 gtk_file_chooser_entry_finalize (GObject *object)
208 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
210 if (chooser_entry->base_folder)
211 g_object_unref (chooser_entry->base_folder);
213 if (chooser_entry->current_folder_file)
214 g_object_unref (chooser_entry->current_folder_file);
216 g_free (chooser_entry->dir_part);
217 g_free (chooser_entry->file_part);
219 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
223 gtk_file_chooser_entry_dispose (GObject *object)
225 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
227 set_completion_folder (chooser_entry, NULL);
229 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
232 /* Match functions for the GtkEntryCompletion */
234 match_selected_callback (GtkEntryCompletion *completion,
237 GtkFileChooserEntry *chooser_entry)
241 gtk_tree_model_get (model, iter,
242 FULL_PATH_COLUMN, &path,
245 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
247 gtk_editable_get_position (GTK_EDITABLE (chooser_entry)));
248 gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
259 set_complete_on_load (GtkFileChooserEntry *chooser_entry,
260 gboolean complete_on_load)
262 /* a completion was triggered, but we couldn't do it.
263 * So no text was inserted when pressing tab, so we beep */
264 if (chooser_entry->complete_on_load && !complete_on_load)
265 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
267 chooser_entry->complete_on_load = complete_on_load;
271 is_valid_scheme_character (char c)
273 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
277 has_uri_scheme (const char *str)
283 if (!is_valid_scheme_character (*p))
288 while (is_valid_scheme_character (*p));
290 return (strncmp (p, "://", 3) == 0);
294 gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
299 if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
300 file = g_file_parse_name (str);
301 else if (chooser_entry->base_folder != NULL)
302 file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
310 gtk_file_chooser_get_directory_for_text (GtkFileChooserEntry *chooser_entry,
313 GFile *file, *parent;
315 file = gtk_file_chooser_get_file_for_text (chooser_entry, text);
320 if (text[0] == 0 || text[strlen (text) - 1] == G_DIR_SEPARATOR)
323 parent = g_file_get_parent (file);
324 g_object_unref (file);
329 /* Finds a common prefix based on the contents of the entry
330 * and mandatorily appends it
333 explicitly_complete (GtkFileChooserEntry *chooser_entry)
335 chooser_entry->complete_on_load = FALSE;
337 if (chooser_entry->completion_store)
339 char *completion, *text;
340 gsize completion_len, text_len;
342 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
343 text_len = strlen (text);
344 completion = gtk_entry_completion_compute_prefix (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), text);
345 completion_len = completion ? strlen (completion) : 0;
347 if (completion_len > text_len)
349 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
350 int pos = gtk_editable_get_position (editable);
352 gtk_editable_insert_text (editable,
353 completion + text_len,
354 completion_len - text_len,
356 gtk_editable_set_position (editable, pos);
361 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
365 gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
367 GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
368 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
372 start_explicit_completion (GtkFileChooserEntry *chooser_entry)
374 if (chooser_entry->current_folder_loaded)
375 explicitly_complete (chooser_entry);
377 set_complete_on_load (chooser_entry, TRUE);
381 gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
384 GtkFileChooserEntry *chooser_entry;
385 GtkEditable *editable;
386 GdkModifierType state;
387 gboolean control_pressed;
389 chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
390 editable = GTK_EDITABLE (widget);
392 if (!chooser_entry->eat_tabs)
393 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
395 control_pressed = FALSE;
397 if (gtk_get_current_event_state (&state))
399 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
400 control_pressed = TRUE;
403 /* This is a bit evil -- it makes Tab never leave the entry. It basically
404 * makes it 'safe' for people to hit. */
405 if (event->keyval == GDK_KEY_Tab && !control_pressed)
409 gtk_editable_get_selection_bounds (editable, &start, &end);
412 gtk_editable_set_position (editable, MAX (start, end));
414 start_explicit_completion (chooser_entry);
419 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
424 gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
425 GdkEventFocus *event)
427 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
429 set_complete_on_load (chooser_entry, FALSE);
431 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->focus_out_event (widget, event);
435 update_inline_completion (GtkFileChooserEntry *chooser_entry)
437 GtkEntryCompletion *completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
439 if (!chooser_entry->current_folder_loaded)
441 gtk_entry_completion_set_inline_completion (completion, FALSE);
445 switch (chooser_entry->action)
447 case GTK_FILE_CHOOSER_ACTION_OPEN:
448 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
449 gtk_entry_completion_set_inline_completion (completion, TRUE);
451 case GTK_FILE_CHOOSER_ACTION_SAVE:
452 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
453 gtk_entry_completion_set_inline_completion (completion, FALSE);
459 discard_completion_store (GtkFileChooserEntry *chooser_entry)
461 if (!chooser_entry->completion_store)
464 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
465 update_inline_completion (chooser_entry);
466 g_object_unref (chooser_entry->completion_store);
467 chooser_entry->completion_store = NULL;
471 completion_store_set (GtkFileSystemModel *model,
478 GtkFileChooserEntry *chooser_entry = data;
480 const char *prefix = "";
481 const char *suffix = "";
485 case FULL_PATH_COLUMN:
486 prefix = chooser_entry->dir_part;
488 case DISPLAY_NAME_COLUMN:
489 if (_gtk_file_info_consider_as_directory (info))
490 suffix = G_DIR_SEPARATOR_S;
492 g_value_take_string (value, g_strconcat (
494 g_file_info_get_display_name (info),
499 g_assert_not_reached ();
506 /* Fills the completion store from the contents of the current folder */
508 populate_completion_store (GtkFileChooserEntry *chooser_entry)
510 chooser_entry->completion_store = GTK_TREE_MODEL (
511 _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
512 "standard::name,standard::display-name,standard::type",
513 completion_store_set,
518 g_signal_connect (chooser_entry->completion_store, "finished-loading",
519 G_CALLBACK (finished_loading_cb), chooser_entry);
521 _gtk_file_system_model_set_filter_folders (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
523 _gtk_file_system_model_set_show_files (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
524 chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
525 chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE);
526 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
527 DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
529 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
530 chooser_entry->completion_store);
533 /* Callback when the current folder finishes loading */
535 finished_loading_cb (GtkFileSystemModel *model,
537 GtkFileChooserEntry *chooser_entry)
539 GtkEntryCompletion *completion;
541 chooser_entry->current_folder_loaded = TRUE;
545 discard_completion_store (chooser_entry);
546 set_complete_on_load (chooser_entry, FALSE);
550 if (chooser_entry->complete_on_load)
551 explicitly_complete (chooser_entry);
553 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
555 completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
556 update_inline_completion (chooser_entry);
557 gtk_entry_completion_complete (completion);
558 gtk_entry_completion_insert_prefix (completion);
562 set_completion_folder (GtkFileChooserEntry *chooser_entry,
566 chooser_entry->local_only
567 && !g_file_is_native (folder_file))
570 if ((chooser_entry->current_folder_file
572 && g_file_equal (folder_file, chooser_entry->current_folder_file))
573 || chooser_entry->current_folder_file == folder_file)
576 if (chooser_entry->current_folder_file)
578 g_object_unref (chooser_entry->current_folder_file);
579 chooser_entry->current_folder_file = NULL;
582 chooser_entry->current_folder_loaded = FALSE;
584 discard_completion_store (chooser_entry);
588 chooser_entry->current_folder_file = g_object_ref (folder_file);
589 populate_completion_store (chooser_entry);
594 refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry)
597 char *text, *last_slash, *old_file_part;
599 old_file_part = chooser_entry->file_part;
600 g_free (chooser_entry->dir_part);
602 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
604 last_slash = strrchr (text, G_DIR_SEPARATOR);
607 chooser_entry->dir_part = g_strndup (text, last_slash - text + 1);
608 chooser_entry->file_part = g_strdup (last_slash + 1);
612 chooser_entry->dir_part = g_strdup ("");
613 chooser_entry->file_part = g_strdup (text);
616 folder_file = gtk_file_chooser_get_directory_for_text (chooser_entry, text);
617 set_completion_folder (chooser_entry, folder_file);
619 g_object_unref (folder_file);
621 if (chooser_entry->completion_store &&
622 (g_strcmp0 (old_file_part, chooser_entry->file_part) != 0))
624 GtkFileFilter *filter;
627 filter = gtk_file_filter_new ();
628 pattern = g_strconcat (chooser_entry->file_part, "*", NULL);
629 gtk_file_filter_add_pattern (filter, pattern);
631 _gtk_file_system_model_set_filter (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
635 g_object_unref (filter);
639 g_free (old_file_part);
644 insert_text_callback (GtkFileChooserEntry *chooser_entry,
645 const gchar *new_text,
646 gint new_text_length,
650 const gchar *colon = memchr (new_text, ':', new_text_length);
653 /* Disallow these characters altogether */
654 for (i = 0; i < new_text_length; i++)
656 if (new_text[i] == '<' ||
657 new_text[i] == '>' ||
658 new_text[i] == '"' ||
659 new_text[i] == '|' ||
660 new_text[i] == '*' ||
665 if (i < new_text_length ||
666 /* Disallow entering text that would cause a colon to be anywhere except
667 * after a drive letter.
670 *position + (colon - new_text) != 1) ||
671 (new_text_length > 0 &&
673 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
674 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':'))
676 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
677 g_signal_stop_emission_by_name (chooser_entry, "insert_text");
685 delete_text_callback (GtkFileChooserEntry *chooser_entry,
690 /* If deleting a drive letter, delete the colon, too */
691 if (start_pos == 0 && end_pos == 1 &&
692 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
693 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':')
695 g_signal_handlers_block_by_func (chooser_entry,
696 G_CALLBACK (delete_text_callback),
698 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry), 0, 1);
699 g_signal_handlers_unblock_by_func (chooser_entry,
700 G_CALLBACK (delete_text_callback),
707 * _gtk_file_chooser_entry_new:
708 * @eat_tabs: If %FALSE, allow focus navigation with the tab key.
710 * Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
711 * is an internal implementation widget for the GTK+ file chooser
712 * which is an entry with completion with respect to a
713 * #GtkFileSystem object.
715 * Return value: the newly created #GtkFileChooserEntry
718 _gtk_file_chooser_entry_new (gboolean eat_tabs)
720 GtkFileChooserEntry *chooser_entry;
722 chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
723 chooser_entry->eat_tabs = (eat_tabs != FALSE);
725 return GTK_WIDGET (chooser_entry);
729 * _gtk_file_chooser_entry_set_base_folder:
730 * @chooser_entry: a #GtkFileChooserEntry
731 * @file: file for a folder in the chooser entries current file system.
733 * Sets the folder with respect to which completions occur.
736 _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
739 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
740 g_return_if_fail (file == NULL || G_IS_FILE (file));
742 if (chooser_entry->base_folder == file ||
743 (file != NULL && chooser_entry->base_folder != NULL
744 && g_file_equal (chooser_entry->base_folder, file)))
750 if (chooser_entry->base_folder)
751 g_object_unref (chooser_entry->base_folder);
753 chooser_entry->base_folder = file;
755 refresh_current_folder_and_file_part (chooser_entry);
759 * _gtk_file_chooser_entry_get_current_folder:
760 * @chooser_entry: a #GtkFileChooserEntry
762 * Gets the current folder for the #GtkFileChooserEntry. If the
763 * user has only entered a filename, this will be in the base folder
764 * (see _gtk_file_chooser_entry_set_base_folder()), but if the
765 * user has entered a relative or absolute path, then it will
766 * be different. If the user has entered unparsable text, or text which
767 * the entry cannot handle, this will return %NULL.
769 * Return value: the file for the current folder - you must g_object_unref()
770 * the value after use.
773 _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
775 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
777 return gtk_file_chooser_get_directory_for_text (chooser_entry,
778 gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
782 * _gtk_file_chooser_entry_get_file_part:
783 * @chooser_entry: a #GtkFileChooserEntry
785 * Gets the non-folder portion of whatever the user has entered
786 * into the file selector. What is returned is a UTF-8 string,
787 * and if a filename path is needed, g_file_get_child_for_display_name()
790 * Return value: the entered filename - this value is owned by the
791 * chooser entry and must not be modified or freed.
794 _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
796 const char *last_slash, *text;
798 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
800 text = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
801 last_slash = strrchr (text, G_DIR_SEPARATOR);
803 return last_slash + 1;
809 * _gtk_file_chooser_entry_set_action:
810 * @chooser_entry: a #GtkFileChooserEntry
811 * @action: the action which is performed by the file selector using this entry
813 * Sets action which is performed by the file selector using this entry.
814 * The #GtkFileChooserEntry will use different completion strategies for
818 _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
819 GtkFileChooserAction action)
821 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
823 if (chooser_entry->action != action)
825 GtkEntryCompletion *comp;
827 chooser_entry->action = action;
829 comp = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
831 /* FIXME: do we need to actually set the following? */
835 case GTK_FILE_CHOOSER_ACTION_OPEN:
836 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
837 gtk_entry_completion_set_popup_single_match (comp, FALSE);
839 case GTK_FILE_CHOOSER_ACTION_SAVE:
840 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
841 gtk_entry_completion_set_popup_single_match (comp, TRUE);
845 if (chooser_entry->completion_store)
846 _gtk_file_system_model_set_show_files (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
847 action == GTK_FILE_CHOOSER_ACTION_OPEN ||
848 action == GTK_FILE_CHOOSER_ACTION_SAVE);
850 update_inline_completion (chooser_entry);
856 * _gtk_file_chooser_entry_get_action:
857 * @chooser_entry: a #GtkFileChooserEntry
859 * Gets the action for this entry.
861 * Returns: the action
864 _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry)
866 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry),
867 GTK_FILE_CHOOSER_ACTION_OPEN);
869 return chooser_entry->action;
873 _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
879 if (chooser_entry->completion_store == NULL ||
880 !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
885 info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
888 return _gtk_file_info_consider_as_directory (info);
893 * _gtk_file_chooser_entry_select_filename:
894 * @chooser_entry: a #GtkFileChooserEntry
896 * Selects the filename (without the extension) for user edition.
899 _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
901 const gchar *str, *ext;
904 if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE)
906 str = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
907 ext = g_strrstr (str, ".");
910 len = g_utf8_pointer_to_offset (str, ext);
913 gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
917 _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
920 chooser_entry->local_only = local_only;
921 refresh_current_folder_and_file_part (chooser_entry);
925 _gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry)
927 return chooser_entry->local_only;