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_AUTOCOMPLETE,
52 LOAD_COMPLETE_EXPLICIT_COMPLETION
58 REFRESH_INVALID_INPUT,
59 REFRESH_INCOMPLETE_HOSTNAME,
64 struct _GtkFileChooserEntry
66 GtkEntry parent_instance;
68 GtkFileChooserAction action;
71 GFile *current_folder_file;
75 LoadCompleteAction load_complete_action;
77 GtkTreeModel *completion_store;
79 GtkWidget *completion_feedback_window;
80 GtkWidget *completion_feedback_label;
81 guint completion_feedback_timeout_id;
83 guint current_folder_loaded : 1;
84 guint has_completion : 1;
97 #define COMPLETION_FEEDBACK_TIMEOUT_MS 2000
99 static void gtk_file_chooser_entry_iface_init (GtkEditableInterface *iface);
101 static void gtk_file_chooser_entry_finalize (GObject *object);
102 static void gtk_file_chooser_entry_dispose (GObject *object);
103 static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
104 static void gtk_file_chooser_entry_unmap (GtkWidget *widget);
105 static gboolean gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
107 static gboolean gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
108 GdkEventFocus *event);
109 static void gtk_file_chooser_entry_activate (GtkEntry *entry);
110 static void gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
111 const gchar *new_text,
112 gint new_text_length,
114 static void gtk_file_chooser_entry_do_delete_text (GtkEditable *editable,
117 static void gtk_file_chooser_entry_set_position (GtkEditable *editable,
119 static void gtk_file_chooser_entry_set_selection_bounds (GtkEditable *editable,
124 static gint insert_text_callback (GtkFileChooserEntry *widget,
125 const gchar *new_text,
126 gint new_text_length,
129 static void delete_text_callback (GtkFileChooserEntry *widget,
135 static gboolean match_selected_callback (GtkEntryCompletion *completion,
138 GtkFileChooserEntry *chooser_entry);
139 static gboolean completion_match_func (GtkEntryCompletion *comp,
145 REFRESH_UP_TO_CURSOR_POSITION,
149 static RefreshStatus refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
150 RefreshMode refresh_mode);
151 static void finished_loading_cb (GtkFileSystemModel *model,
153 GtkFileChooserEntry *chooser_entry);
154 static void autocomplete (GtkFileChooserEntry *chooser_entry);
155 static void start_autocompletion (GtkFileChooserEntry *chooser_entry);
156 static void remove_completion_feedback (GtkFileChooserEntry *chooser_entry);
157 static void pop_up_completion_feedback (GtkFileChooserEntry *chooser_entry,
158 const gchar *feedback);
160 static GtkEditableInterface *parent_editable_iface;
162 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY,
163 G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
164 gtk_file_chooser_entry_iface_init))
167 _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
169 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
170 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
171 GtkEntryClass *entry_class = GTK_ENTRY_CLASS (class);
173 gobject_class->finalize = gtk_file_chooser_entry_finalize;
174 gobject_class->dispose = gtk_file_chooser_entry_dispose;
176 widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
177 widget_class->unmap = gtk_file_chooser_entry_unmap;
178 widget_class->key_press_event = gtk_file_chooser_entry_key_press_event;
179 widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
181 entry_class->activate = gtk_file_chooser_entry_activate;
185 gtk_file_chooser_entry_iface_init (GtkEditableInterface *iface)
187 parent_editable_iface = g_type_interface_peek_parent (iface);
189 iface->do_insert_text = gtk_file_chooser_entry_do_insert_text;
190 iface->do_delete_text = gtk_file_chooser_entry_do_delete_text;
191 iface->set_position = gtk_file_chooser_entry_set_position;
192 iface->set_selection_bounds = gtk_file_chooser_entry_set_selection_bounds;
196 _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
198 GtkEntryCompletion *comp;
199 GtkCellRenderer *cell;
201 chooser_entry->local_only = TRUE;
202 chooser_entry->base_folder = g_file_new_for_path (g_get_home_dir ());
204 g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
206 comp = gtk_entry_completion_new ();
207 gtk_entry_completion_set_popup_single_match (comp, FALSE);
209 gtk_entry_completion_set_match_func (comp,
210 completion_match_func,
214 cell = gtk_cell_renderer_text_new ();
215 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp),
217 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
219 "text", DISPLAY_NAME_COLUMN);
221 g_signal_connect (comp, "match-selected",
222 G_CALLBACK (match_selected_callback), chooser_entry);
224 gtk_entry_set_completion (GTK_ENTRY (chooser_entry), comp);
225 g_object_unref (comp);
228 g_signal_connect (chooser_entry, "insert-text",
229 G_CALLBACK (insert_text_callback), NULL);
230 g_signal_connect (chooser_entry, "delete-text",
231 G_CALLBACK (delete_text_callback), NULL);
236 gtk_file_chooser_entry_finalize (GObject *object)
238 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
240 g_object_unref (chooser_entry->base_folder);
242 if (chooser_entry->current_folder_file)
243 g_object_unref (chooser_entry->current_folder_file);
245 g_free (chooser_entry->file_part);
247 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
251 discard_loading_and_current_folder_file (GtkFileChooserEntry *chooser_entry)
253 if (chooser_entry->current_folder_file)
255 g_object_unref (chooser_entry->current_folder_file);
256 chooser_entry->current_folder_file = NULL;
261 gtk_file_chooser_entry_dispose (GObject *object)
263 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
265 remove_completion_feedback (chooser_entry);
266 discard_loading_and_current_folder_file (chooser_entry);
268 if (chooser_entry->completion_store)
270 g_object_unref (chooser_entry->completion_store);
271 chooser_entry->completion_store = NULL;
274 G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
277 /* Match functions for the GtkEntryCompletion */
279 match_selected_callback (GtkEntryCompletion *completion,
282 GtkFileChooserEntry *chooser_entry)
288 gtk_tree_model_get (model, iter,
289 DISPLAY_NAME_COLUMN, &display_name,
293 if (!display_name || !file)
296 g_object_unref (file);
298 g_free (display_name);
302 pos = chooser_entry->file_part_pos;
304 /* We don't set in_change here as we want to update the current_folder
306 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
308 gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
311 gtk_editable_set_position (GTK_EDITABLE (chooser_entry), -1);
313 g_object_unref (file);
314 g_free (display_name);
319 /* Match function for the GtkEntryCompletion */
321 completion_match_func (GtkEntryCompletion *comp,
322 const char *key_unused,
326 GtkFileChooserEntry *chooser_entry;
329 char *norm_file_part;
332 chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
334 /* We ignore the key because it is the contents of the entry. Instead, we
335 * just use our precomputed file_part.
337 if (!chooser_entry->file_part)
342 gtk_tree_model_get (chooser_entry->completion_store, iter, DISPLAY_NAME_COLUMN, &name, -1);
345 return FALSE; /* Uninitialized row, ugh */
348 /* If we have an empty file_part, then we're at the root of a directory. In
349 * that case, we want to match all non-dot files. We might want to match
350 * dot_files too if show_hidden is TRUE on the fileselector in the future.
352 /* Additionally, support for gnome .hidden files would be sweet, too */
353 if (chooser_entry->file_part[0] == '\000')
365 norm_file_part = g_utf8_normalize (chooser_entry->file_part, -1, G_NORMALIZE_ALL);
366 norm_name = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
368 #ifdef G_PLATFORM_WIN32
372 temp = norm_file_part;
373 norm_file_part = g_utf8_casefold (norm_file_part, -1);
377 norm_name = g_utf8_casefold (norm_name, -1);
382 result = (strncmp (norm_file_part, norm_name, strlen (norm_file_part)) == 0);
384 g_free (norm_file_part);
392 clear_completions (GtkFileChooserEntry *chooser_entry)
394 chooser_entry->has_completion = FALSE;
395 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
397 remove_completion_feedback (chooser_entry);
401 beep (GtkFileChooserEntry *chooser_entry)
403 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
407 is_valid_scheme_character (char c)
409 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
413 has_uri_scheme (const char *str)
419 if (!is_valid_scheme_character (*p))
424 while (is_valid_scheme_character (*p));
426 return (strncmp (p, "://", 3) == 0);
430 gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
435 if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
436 file = g_file_parse_name (str);
438 file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
444 gtk_file_chooser_entry_parse (GtkFileChooserEntry *chooser_entry,
451 gboolean result = FALSE;
452 gboolean is_dir = FALSE;
453 gchar *last_slash = NULL;
456 is_dir = (str [strlen (str) - 1] == G_DIR_SEPARATOR);
458 last_slash = strrchr (str, G_DIR_SEPARATOR);
460 file = gtk_file_chooser_get_file_for_text (chooser_entry, str);
462 if (g_file_equal (chooser_entry->base_folder, file))
464 /* this is when user types '.', could be the
465 * beginning of a hidden file, ./ or ../
467 *folder = g_object_ref (file);
468 *file_part = g_strdup (str);
473 /* it's a dir, or at least it ends with the dir separator */
474 *folder = g_object_ref (file);
475 *file_part = g_strdup ("");
482 parent_file = g_file_get_parent (file);
487 GTK_FILE_CHOOSER_ERROR,
488 GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
489 "Could not get parent file");
495 *folder = parent_file;
499 *file_part = g_strdup (last_slash + 1);
501 *file_part = g_strdup (str);
505 g_object_unref (file);
510 /* Determines if the completion model has entries with a common prefix relative
511 * to the current contents of the entry. Also, if there's one and only one such
512 * path, stores it in unique_path_ret.
515 find_common_prefix (GtkFileChooserEntry *chooser_entry,
516 gchar **common_prefix_ret,
517 GFile **unique_file_ret,
518 gboolean *is_complete_not_unique_ret,
519 gboolean *prefix_expands_the_file_part_ret,
522 GtkEditable *editable;
526 char *text_up_to_cursor;
527 GFile *parsed_folder_file;
528 char *parsed_file_part;
530 *common_prefix_ret = NULL;
531 *unique_file_ret = NULL;
532 *is_complete_not_unique_ret = FALSE;
533 *prefix_expands_the_file_part_ret = FALSE;
535 editable = GTK_EDITABLE (chooser_entry);
537 text_up_to_cursor = gtk_editable_get_chars (editable, 0, gtk_editable_get_position (editable));
539 parsed = gtk_file_chooser_entry_parse (chooser_entry,
545 g_free (text_up_to_cursor);
550 g_assert (parsed_folder_file != NULL
551 && g_file_equal (parsed_folder_file, chooser_entry->current_folder_file));
553 g_object_unref (parsed_folder_file);
555 /* First pass: find the common prefix */
557 valid = gtk_tree_model_get_iter_first (chooser_entry->completion_store, &iter);
564 gtk_tree_model_get (chooser_entry->completion_store,
566 DISPLAY_NAME_COLUMN, &display_name,
570 if (g_str_has_prefix (display_name, parsed_file_part))
572 if (!*common_prefix_ret)
574 *common_prefix_ret = g_strdup (display_name);
575 *unique_file_ret = g_object_ref (file);
579 gchar *p = *common_prefix_ret;
580 const gchar *q = display_name;
582 while (*p && *p == *q)
590 if (*unique_file_ret)
592 g_object_unref (*unique_file_ret);
593 *unique_file_ret = NULL;
598 g_free (display_name);
599 g_object_unref (file);
600 valid = gtk_tree_model_iter_next (chooser_entry->completion_store, &iter);
603 /* Second pass: see if the prefix we found is a complete match */
605 if (*common_prefix_ret != NULL)
607 valid = gtk_tree_model_get_iter_first (chooser_entry->completion_store, &iter);
614 gtk_tree_model_get (chooser_entry->completion_store,
616 DISPLAY_NAME_COLUMN, &display_name,
618 len = strlen (display_name);
621 if (G_IS_DIR_SEPARATOR (display_name[len - 1]))
624 if (*unique_file_ret == NULL && strncmp (*common_prefix_ret, display_name, len) == 0)
625 *is_complete_not_unique_ret = TRUE;
627 g_free (display_name);
628 valid = gtk_tree_model_iter_next (chooser_entry->completion_store, &iter);
631 /* Finally: Did we generate a new completion, or was the user's input already completed as far as it could go? */
633 *prefix_expands_the_file_part_ret = g_utf8_strlen (*common_prefix_ret, -1) > g_utf8_strlen (parsed_file_part, -1);
636 g_free (parsed_file_part);
642 INVALID_INPUT, /* what the user typed is bogus */
643 NO_MATCH, /* no matches based on what the user typed */
644 NOTHING_INSERTED_COMPLETE, /* what the user typed is already completed as far as it will go */
645 NOTHING_INSERTED_UNIQUE, /* what the user typed is already completed, and is a unique match */
646 COMPLETED, /* completion inserted (ambiguous suffix) */
647 COMPLETED_UNIQUE, /* completion inserted, and it is a complete name and a unique match */
648 COMPLETE_BUT_NOT_UNIQUE /* completion inserted, it is a complete name but not unique */
649 } CommonPrefixResult;
651 /* Finds a common prefix based on the contents of the entry
652 * and mandatorily appends it
654 static CommonPrefixResult
655 append_common_prefix (GtkFileChooserEntry *chooser_entry,
657 gboolean show_errors)
659 gchar *common_prefix;
661 gboolean is_complete_not_unique;
662 gboolean prefix_expands_the_file_part;
664 CommonPrefixResult result = NO_MATCH;
665 gboolean have_result;
667 clear_completions (chooser_entry);
669 if (chooser_entry->completion_store == NULL)
673 if (!find_common_prefix (chooser_entry, &common_prefix, &unique_file, &is_complete_not_unique, &prefix_expands_the_file_part, &error))
675 g_error_free (error);
677 return INVALID_INPUT;
684 g_object_unref (unique_file);
686 if (prefix_expands_the_file_part)
687 result = COMPLETED_UNIQUE;
689 result = NOTHING_INSERTED_UNIQUE;
695 if (is_complete_not_unique)
697 result = COMPLETE_BUT_NOT_UNIQUE;
707 cursor_pos = gtk_editable_get_position (GTK_EDITABLE (chooser_entry));
709 pos = chooser_entry->file_part_pos;
711 if (prefix_expands_the_file_part)
713 chooser_entry->in_change = TRUE;
714 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
716 gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
719 chooser_entry->in_change = FALSE;
723 /* equivalent to cursor_pos + common_prefix_len); */
724 gtk_editable_select_region (GTK_EDITABLE (chooser_entry),
727 chooser_entry->has_completion = TRUE;
730 gtk_editable_set_position (GTK_EDITABLE (chooser_entry), pos);
732 else if (!have_result)
734 result = NOTHING_INSERTED_COMPLETE;
738 g_free (common_prefix);
755 gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
756 const gchar *new_text,
757 gint new_text_length,
760 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
764 old_text_len = gtk_entry_get_text_length (GTK_ENTRY (chooser_entry));
765 insert_pos = *position;
767 parent_editable_iface->do_insert_text (editable, new_text, new_text_length, position);
769 if (chooser_entry->in_change)
772 remove_completion_feedback (chooser_entry);
774 if ((chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN
775 || chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
776 && insert_pos == old_text_len)
777 start_autocompletion (chooser_entry);
781 clear_completions_if_not_in_change (GtkFileChooserEntry *chooser_entry)
783 if (chooser_entry->in_change)
786 clear_completions (chooser_entry);
790 gtk_file_chooser_entry_do_delete_text (GtkEditable *editable,
794 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
796 parent_editable_iface->do_delete_text (editable, start_pos, end_pos);
798 clear_completions_if_not_in_change (chooser_entry);
802 gtk_file_chooser_entry_set_position (GtkEditable *editable,
805 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
807 parent_editable_iface->set_position (editable, position);
809 clear_completions_if_not_in_change (chooser_entry);
813 gtk_file_chooser_entry_set_selection_bounds (GtkEditable *editable,
817 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
819 parent_editable_iface->set_selection_bounds (editable, start_pos, end_pos);
821 clear_completions_if_not_in_change (chooser_entry);
825 gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
827 GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
828 _gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
832 gtk_file_chooser_entry_unmap (GtkWidget *widget)
834 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
836 remove_completion_feedback (chooser_entry);
838 GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->unmap (widget);
842 completion_feedback_window_draw_cb (GtkWidget *widget,
846 /* Stolen from gtk_tooltip_paint_window() */
848 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
849 GtkStyleContext *context;
851 context = gtk_widget_get_style_context (chooser_entry->completion_feedback_window);
853 gtk_render_background (context, cr, 0, 0,
854 gtk_widget_get_allocated_width (widget),
855 gtk_widget_get_allocated_height (widget));
856 gtk_render_frame (context, cr, 0, 0,
857 gtk_widget_get_allocated_width (widget),
858 gtk_widget_get_allocated_height (widget));
864 set_invisible_mouse_cursor (GdkWindow *window)
869 display = gdk_window_get_display (window);
870 cursor = gdk_cursor_new_for_display (display, GDK_BLANK_CURSOR);
872 gdk_window_set_cursor (window, cursor);
874 g_object_unref (cursor);
878 completion_feedback_window_realize_cb (GtkWidget *widget,
881 /* We hide the mouse cursor inside the completion feedback window, since
882 * GtkEntry hides the cursor when the user types. We don't want the cursor to
883 * come back if the completion feedback ends up where the mouse is.
885 set_invisible_mouse_cursor (gtk_widget_get_window (widget));
889 create_completion_feedback_window (GtkFileChooserEntry *chooser_entry)
891 /* Stolen from gtk_tooltip_init() */
892 GtkWidget *window, *label;
893 GtkStyleContext *context;
895 window = gtk_window_new (GTK_WINDOW_POPUP);
896 gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_TOOLTIP);
897 gtk_widget_set_app_paintable (window, TRUE);
898 gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
899 gtk_widget_set_name (window, "gtk-tooltip");
901 context = gtk_widget_get_style_context (window);
902 gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOOLTIP);
904 g_signal_connect (window, "draw",
905 G_CALLBACK (completion_feedback_window_draw_cb), chooser_entry);
906 g_signal_connect (window, "realize",
907 G_CALLBACK (completion_feedback_window_realize_cb), chooser_entry);
908 /* FIXME: connect to motion-notify-event, and *show* the cursor when the mouse moves */
910 label = gtk_label_new (NULL);
911 gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
912 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
913 /* FIXME: don't hardcode this */
914 gtk_widget_set_margin_left (label, 6);
915 gtk_widget_set_margin_right (label, 6);
916 gtk_widget_set_margin_top (label, 6);
917 gtk_widget_set_margin_bottom (label, 6);
918 gtk_container_add (GTK_CONTAINER (window), label);
919 gtk_widget_show (label);
921 chooser_entry->completion_feedback_window = window;
922 chooser_entry->completion_feedback_label = label;
926 completion_feedback_timeout_cb (gpointer data)
928 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
930 chooser_entry->completion_feedback_timeout_id = 0;
932 remove_completion_feedback (chooser_entry);
937 install_completion_feedback_timer (GtkFileChooserEntry *chooser_entry)
939 if (chooser_entry->completion_feedback_timeout_id != 0)
940 g_source_remove (chooser_entry->completion_feedback_timeout_id);
942 chooser_entry->completion_feedback_timeout_id = gdk_threads_add_timeout (COMPLETION_FEEDBACK_TIMEOUT_MS,
943 completion_feedback_timeout_cb,
947 /* Gets the x position of the text cursor in the entry, in widget coordinates */
949 get_entry_cursor_x (GtkFileChooserEntry *chooser_entry,
952 /* FIXME: see the docs for gtk_entry_get_layout_offsets(). As an exercise for
953 * the reader, you have to implement support for the entry's scroll offset and
954 * RTL layouts and all the fancy Pango stuff.
958 gint layout_x, layout_y;
960 PangoRectangle strong_pos;
961 gint start_pos, end_pos;
963 layout = gtk_entry_get_layout (GTK_ENTRY (chooser_entry));
965 gtk_entry_get_layout_offsets (GTK_ENTRY (chooser_entry), &layout_x, &layout_y);
967 gtk_editable_get_selection_bounds (GTK_EDITABLE (chooser_entry), &start_pos, &end_pos);
968 layout_index = gtk_entry_text_index_to_layout_index (GTK_ENTRY (chooser_entry),
972 pango_layout_get_cursor_pos (layout, layout_index, &strong_pos, NULL);
974 *x_ret = layout_x + strong_pos.x / PANGO_SCALE;
978 show_completion_feedback_window (GtkFileChooserEntry *chooser_entry)
980 /* More or less stolen from gtk_tooltip_position() */
982 GtkRequisition feedback_req;
983 GtkWidget *widget = GTK_WIDGET (chooser_entry);
984 gint entry_x, entry_y;
986 GtkAllocation entry_allocation;
987 int feedback_x, feedback_y;
989 gtk_widget_get_preferred_size (chooser_entry->completion_feedback_window,
990 &feedback_req, NULL);
992 gdk_window_get_origin (gtk_widget_get_window (widget), &entry_x, &entry_y);
993 gtk_widget_get_allocation (widget, &entry_allocation);
995 get_entry_cursor_x (chooser_entry, &cursor_x);
997 /* FIXME: fit to the screen if we bump on the screen's edge */
998 /* cheap "half M-width", use height as approximation of character em-size */
999 feedback_x = entry_x + cursor_x + entry_allocation.height / 2;
1000 feedback_y = entry_y + (entry_allocation.height - feedback_req.height) / 2;
1002 gtk_window_move (GTK_WINDOW (chooser_entry->completion_feedback_window), feedback_x, feedback_y);
1003 gtk_widget_show (chooser_entry->completion_feedback_window);
1005 install_completion_feedback_timer (chooser_entry);
1009 pop_up_completion_feedback (GtkFileChooserEntry *chooser_entry,
1010 const gchar *feedback)
1012 if (chooser_entry->completion_feedback_window == NULL)
1013 create_completion_feedback_window (chooser_entry);
1015 gtk_label_set_text (GTK_LABEL (chooser_entry->completion_feedback_label), feedback);
1017 show_completion_feedback_window (chooser_entry);
1021 remove_completion_feedback (GtkFileChooserEntry *chooser_entry)
1023 if (chooser_entry->completion_feedback_window)
1024 gtk_widget_destroy (chooser_entry->completion_feedback_window);
1026 chooser_entry->completion_feedback_window = NULL;
1027 chooser_entry->completion_feedback_label = NULL;
1029 if (chooser_entry->completion_feedback_timeout_id != 0)
1031 g_source_remove (chooser_entry->completion_feedback_timeout_id);
1032 chooser_entry->completion_feedback_timeout_id = 0;
1037 explicitly_complete (GtkFileChooserEntry *chooser_entry)
1039 CommonPrefixResult result;
1041 g_assert (chooser_entry->current_folder_loaded);
1043 /* FIXME: see what Emacs does in case there is no common prefix, or there is more than one match:
1045 * - If there is a common prefix, insert it (done)
1046 * - If there is no common prefix, pop up the suggestion window
1047 * - If there are no matches at all, beep and bring up a tooltip (done)
1048 * - If the suggestion window is already up, scroll it
1050 result = append_common_prefix (chooser_entry, FALSE, TRUE);
1055 /* We already beeped in append_common_prefix(); do nothing here */
1059 beep (chooser_entry);
1060 /* translators: this text is shown when there are no completions
1061 * for something the user typed in a file chooser entry
1063 pop_up_completion_feedback (chooser_entry, _("No match"));
1066 case NOTHING_INSERTED_COMPLETE:
1067 /* FIXME: pop up the suggestion window or scroll it */
1070 case NOTHING_INSERTED_UNIQUE:
1071 /* translators: this text is shown when there is exactly one completion
1072 * for something the user typed in a file chooser entry
1074 pop_up_completion_feedback (chooser_entry, _("Sole completion"));
1081 case COMPLETED_UNIQUE:
1085 case COMPLETE_BUT_NOT_UNIQUE:
1086 /* translators: this text is shown when the text in a file chooser
1087 * entry is a complete filename, but could be continued to find
1090 pop_up_completion_feedback (chooser_entry, _("Complete, but not unique"));
1094 g_assert_not_reached ();
1099 start_explicit_completion (GtkFileChooserEntry *chooser_entry)
1101 RefreshStatus status;
1105 status = refresh_current_folder_and_file_part (chooser_entry, REFRESH_UP_TO_CURSOR_POSITION);
1112 g_assert (chooser_entry->current_folder_file != NULL);
1114 if (chooser_entry->current_folder_loaded)
1115 explicitly_complete (chooser_entry);
1118 chooser_entry->load_complete_action = LOAD_COMPLETE_EXPLICIT_COMPLETION;
1120 /* Translators: this text is shown while the system is searching
1121 * for possible completions for filenames in a file chooser entry. */
1122 pop_up_completion_feedback (chooser_entry, _("Completing..."));
1127 case REFRESH_INVALID_INPUT:
1129 /* Translators: this is shown in the feedback for Tab-completion in a file
1130 * chooser's text entry, when the user enters an invalid path. */
1131 feedback_msg = _("Invalid path");
1134 case REFRESH_INCOMPLETE_HOSTNAME:
1137 if (chooser_entry->local_only)
1139 /* hostnames in a local_only file chooser? user error */
1141 /* Translators: this is shown in the feedback for Tab-completion in a
1142 * file chooser's text entry when the user enters something like
1143 * "sftp://blahblah" in an app that only supports local filenames. */
1144 feedback_msg = _("Only local files may be selected");
1148 /* Another option is to complete the hostname based on the remote volumes that are mounted */
1150 /* Translators: this is shown in the feedback for Tab-completion in a
1151 * file chooser's text entry when the user hasn't entered the first '/'
1152 * after a hostname and yet hits Tab (such as "sftp://blahblah[Tab]") */
1153 feedback_msg = _("Incomplete hostname; end it with '/'");
1158 case REFRESH_NONEXISTENT:
1161 /* Translators: this is shown in the feedback for Tab-completion in a file
1162 * chooser's text entry when the user enters a path that does not exist
1163 * and then hits Tab */
1164 feedback_msg = _("Path does not exist");
1167 case REFRESH_NOT_LOCAL:
1169 feedback_msg = _("Only local files may be selected");
1173 g_assert_not_reached ();
1179 g_assert (chooser_entry->current_folder_file == NULL);
1181 beep (chooser_entry);
1182 pop_up_completion_feedback (chooser_entry, feedback_msg);
1183 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
1188 gtk_file_chooser_entry_key_press_event (GtkWidget *widget,
1191 GtkFileChooserEntry *chooser_entry;
1192 GtkEditable *editable;
1194 GdkModifierType state;
1195 gboolean control_pressed;
1197 chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
1198 editable = GTK_EDITABLE (widget);
1199 entry = GTK_ENTRY (widget);
1201 if (!chooser_entry->eat_tabs)
1202 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
1204 control_pressed = FALSE;
1206 if (gtk_get_current_event_state (&state))
1208 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
1209 control_pressed = TRUE;
1212 /* This is a bit evil -- it makes Tab never leave the entry. It basically
1213 * makes it 'safe' for people to hit. */
1214 if (event->keyval == GDK_KEY_Tab && !control_pressed)
1216 if (chooser_entry->has_completion)
1217 gtk_editable_set_position (editable, gtk_entry_get_text_length (entry));
1219 start_explicit_completion (chooser_entry);
1224 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->key_press_event (widget, event);
1229 gtk_file_chooser_entry_focus_out_event (GtkWidget *widget,
1230 GdkEventFocus *event)
1232 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
1234 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
1236 return GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->focus_out_event (widget, event);
1240 commit_completion_and_refresh (GtkFileChooserEntry *chooser_entry)
1242 if (chooser_entry->has_completion)
1244 gtk_editable_set_position (GTK_EDITABLE (chooser_entry),
1245 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)));
1248 /* Here we ignore the result of refresh_current_folder_and_file_part(); there is nothing we can do with it */
1249 refresh_current_folder_and_file_part (chooser_entry, REFRESH_WHOLE_TEXT);
1253 gtk_file_chooser_entry_activate (GtkEntry *entry)
1255 GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (entry);
1257 commit_completion_and_refresh (chooser_entry);
1258 GTK_ENTRY_CLASS (_gtk_file_chooser_entry_parent_class)->activate (entry);
1262 discard_completion_store (GtkFileChooserEntry *chooser_entry)
1264 if (!chooser_entry->completion_store)
1267 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
1268 g_object_unref (chooser_entry->completion_store);
1269 chooser_entry->completion_store = NULL;
1273 completion_store_set (GtkFileSystemModel *model,
1283 g_value_set_object (value, file);
1285 case DISPLAY_NAME_COLUMN:
1286 if (_gtk_file_info_consider_as_directory (info))
1287 g_value_take_string (value, g_strconcat (g_file_info_get_display_name (info), G_DIR_SEPARATOR_S, NULL));
1289 g_value_set_string (value, g_file_info_get_display_name (info));
1292 g_assert_not_reached ();
1299 /* Fills the completion store from the contents of the current folder */
1301 populate_completion_store (GtkFileChooserEntry *chooser_entry)
1303 discard_completion_store (chooser_entry);
1305 chooser_entry->completion_store = GTK_TREE_MODEL (
1306 _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
1307 "standard::name,standard::display-name,standard::type",
1308 completion_store_set,
1313 g_signal_connect (chooser_entry->completion_store, "finished-loading",
1314 G_CALLBACK (finished_loading_cb), chooser_entry);
1316 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
1317 DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
1319 gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
1320 chooser_entry->completion_store);
1323 /* When we finish loading the current folder, this function should get called to
1324 * perform the deferred autocompletion or explicit completion.
1327 perform_load_complete_action (GtkFileChooserEntry *chooser_entry)
1329 switch (chooser_entry->load_complete_action)
1331 case LOAD_COMPLETE_NOTHING:
1334 case LOAD_COMPLETE_AUTOCOMPLETE:
1335 autocomplete (chooser_entry);
1338 case LOAD_COMPLETE_EXPLICIT_COMPLETION:
1339 explicitly_complete (chooser_entry);
1343 g_assert_not_reached ();
1346 chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
1350 finish_folder_load (GtkFileChooserEntry *chooser_entry)
1352 perform_load_complete_action (chooser_entry);
1354 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
1357 /* Callback when the current folder finishes loading */
1359 finished_loading_cb (GtkFileSystemModel *model,
1361 GtkFileChooserEntry *chooser_entry)
1363 chooser_entry->current_folder_loaded = TRUE;
1367 LoadCompleteAction old_load_complete_action;
1369 old_load_complete_action = chooser_entry->load_complete_action;
1371 discard_completion_store (chooser_entry);
1372 clear_completions (chooser_entry);
1374 if (old_load_complete_action == LOAD_COMPLETE_EXPLICIT_COMPLETION)
1376 /* Since this came from explicit user action (Tab completion), we'll present errors visually */
1378 beep (chooser_entry);
1379 pop_up_completion_feedback (chooser_entry, error->message);
1385 finish_folder_load (chooser_entry);
1388 static RefreshStatus
1389 reload_current_folder (GtkFileChooserEntry *chooser_entry,
1392 g_assert (folder_file != NULL);
1394 if (chooser_entry->current_folder_file
1395 && g_file_equal (folder_file, chooser_entry->current_folder_file))
1398 if (chooser_entry->current_folder_file)
1400 discard_loading_and_current_folder_file (chooser_entry);
1403 if (chooser_entry->local_only
1404 && !g_file_is_native (folder_file))
1405 return REFRESH_NOT_LOCAL;
1407 chooser_entry->current_folder_file = g_object_ref (folder_file);
1408 chooser_entry->current_folder_loaded = FALSE;
1410 populate_completion_store (chooser_entry);
1415 static RefreshStatus
1416 refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
1417 RefreshMode refresh_mode)
1419 GtkEditable *editable;
1424 gsize total_len, file_part_len;
1427 RefreshStatus result;
1429 editable = GTK_EDITABLE (chooser_entry);
1431 switch (refresh_mode)
1433 case REFRESH_UP_TO_CURSOR_POSITION:
1434 end_pos = gtk_editable_get_position (editable);
1437 case REFRESH_WHOLE_TEXT:
1438 end_pos = gtk_entry_get_text_length (GTK_ENTRY (chooser_entry));
1442 g_assert_not_reached ();
1443 return REFRESH_INVALID_INPUT;
1446 text = gtk_editable_get_chars (editable, 0, end_pos);
1449 if (!gtk_file_chooser_entry_parse (chooser_entry,
1450 text, &folder_file, &file_part, &error))
1452 folder_file = g_object_ref (chooser_entry->base_folder);
1454 if (g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_NONEXISTENT))
1455 result = REFRESH_NONEXISTENT;
1457 result = REFRESH_INVALID_INPUT;
1460 g_error_free (error);
1462 file_part = g_strdup ("");
1467 g_assert (folder_file != NULL);
1469 file_part_len = strlen (file_part);
1470 total_len = strlen (text);
1471 if (total_len > file_part_len)
1472 file_part_pos = g_utf8_strlen (text, total_len - file_part_len);
1476 result = REFRESH_OK;
1481 g_free (chooser_entry->file_part);
1483 chooser_entry->file_part = file_part;
1484 chooser_entry->file_part_pos = file_part_pos;
1486 if (result == REFRESH_OK)
1488 result = reload_current_folder (chooser_entry, folder_file);
1492 discard_loading_and_current_folder_file (chooser_entry);
1496 g_object_unref (folder_file);
1498 g_assert (/* we are OK and we have a current folder file and (loading process or folder handle)... */
1499 ((result == REFRESH_OK)
1500 && (chooser_entry->current_folder_file != NULL))
1501 /* ... OR we have an error, and we don't have a current folder file nor a loading process nor a folder handle */
1502 || ((result != REFRESH_OK)
1503 && (chooser_entry->current_folder_file == NULL)));
1509 autocomplete (GtkFileChooserEntry *chooser_entry)
1511 if (!(chooser_entry->current_folder_loaded
1512 && gtk_editable_get_position (GTK_EDITABLE (chooser_entry)) == gtk_entry_get_text_length (GTK_ENTRY (chooser_entry))))
1515 append_common_prefix (chooser_entry, TRUE, FALSE);
1519 start_autocompletion (GtkFileChooserEntry *chooser_entry)
1521 RefreshStatus status;
1523 status = refresh_current_folder_and_file_part (chooser_entry, REFRESH_UP_TO_CURSOR_POSITION);
1528 g_assert (chooser_entry->current_folder_file != NULL);
1530 if (chooser_entry->current_folder_loaded)
1531 autocomplete (chooser_entry);
1533 chooser_entry->load_complete_action = LOAD_COMPLETE_AUTOCOMPLETE;
1537 case REFRESH_INVALID_INPUT:
1538 case REFRESH_INCOMPLETE_HOSTNAME:
1539 case REFRESH_NONEXISTENT:
1540 case REFRESH_NOT_LOCAL:
1541 /* We don't beep or anything, since this is autocompletion - the user
1542 * didn't request any action explicitly.
1547 g_assert_not_reached ();
1553 insert_text_callback (GtkFileChooserEntry *chooser_entry,
1554 const gchar *new_text,
1555 gint new_text_length,
1559 const gchar *colon = memchr (new_text, ':', new_text_length);
1562 /* Disallow these characters altogether */
1563 for (i = 0; i < new_text_length; i++)
1565 if (new_text[i] == '<' ||
1566 new_text[i] == '>' ||
1567 new_text[i] == '"' ||
1568 new_text[i] == '|' ||
1569 new_text[i] == '*' ||
1574 if (i < new_text_length ||
1575 /* Disallow entering text that would cause a colon to be anywhere except
1576 * after a drive letter.
1579 *position + (colon - new_text) != 1) ||
1580 (new_text_length > 0 &&
1582 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
1583 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':'))
1585 gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
1586 g_signal_stop_emission_by_name (chooser_entry, "insert_text");
1594 delete_text_callback (GtkFileChooserEntry *chooser_entry,
1599 /* If deleting a drive letter, delete the colon, too */
1600 if (start_pos == 0 && end_pos == 1 &&
1601 gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)) >= 2 &&
1602 gtk_entry_get_text (GTK_ENTRY (chooser_entry))[1] == ':')
1604 g_signal_handlers_block_by_func (chooser_entry,
1605 G_CALLBACK (delete_text_callback),
1607 gtk_editable_delete_text (GTK_EDITABLE (chooser_entry), 0, 1);
1608 g_signal_handlers_unblock_by_func (chooser_entry,
1609 G_CALLBACK (delete_text_callback),
1616 * _gtk_file_chooser_entry_new:
1617 * @eat_tabs: If %FALSE, allow focus navigation with the tab key.
1619 * Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
1620 * is an internal implementation widget for the GTK+ file chooser
1621 * which is an entry with completion with respect to a
1622 * #GtkFileSystem object.
1624 * Return value: the newly created #GtkFileChooserEntry
1627 _gtk_file_chooser_entry_new (gboolean eat_tabs)
1629 GtkFileChooserEntry *chooser_entry;
1631 chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
1632 chooser_entry->eat_tabs = (eat_tabs != FALSE);
1634 return GTK_WIDGET (chooser_entry);
1638 * _gtk_file_chooser_entry_set_base_folder:
1639 * @chooser_entry: a #GtkFileChooserEntry
1640 * @file: file for a folder in the chooser entries current file system.
1642 * Sets the folder with respect to which completions occur.
1645 _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
1649 g_object_ref (file);
1651 file = g_file_new_for_path (g_get_home_dir ());
1653 if (g_file_equal (chooser_entry->base_folder, file))
1655 g_object_unref (file);
1659 if (chooser_entry->base_folder)
1660 g_object_unref (chooser_entry->base_folder);
1662 chooser_entry->base_folder = file;
1664 clear_completions (chooser_entry);
1668 * _gtk_file_chooser_entry_get_current_folder:
1669 * @chooser_entry: a #GtkFileChooserEntry
1671 * Gets the current folder for the #GtkFileChooserEntry. If the
1672 * user has only entered a filename, this will be in the base folder
1673 * (see _gtk_file_chooser_entry_set_base_folder()), but if the
1674 * user has entered a relative or absolute path, then it will
1675 * be different. If the user has entered unparsable text, or text which
1676 * the entry cannot handle, this will return %NULL.
1678 * Return value: the file for the current folder - this value is owned by the
1679 * chooser entry and must not be modified or freed.
1682 _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
1684 commit_completion_and_refresh (chooser_entry);
1685 return chooser_entry->current_folder_file;
1689 * _gtk_file_chooser_entry_get_file_part:
1690 * @chooser_entry: a #GtkFileChooserEntry
1692 * Gets the non-folder portion of whatever the user has entered
1693 * into the file selector. What is returned is a UTF-8 string,
1694 * and if a filename path is needed, g_file_get_child_for_display_name()
1697 * Return value: the entered filename - this value is owned by the
1698 * chooser entry and must not be modified or freed.
1701 _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
1703 commit_completion_and_refresh (chooser_entry);
1704 return chooser_entry->file_part;
1708 * _gtk_file_chooser_entry_set_file_part:
1709 * @chooser_entry: a #GtkFileChooserEntry
1710 * @file_part: text to display in the entry, in UTF-8
1712 * Sets the current text shown in the file chooser entry.
1715 _gtk_file_chooser_entry_set_file_part (GtkFileChooserEntry *chooser_entry,
1716 const gchar *file_part)
1718 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
1720 chooser_entry->in_change = TRUE;
1721 clear_completions (chooser_entry);
1722 gtk_entry_set_text (GTK_ENTRY (chooser_entry), file_part);
1723 chooser_entry->in_change = FALSE;
1728 * _gtk_file_chooser_entry_set_action:
1729 * @chooser_entry: a #GtkFileChooserEntry
1730 * @action: the action which is performed by the file selector using this entry
1732 * Sets action which is performed by the file selector using this entry.
1733 * The #GtkFileChooserEntry will use different completion strategies for
1734 * different actions.
1737 _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
1738 GtkFileChooserAction action)
1740 g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
1742 if (chooser_entry->action != action)
1744 GtkEntryCompletion *comp;
1746 chooser_entry->action = action;
1748 comp = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
1750 /* FIXME: do we need to actually set the following? */
1754 case GTK_FILE_CHOOSER_ACTION_OPEN:
1755 case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
1756 gtk_entry_completion_set_popup_single_match (comp, FALSE);
1758 case GTK_FILE_CHOOSER_ACTION_SAVE:
1759 case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
1760 gtk_entry_completion_set_popup_single_match (comp, TRUE);
1768 * _gtk_file_chooser_entry_get_action:
1769 * @chooser_entry: a #GtkFileChooserEntry
1771 * Gets the action for this entry.
1773 * Returns: the action
1775 GtkFileChooserAction
1776 _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry)
1778 g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry),
1779 GTK_FILE_CHOOSER_ACTION_OPEN);
1781 return chooser_entry->action;
1785 _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
1791 if (chooser_entry->completion_store == NULL ||
1792 !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
1797 info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
1800 return _gtk_file_info_consider_as_directory (info);
1805 * _gtk_file_chooser_entry_select_filename:
1806 * @chooser_entry: a #GtkFileChooserEntry
1808 * Selects the filename (without the extension) for user edition.
1811 _gtk_file_chooser_entry_select_filename (GtkFileChooserEntry *chooser_entry)
1813 const gchar *str, *ext;
1816 if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SAVE)
1818 str = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
1819 ext = g_strrstr (str, ".");
1822 len = g_utf8_pointer_to_offset (str, ext);
1825 gtk_editable_select_region (GTK_EDITABLE (chooser_entry), 0, (gint) len);
1829 _gtk_file_chooser_entry_set_local_only (GtkFileChooserEntry *chooser_entry,
1830 gboolean local_only)
1832 chooser_entry->local_only = local_only;
1833 clear_completions (chooser_entry);
1837 _gtk_file_chooser_entry_get_local_only (GtkFileChooserEntry *chooser_entry)
1839 return chooser_entry->local_only;