diff options
author | Federico Mena Quintero <federico@novell.com> | 2009-01-23 00:55:07 +0000 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2009-01-23 00:55:07 +0000 |
commit | 7fde4a8542f7c7bb93e8b29df21e3448c42ef79d (patch) | |
tree | fde62baf019fe6311f8cbc71ee42978bf6a15f1a /gtk | |
parent | a8b06ad56103ca7496971abaaeb4f5d85e7c33ed (diff) | |
download | gtk+-7fde4a8542f7c7bb93e8b29df21e3448c42ef79d.tar.gz |
GtkFileChooserEntry: fix the computation of 'complete but not unique' and appending a '/' to unique directory names
2009-01-22 Federico Mena Quintero <federico@novell.com>
Fix the computation of "complete but unique" in
GtkFileChooserEntry. Fix the case where "/" was not appended to a
unique directory name during explicit Tab completion.
* gtk/gtkfilechooserentry.c (maybe_append_separator_to_file):
Return whether anything was appended as well as the new string
itself.
(find_common_prefix): Oops, only turn on
is_complete_not_unique_ret if we had a unique match!
(append_common_prefix): If we appended a directory separator, we
*did* expand the common prefix, so we are not in the "nothing
inserted" case.
Signed-off-by: Federico Mena Quintero <federico@novell.com>
svn path=/trunk/; revision=22184
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkfilechooserentry.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c index 68d0624b25..36c405524b 100644 --- a/gtk/gtkfilechooserentry.c +++ b/gtk/gtkfilechooserentry.c @@ -146,7 +146,8 @@ static gboolean completion_match_func (GtkEntryCompletion *comp, gpointer data); static char *maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry, GFile *file, - gchar *display_name); + gchar *display_name, + gboolean *appended); typedef enum { REFRESH_UP_TO_CURSOR_POSITION, @@ -324,6 +325,7 @@ match_selected_callback (GtkEntryCompletion *completion, char *display_name; GFile *file; gint pos; + gboolean dummy; gtk_tree_model_get (model, iter, DISPLAY_NAME_COLUMN, &display_name, @@ -338,7 +340,7 @@ match_selected_callback (GtkEntryCompletion *completion, return FALSE; } - display_name = maybe_append_separator_to_file (chooser_entry, file, display_name); + display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy); pos = chooser_entry->file_part_pos; @@ -450,15 +452,18 @@ beep (GtkFileChooserEntry *chooser_entry) * return a new one if needed. Otherwise, it will return the old one. * You should be safe calling * - * display_name = maybe_append_separator_to_file (entry, file, display_name); + * display_name = maybe_append_separator_to_file (entry, file, display_name, &appended); * ... * g_free (display_name); */ static char * maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry, GFile *file, - gchar *display_name) + gchar *display_name, + gboolean *appended) { + *appended = FALSE; + if (!g_str_has_suffix (display_name, G_DIR_SEPARATOR_S) && file) { GFileInfo *info; @@ -471,6 +476,7 @@ maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry, { gchar *tmp = display_name; display_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL); + *appended = TRUE; g_free (tmp); } @@ -609,7 +615,7 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry, if (G_IS_DIR_SEPARATOR (display_name[len - 1])) len--; - if (strncmp (*common_prefix_ret, display_name, len) == 0) + if (*unique_file_ret == NULL && strncmp (*common_prefix_ret, display_name, len) == 0) *is_complete_not_unique_ret = TRUE; g_free (display_name); @@ -702,21 +708,23 @@ append_common_prefix (GtkFileChooserEntry *chooser_entry, if (unique_file) { if (!char_after_cursor_is_directory_separator (chooser_entry)) - common_prefix = maybe_append_separator_to_file (chooser_entry, - unique_file, - common_prefix); + { + gboolean appended; + + common_prefix = maybe_append_separator_to_file (chooser_entry, + unique_file, + common_prefix, + &appended); + if (appended) + prefix_expands_the_file_part = TRUE; + } g_object_unref (unique_file); - if (common_prefix) - { - if (prefix_expands_the_file_part) - result = COMPLETED_UNIQUE; - else - result = NOTHING_INSERTED_UNIQUE; - } + if (prefix_expands_the_file_part) + result = COMPLETED_UNIQUE; else - result = INVALID_INPUT; + result = NOTHING_INSERTED_UNIQUE; have_result = TRUE; } @@ -1322,8 +1330,9 @@ populate_completion_store (GtkFileChooserEntry *chooser_entry) { gchar *display_name = g_strdup (g_file_info_get_display_name (info)); GtkTreeIter iter; + gboolean dummy; - display_name = maybe_append_separator_to_file (chooser_entry, file, display_name); + display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy); gtk_list_store_append (chooser_entry->completion_store, &iter); gtk_list_store_set (chooser_entry->completion_store, &iter, |