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;
82 static void gtk_file_chooser_entry_finalize (GObject *object);
83 static void gtk_file_chooser_entry_dispose (GObject *object);
84 static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
85 static gboolean gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
87 static gboolean gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
88 GdkEventFocus *event);
91 static gint insert_text_callback (GtkFileChooserEntry *widget,
92 const gchar *new_text,
96 static void delete_text_callback (GtkFileChooserEntry *widget,
102 static gboolean match_selected_callback (GtkEntryCompletion *completion,
105 GtkFileChooserEntry *chooser_entry);
106 static gboolean completion_match_func (GtkEntryCompletion *comp,
111 static void refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry);
112 static void set_completion_folder (GtkFileChooserEntry *chooser_entry,
114 static void finished_loading_cb (GtkFileSystemModel *model,
116 GtkFileChooserEntry *chooser_entry);
118 G_DEFINE_TYPE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY)
121 gtk_file_chooser_entry_get_completion_text (GtkFileChooserEntry *chooser_entry)
123 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
126 gtk_editable_get_selection_bounds (editable, &start, &end);
127 return gtk_editable_get_chars (editable, 0, MIN (start, end));
131 gtk_file_chooser_entry_dispatch_properties_changed (GObject *object,
135 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
138 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
140 /* What we are after: The text in front of the cursor was modified.
141 * Unfortunately, there's no other way to catch this. */
143 for (i = 0; i < n_pspecs; i++)
145 if (pspecs[i]->name == I_("cursor-position") ||
146 pspecs[i]->name == I_("selection-bound") ||
147 pspecs[i]->name == I_("text"))
149 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
151 refresh_current_folder_and_file_part (chooser_entry);
159 _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
161 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
162 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
164 gobject_class->finalize = gtk_file_chooser_entry_finalize;
165 gobject_class->dispose = gtk_file_chooser_entry_dispose;
166 gobject_class->dispatch_properties_changed = gtk_file_chooser_entry_dispatch_properties_changed;
168 widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
169 widget_class->key_press_event = gtk_file_chooser_entry_key_press_event;
170 widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
174 _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
176 GtkEntryCompletion *comp;
177 GtkCellRenderer *cell;
179 chooser_entry->local_only = TRUE;
180 chooser_entry->base_folder = g_file_new_for_path (g_get_home_dir ());
182 g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
184 comp = gtk_entry_completion_new ();
185 gtk_entry_completion_set_popup_single_match (comp, FALSE);
186 gtk_entry_completion_set_minimum_key_length (comp, 0);
187 /* see docs for gtk_entry_completion_set_text_column() */
188 g_object_set (comp, "text-column", FULL_PATH_COLUMN, NULL);
190 gtk_entry_completion_set_match_func (comp,
191 completion_match_func,
195 cell = gtk_cell_renderer_text_new ();
196 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp),
198 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
200 "text", DISPLAY_NAME_COLUMN);
202 g_signal_connect (comp, "match-selected",
203 G_CALLBACK (match_selected_callback), chooser_entry);
205 gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp);
206 g_object_unref (comp);
209 g_signal_connect (chooser_entry, "insert-text",
210 G_CALLBACK (insert_text_callback), NULL);
211 g_signal_connect (chooser_entry, "delete-text",
212 G_CALLBACK (delete_text_callback), NULL);
217 gtk_file_chooser_entry_finalize (GObject *object)
219 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
221 g_object_unref (chooser_entry->base_folder);
223 if (chooser_entry->current_folder_file)
224 g_object_unref (chooser_entry->current_folder_file);
226 g_free (chooser_entry->dir_part);
227 g_free (chooser_entry->file_part);
229 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
233 gtk_file_chooser_entry_dispose (GObject *object)
235 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
237 set_completion_folder (chooser_entry, NULL);
239 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
242 /* Match functions for the GtkEntryCompletion */
244 match_selected_callback (GtkEntryCompletion *completion,
247 GtkFileChooserEntry *chooser_entry)
251 gtk_tree_model_get (model, iter,
252 FULL_PATH_COLUMN, &path,
255 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
257 gtk_editable_get_position (GTK_EDITABLE (chooser_entry)));
258 gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
268 /* Match function for the GtkEntryCompletion */
270 completion_match_func (GtkEntryCompletion *comp,
271 const char *key_unused,
275 GtkFileChooserEntry *chooser_entry;
278 char *norm_file_part;
281 chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
283 /* We ignore the key because it is the contents of the entry. Instead, we
284 * just use our precomputed file_part.
286 if (!chooser_entry->file_part)
291 gtk_tree_model_get (chooser_entry->completion_store, iter, DISPLAY_NAME_COLUMN, &name, -1);
294 return FALSE; /* Uninitialized row, ugh */
297 /* If we have an empty file_part, then we're at the root of a directory. In
298 * that case, we want to match all non-dot files. We might want to match
299 * dot_files too if show_hidden is TRUE on the fileselector in the future.
301 /* Additionally, support for gnome .hidden files would be sweet, too */
302 if (chooser_entry->file_part[0] == '\000')
314 norm_file_part = g_utf8_normalize (chooser_entry->file_part, -1, G_NORMALIZE_ALL);
315 norm_name = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
317 #ifdef G_PLATFORM_WIN32
321 temp = norm_file_part;
322 norm_file_part = g_utf8_casefold (norm_file_part, -1);
326 norm_name = g_utf8_casefold (norm_name, -1);
331 result = (strncmp (norm_file_part, norm_name, strlen (norm_file_part)) == 0);
333 g_free (norm_file_part);
341 clear_completions (GtkFileChooserEntry *chooser_entry)
343 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
347 beep (GtkFileChooserEntry *chooser_entry)
349 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
353 is_valid_scheme_character (char c)
355 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
359 has_uri_scheme (const char *str)
365 if (!is_valid_scheme_character (*p))
370 while (is_valid_scheme_character (*p));
372 return (strncmp (p, "://", 3) == 0);
376 gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
381 if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
382 file = g_file_parse_name (str);
384 file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
390 gtk_file_chooser_get_directory_for_text (GtkFileChooserEntry *chooser_entry,
393 GFile *file, *parent;
395 file = gtk_file_chooser_get_file_for_text (chooser_entry, text);
397 if (text[0] == 0 || text[strlen (text) - 1] == G_DIR_SEPARATOR)
400 parent = g_file_get_parent (file);
401 g_object_unref (file);
406 /* Finds a common prefix based on the contents of the entry
407 * and mandatorily appends it
410 explicitly_complete (GtkFileChooserEntry *chooser_entry)
412 clear_completions (chooser_entry);
414 if (chooser_entry->completion_store)
416 char *completion, *text;
417 gsize completion_len, text_len;
419 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
420 text_len = strlen (text);
421 completion = gtk_entry_completion_compute_prefix (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), text);
422 completion_len = completion ? strlen (completion) : 0;
424 if (completion_len > text_len)
426 GtkEditable *editable = GTK_EDITABLE (chooser_entry);
427 int pos = gtk_editable_get_position (editable);
429 gtk_editable_insert_text (editable,
430 completion + text_len,
431 completion_len - text_len,
433 gtk_editable_set_position (editable, pos);
438 beep (chooser_entry);
442 gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
444 GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
445 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
449 start_explicit_completion (GtkFileChooserEntry *chooser_entry)
451 if (chooser_entry->current_folder_loaded)
452 explicitly_complete (chooser_entry);
454 chooser_entry->load_complete_action = LOAD_COMPLETE_EXPLICIT_COMPLETION;
458 gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
461 GtkFileChooserEntry *chooser_entry;
462 GtkEditable *editable;
463 GdkModifierType state;
464 gboolean control_pressed;
466 chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
467 editable = GTK_EDITABLE (widget);
469 if (!chooser_entry->eat_tabs)
470 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
472 control_pressed = FALSE;
474 if (gtk_get_current_event_state (&state))
476 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
477 control_pressed = TRUE;
480 /* This is a bit evil -- it makes Tab never leave the entry. It basically
481 * makes it 'safe' for people to hit. */
482 if (event->keyval == GDK_KEY_Tab && !control_pressed)
486 gtk_editable_get_selection_bounds (editable, &start, &end);
489 gtk_editable_set_position (editable, MAX (start, end));
491 start_explicit_completion (chooser_entry);
496 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
501 gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
502 GdkEventFocus *event)
504 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
506 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
508 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->focus_out_event (widget, event);
512 discard_completion_store (GtkFileChooserEntry *chooser_entry)
514 if (!chooser_entry->completion_store)
517 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
518 gtk_entry_completion_set_inline_completion (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), FALSE);
519 g_object_unref (chooser_entry->completion_store);
520 chooser_entry->completion_store = NULL;
524 completion_store_set (GtkFileSystemModel *model,
531 GtkFileChooserEntry *chooser_entry = data;
533 const char *prefix = "";
534 const char *suffix = "";
539 g_value_set_object (value, file);
541 case FULL_PATH_COLUMN:
542 prefix = chooser_entry->dir_part;
544 case DISPLAY_NAME_COLUMN:
545 if (_gtk_file_info_consider_as_directory (info))
546 suffix = G_DIR_SEPARATOR_S;
548 g_value_take_string (value, g_strconcat (
550 g_file_info_get_display_name (info),
555 g_assert_not_reached ();
562 /* Fills the completion store from the contents of the current folder */
564 populate_completion_store (GtkFileChooserEntry *chooser_entry)
566 chooser_entry->completion_store = GTK_TREE_MODEL (
567 _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
568 "standard::name,standard::display-name,standard::type",
569 completion_store_set,
575 g_signal_connect (chooser_entry->completion_store, "finished-loading",
576 G_CALLBACK (finished_loading_cb), chooser_entry);
578 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
579 DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
581 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
582 chooser_entry->completion_store);
585 /* When we finish loading the current folder, this function should get called to
586 * perform the deferred explicit completion.
589 perform_load_complete_action (GtkFileChooserEntry *chooser_entry)
591 switch (chooser_entry->load_complete_action)
593 case LOAD_COMPLETE_NOTHING:
596 case LOAD_COMPLETE_EXPLICIT_COMPLETION:
597 explicitly_complete (chooser_entry);
601 g_assert_not_reached ();
606 /* Callback when the current folder finishes loading */
608 finished_loading_cb (GtkFileSystemModel *model,
610 GtkFileChooserEntry *chooser_entry)
612 GtkEntryCompletion *completion;
614 chooser_entry->current_folder_loaded = TRUE;
618 LoadCompleteAction old_load_complete_action;
620 old_load_complete_action = chooser_entry->load_complete_action;
622 discard_completion_store (chooser_entry);
623 clear_completions (chooser_entry);
625 if (old_load_complete_action == LOAD_COMPLETE_EXPLICIT_COMPLETION)
627 /* Since this came from explicit user action (Tab completion), we'll present errors visually */
629 beep (chooser_entry);
635 perform_load_complete_action (chooser_entry);
637 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
639 completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
640 gtk_entry_completion_set_inline_completion (completion, TRUE);
641 gtk_entry_completion_complete (completion);
642 gtk_entry_completion_insert_prefix (completion);
646 set_completion_folder (GtkFileChooserEntry *chooser_entry,
650 chooser_entry->local_only
651 && !g_file_is_native (folder_file))
654 if ((chooser_entry->current_folder_file
656 && g_file_equal (folder_file, chooser_entry->current_folder_file))
657 || chooser_entry->current_folder_file == folder_file)
660 if (chooser_entry->current_folder_file)
662 g_object_unref (chooser_entry->current_folder_file);
663 chooser_entry->current_folder_file = NULL;
666 chooser_entry->current_folder_loaded = FALSE;
668 discard_completion_store (chooser_entry);
672 chooser_entry->current_folder_file = g_object_ref (folder_file);
673 populate_completion_store (chooser_entry);
678 refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry)
681 char *text, *last_slash;
683 g_free (chooser_entry->file_part);
684 g_free (chooser_entry->dir_part);
686 text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
688 last_slash = strrchr (text, G_DIR_SEPARATOR);
691 chooser_entry->dir_part = g_strndup (text, last_slash - text + 1);
692 chooser_entry->file_part = g_strdup (last_slash + 1);
696 chooser_entry->dir_part = g_strdup ("");
697 chooser_entry->file_part = g_strdup (text);
700 folder_file = gtk_file_chooser_get_directory_for_text (chooser_entry, text);
701 set_completion_folder (chooser_entry, folder_file);
703 g_object_unref (folder_file);
710 insert_text_callback (GtkFileChooserEntry *chooser_entry,
711 const gchar *new_text,
712 gint new_text_length,
716 const gchar *colon = memchr (new_text, ':', new_text_length);
719 /* Disallow these characters altogether */
720 for (i = 0; i < new_text_length; i++)
722 if (new_text[i] == '<' ||
723 new_text[i] == '>' ||
724 new_text[i] == '"' ||
725 new_text[i] == '|' ||
726 new_text[i] == '*' ||
731 if (i < new_text_length ||
732 /* Disallow entering text that would cause a colon to be anywhere except
733 * after a drive letter.
736 *position + (colon - new_text) != 1) ||
737 (new_text_length > 0 &&
739 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
740 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':'))
742 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
743 g_signal_stop_emission_by_name (chooser_entry, "insert_text");
751 delete_text_callback (GtkFileChooserEntry *chooser_entry,
756 /* If deleting a drive letter, delete the colon, too */
757 if (start_pos == 0 && end_pos == 1 &&
758 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
759 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':')
761 g_signal_handlers_block_by_func (chooser_entry,
762 G_CALLBACK (delete_text_callback),
764 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry), 0, 1);
765 g_signal_handlers_unblock_by_func (chooser_entry,
766 G_CALLBACK (delete_text_callback),
773 * _gtk_file_chooser_entry_new:
774 * @eat_tabs: If %FALSE, allow focus navigation with the tab key.
776 * Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
777 * is an internal implementation widget for the GTK+ file chooser
778 * which is an entry with completion with respect to a
779 * #GtkFileSystem object.
781 * Return value: the newly created #GtkFileChooserEntry
784 _gtk_file_chooser_entry_new (gboolean eat_tabs)
786 GtkFileChooserEntry *chooser_entry;
788 chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
789 chooser_entry->eat_tabs = (eat_tabs != FALSE);
791 return GTK_WIDGET (chooser_entry);
795 * _gtk_file_chooser_entry_set_base_folder:
796 * @chooser_entry: a #GtkFileChooserEntry
797 * @file: file for a folder in the chooser entries current file system.
799 * Sets the folder with respect to which completions occur.
802 _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
808 file = g_file_new_for_path (g_get_home_dir ());
810 if (g_file_equal (chooser_entry->base_folder, file))
812 g_object_unref (file);
816 if (chooser_entry->base_folder)
817 g_object_unref (chooser_entry->base_folder);
819 chooser_entry->base_folder = file;
821 clear_completions (chooser_entry);
825 * _gtk_file_chooser_entry_get_current_folder:
826 * @chooser_entry: a #GtkFileChooserEntry
828 * Gets the current folder for the #GtkFileChooserEntry. If the
829 * user has only entered a filename, this will be in the base folder
830 * (see _gtk_file_chooser_entry_set_base_folder()), but if the
831 * user has entered a relative or absolute path, then it will
832 * be different. If the user has entered unparsable text, or text which
833 * the entry cannot handle, this will return %NULL.
835 * Return value: the file for the current folder - you must g_object_unref()
836 * the value after use.
839 _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
841 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
843 return gtk_file_chooser_get_directory_for_text (chooser_entry,
844 gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
848 * _gtk_file_chooser_entry_get_file_part:
849 * @chooser_entry: a #GtkFileChooserEntry
851 * Gets the non-folder portion of whatever the user has entered
852 * into the file selector. What is returned is a UTF-8 string,
853 * and if a filename path is needed, g_file_get_child_for_display_name()
856 * Return value: the entered filename - this value is owned by the
857 * chooser entry and must not be modified or freed.
860 _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
862 const char *last_slash, *text;
864 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
866 text = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
867 last_slash = strrchr (text, G_DIR_SEPARATOR);
869 return last_slash + 1;
875 * _gtk_file_chooser_entry_set_action:
876 * @chooser_entry: a #GtkFileChooserEntry
877 * @action: the action which is performed by the file selector using this entry
879 * Sets action which is performed by the file selector using this entry.
880 * The #GtkFileChooserEntry will use different completion strategies for
884 _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
885 GtkFileChooserAction action)
887 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
889 if (chooser_entry->action != action)
891 GtkEntryCompletion *comp;
893 chooser_entry->action = action;
895 comp = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
897 /* FIXME: do we need to actually set the following? */
901 case GTK_FILE_CHOOSER_ACTION_OPEN:
902 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
903 gtk_entry_completion_set_popup_single_match (comp, FALSE);
905 case GTK_FILE_CHOOSER_ACTION_SAVE:
906 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
907 gtk_entry_completion_set_popup_single_match (comp, TRUE);
915 * _gtk_file_chooser_entry_get_action:
916 * @chooser_entry: a #GtkFileChooserEntry
918 * Gets the action for this entry.
920 * Returns: the action
923 _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry)
925 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry),
926 GTK_FILE_CHOOSER_ACTION_OPEN);
928 return chooser_entry->action;
932 _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
938 if (chooser_entry->completion_store == NULL ||
939 !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
944 info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
947 return _gtk_file_info_consider_as_directory (info);
952 * _gtk_file_chooser_entry_select_filename:
953 * @chooser_entry: a #GtkFileChooserEntry
955 * Selects the filename (without the extension) for user edition.
958 _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
960 const gchar *str, *ext;
963 if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE)
965 str = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
966 ext = g_strrstr (str, ".");
969 len = g_utf8_pointer_to_offset (str, ext);
972 gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
976 _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
979 chooser_entry->local_only = local_only;
980 clear_completions (chooser_entry);
984 _gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry)
986 return chooser_entry->local_only;