[gtk+] filechooserentry: Add gtk_file_chooser_entry_get_completion_text()



commit d3fd759f779e10419f8b2aa5e9b43393178ca67b
Author: Benjamin Otte <otte redhat com>
Date:   Mon Nov 7 03:09:22 2011 +0100

    filechooserentry: Add gtk_file_chooser_entry_get_completion_text()
    
    This returns the text that should be completed on. As this is somewhat
    tricky to compute (and in fact one place did it wrong), let's make it a
    function.

 gtk/gtkfilechooserentry.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkfilechooserentry.c b/gtk/gtkfilechooserentry.c
index af73ab1..65968f8 100644
--- a/gtk/gtkfilechooserentry.c
+++ b/gtk/gtkfilechooserentry.c
@@ -127,13 +127,22 @@ static void finished_loading_cb (GtkFileSystemModel  *model,
 
 G_DEFINE_TYPE (GtkFileChooserEntry, _gtk_file_chooser_entry, GTK_TYPE_ENTRY)
 
+static char *
+gtk_file_chooser_entry_get_completion_text (GtkFileChooserEntry *chooser_entry)
+{
+  GtkEditable *editable = GTK_EDITABLE (chooser_entry);
+  int start, end;
+
+  gtk_editable_get_selection_bounds (editable, &start, &end);
+  return gtk_editable_get_chars (editable, 0, MIN (start, end));
+}
+
 static void
 gtk_file_chooser_entry_dispatch_properties_changed (GObject     *object,
                                                     guint        n_pspecs,
                                                     GParamSpec **pspecs)
 {
   GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
-  GtkEditable *editable = GTK_EDITABLE (object);
   guint i;
 
   G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispatch_properties_changed (object, n_pspecs, pspecs);
@@ -151,12 +160,10 @@ gtk_file_chooser_entry_dispatch_properties_changed (GObject     *object,
           pspecs[i]->name == I_("text"))
         {
           char *text;
-          int start, end;
 
           chooser_entry->load_complete_action = LOAD_COMPLETE_NOTHING;
 
-          gtk_editable_get_selection_bounds (editable, &start, &end);
-          text = gtk_editable_get_chars (editable, 0, MIN (start, end));
+          text = gtk_file_chooser_entry_get_completion_text (chooser_entry);
           refresh_current_folder_and_file_part (chooser_entry, text);
           g_free (text);
 
@@ -509,7 +516,6 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
 		    gboolean             *prefix_expands_the_file_part_ret,
 		    GError              **error)
 {
-  GtkEditable *editable;
   GtkTreeIter iter;
   gboolean parsed;
   gboolean valid;
@@ -522,9 +528,7 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
   *is_complete_not_unique_ret = FALSE;
   *prefix_expands_the_file_part_ret = FALSE;
 
-  editable = GTK_EDITABLE (chooser_entry);
-
-  text_up_to_cursor = gtk_editable_get_chars (editable, 0, gtk_editable_get_position (editable));
+  text_up_to_cursor = gtk_file_chooser_entry_get_completion_text (chooser_entry);
 
   parsed = gtk_file_chooser_entry_parse (chooser_entry,
                                          text_up_to_cursor,



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