[gtk+/filechooserentry: 34/51] filechooserentry: Get rid of RefreshMode



commit 994b87b75822dc8cf19c32fa228c2aafcf55b8ee
Author: Benjamin Otte <otte redhat com>
Date:   Sun Nov 6 03:52:41 2011 +0100

    filechooserentry: Get rid of RefreshMode
    
    Instead, pass the text to use to refresh_current_folder_and_file_part().
    This also gets rid of the problem introduced earlier that the position
    is not properly updated in do_insert_text() and therefor the completion
    is wrong.

 gtk/gtkfilechooserentry.c |   47 +++++++++++---------------------------------
 1 files changed, 12 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c
index af28d80..7a9b363 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -141,13 +141,8 @@ static gboolean completion_match_func     (GtkEntryCompletion  *comp,
 					   GtkTreeIter         *iter,
 					   gpointer             data);
 
-typedef enum {
-  REFRESH_UP_TO_CURSOR_POSITION,
-  REFRESH_WHOLE_TEXT
-} RefreshMode;
-
 static RefreshStatus refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
-						  RefreshMode refresh_mode);
+						           const char          *text);
 static void finished_loading_cb (GtkFileSystemModel  *model,
                                  GError              *error,
 		                 GtkFileChooserEntry *chooser_entry);
@@ -750,6 +745,7 @@ gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
 				       gint        *position)
 {
   GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (editable);
+  char *text;
 
   parent_editable_iface->do_insert_text (editable, new_text, new_text_length, position);
 
@@ -757,7 +753,9 @@ gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
     return;
 
   remove_completion_feedback (chooser_entry);
-  refresh_current_folder_and_file_part (chooser_entry, REFRESH_UP_TO_CURSOR_POSITION);
+  text = gtk_editable_get_chars (editable, 0, *position);
+  refresh_current_folder_and_file_part (chooser_entry, text);
+  g_free (text);
 }
 
 static void
@@ -1083,9 +1081,12 @@ start_explicit_completion (GtkFileChooserEntry *chooser_entry)
 {
   RefreshStatus status;
   gboolean is_error;
-  char *feedback_msg;
+  char *feedback_msg, *text;
 
-  status = refresh_current_folder_and_file_part (chooser_entry, REFRESH_UP_TO_CURSOR_POSITION);
+  text = gtk_editable_get_chars (GTK_EDITABLE (chooser_entry),
+                                 0, gtk_editable_get_position (GTK_EDITABLE (chooser_entry)));
+  status = refresh_current_folder_and_file_part (chooser_entry, text);
+  g_free (text);
 
   is_error = FALSE;
 
@@ -1225,7 +1226,7 @@ static void
 commit_completion_and_refresh (GtkFileChooserEntry *chooser_entry)
 {
   /* Here we ignore the result of refresh_current_folder_and_file_part(); there is nothing we can do with it */
-  refresh_current_folder_and_file_part (chooser_entry, REFRESH_WHOLE_TEXT);
+  refresh_current_folder_and_file_part (chooser_entry, gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
 }
 
 static void
@@ -1404,11 +1405,8 @@ reload_current_folder (GtkFileChooserEntry *chooser_entry,
 
 static RefreshStatus
 refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
-				      RefreshMode          refresh_mode)
+				      const gchar *        text)
 {
-  GtkEditable *editable;
-  gint end_pos;
-  gchar *text;
   GFile *folder_file;
   gchar *file_part;
   gsize total_len, file_part_len;
@@ -1416,25 +1414,6 @@ refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
   GError *error;
   RefreshStatus result;
 
-  editable = GTK_EDITABLE (chooser_entry);
-
-  switch (refresh_mode)
-    {
-    case REFRESH_UP_TO_CURSOR_POSITION:
-      end_pos = gtk_editable_get_position (editable);
-      break;
-
-    case REFRESH_WHOLE_TEXT:
-      end_pos = gtk_entry_get_text_length (GTK_ENTRY (chooser_entry));
-      break;
-
-    default:
-      g_assert_not_reached ();
-      return REFRESH_INVALID_INPUT;
-    }
-
-  text = gtk_editable_get_chars (editable, 0, end_pos);
-
   error = NULL;
   if (!gtk_file_chooser_entry_parse (chooser_entry,
 			             text, &folder_file, &file_part, &error))
@@ -1473,8 +1452,6 @@ refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
   chooser_entry->file_part = file_part;
   chooser_entry->file_part_pos = file_part_pos;
 
-  g_free (text);
-
   if (result == REFRESH_OK)
     {
       result = reload_current_folder (chooser_entry, folder_file);



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