]> Pileus Git - ~andy/gtk/commitdiff
filechooserentry: Add gtk_file_chooser_entry_get_completion_text()
authorBenjamin Otte <otte@redhat.com>
Mon, 7 Nov 2011 02:09:22 +0000 (03:09 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 16 Dec 2011 19:09:13 +0000 (20:09 +0100)
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

index af73ab18b8f110d0328556c821ff7ba45a55e25f..65968f8ba62baf81b0c8cfa8236b7ae85c9c4f95 100644 (file)
@@ -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,