[gtk+] filechooserentry: Do inline completion only when opening files



commit 640754e98b6a0a59fbfa9f35d03e0f096988a0a2
Author: Benjamin Otte <otte redhat com>
Date:   Fri Dec 16 18:47:42 2011 +0100

    filechooserentry: Do inline completion only when opening files
    
    When saving files, using <tab> is required. We don't want the UI
    randomly changing filenames from below us.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=663573

 gtk/gtkfilechooserentry.c |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c
index 3010c94..50d3462 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -432,13 +432,37 @@ gtk_file_chooser_entry_focus_out_event (GtkWidget     *widget,
 }
 
 static void
+update_inline_completion (GtkFileChooserEntry *chooser_entry)
+{
+  GtkEntryCompletion *completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
+
+  if (!chooser_entry->current_folder_loaded)
+    {
+      gtk_entry_completion_set_inline_completion (completion, FALSE);
+      return;
+    }
+
+  switch (chooser_entry->action)
+    {
+    case GTK_FILE_CHOOSER_ACTION_OPEN:
+    case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
+      gtk_entry_completion_set_inline_completion (completion, TRUE);
+      break;
+    case GTK_FILE_CHOOSER_ACTION_SAVE:
+    case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
+      gtk_entry_completion_set_inline_completion (completion, FALSE);
+      break;
+    }
+}
+
+static void
 discard_completion_store (GtkFileChooserEntry *chooser_entry)
 {
   if (!chooser_entry->completion_store)
     return;
 
   gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), NULL);
-  gtk_entry_completion_set_inline_completion (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)), FALSE);
+  update_inline_completion (chooser_entry);
   g_object_unref (chooser_entry->completion_store);
   chooser_entry->completion_store = NULL;
 }
@@ -529,7 +553,7 @@ finished_loading_cb (GtkFileSystemModel  *model,
   gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
 
   completion = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
-  gtk_entry_completion_set_inline_completion (completion, TRUE);
+  update_inline_completion (chooser_entry);
   gtk_entry_completion_complete (completion);
   gtk_entry_completion_insert_prefix (completion);
 }
@@ -822,6 +846,8 @@ _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
         _gtk_file_system_model_set_show_files (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
                                                action == GTK_FILE_CHOOSER_ACTION_OPEN ||
                                                action == GTK_FILE_CHOOSER_ACTION_SAVE);
+
+      update_inline_completion (chooser_entry);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]