[gtk+/gtk-2-24] filechooserbutton: Update the button/combo whenever the selection is changed programmatically



commit 6fb708775879699d430f639fb1f2d64f74e63ef7
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Mar 7 13:44:33 2013 -0600

    filechooserbutton: Update the button/combo whenever the selection is changed programmatically
    
    We didn't change it when the file chooser button's dialog was inactive, and so
    the actual file chooser button would not visually reflect the current selection.
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 gtk/gtkfilechooserbutton.c |   58 ++++++++++++++++++++++++++-----------------
 1 files changed, 35 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index a3ad36b..5e6ee29 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -568,6 +568,8 @@ gtk_file_chooser_button_set_current_folder (GtkFileChooser    *chooser,
 
       priv->current_folder_while_inactive = g_object_ref (file);
 
+      update_combo_box (button);
+
       g_signal_emit_by_name (button, "current-folder-changed");
 
       return TRUE;
@@ -616,6 +618,9 @@ gtk_file_chooser_button_select_file (GtkFileChooser *chooser,
 
       priv->selection_while_inactive = g_object_ref (file);
 
+      update_label_and_image (button);
+      update_combo_box (button);
+
       return TRUE;
     }
 }
@@ -642,6 +647,9 @@ gtk_file_chooser_button_unselect_file (GtkFileChooser *chooser,
              g_object_unref (priv->selection_while_inactive);
              priv->selection_while_inactive = NULL;
            }
+
+         update_label_and_image (button);
+         update_combo_box (button);
        }
     }
 }
@@ -664,41 +672,43 @@ gtk_file_chooser_button_unselect_all (GtkFileChooser *chooser)
        {
          g_object_unref (priv->selection_while_inactive);
          priv->selection_while_inactive = NULL;
+
+         update_label_and_image (button);
+         update_combo_box (button);
        }
     }
 }
 
-static GSList *
-gtk_file_chooser_button_get_files (GtkFileChooser *chooser)
+static GFile *
+get_selected_file (GtkFileChooserButton *button)
 {
-  GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
   GtkFileChooserButtonPrivate *priv = button->priv;
-  GtkFileChooser *delegate;
-
-  delegate = g_object_get_qdata (G_OBJECT (chooser),
-                                GTK_FILE_CHOOSER_DELEGATE_QUARK);
 
   if (priv->active)
-    return gtk_file_chooser_get_files (delegate);
+    return gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
   else
     {
-      GSList *result;
-
-      result = NULL;
-
       if (priv->selection_while_inactive)
-       result = g_slist_prepend (NULL, g_object_ref (priv->selection_while_inactive));
+       return g_object_ref (priv->selection_while_inactive);
       else if (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (priv->dialog)) == 
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
        {
          /* If there is no "real" selection in SELECT_FOLDER mode, then we'll just return
           * the current folder, since that is what GtkFileChooserDefault would do.
           */
          if (priv->current_folder_while_inactive)
-           result = g_slist_prepend (NULL, g_object_ref (priv->current_folder_while_inactive));
+           return g_object_ref (priv->current_folder_while_inactive);
        }
-
-      return result;
     }
+
+  return NULL;
+}
+
+static GSList *
+gtk_file_chooser_button_get_files (GtkFileChooser *chooser)
+{
+  GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (chooser);
+
+  return g_slist_prepend (NULL, get_selected_file (button));
 }
 
 static gboolean
@@ -2327,12 +2337,12 @@ update_combo_box (GtkFileChooserButton *button)
   GtkTreeIter iter;
   gboolean row_found;
 
-  gtk_tree_model_get_iter_first (priv->filter_model, &iter);
-
-  file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
+  file = get_selected_file (button);
 
   row_found = FALSE;
 
+  gtk_tree_model_get_iter_first (priv->filter_model, &iter);
+
   do
     {
       gchar type;
@@ -2451,7 +2461,8 @@ update_label_and_image (GtkFileChooserButton *button)
   gchar *label_text;
   GFile *file;
 
-  file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
+  file = get_selected_file (button);
+
   label_text = NULL;
 
   if (priv->update_button_cancellable)
@@ -2490,7 +2501,7 @@ update_label_and_image (GtkFileChooserButton *button)
           _gtk_file_system_volume_unref (volume);
 
           if (label_text)
-            goto out;
+             goto out;
         }
 
       if (g_file_is_native (file))
@@ -2513,11 +2524,12 @@ update_label_and_image (GtkFileChooserButton *button)
           if (pixbuf)
             g_object_unref (pixbuf);
         }
-
-      g_object_unref (file);
     }
 out:
 
+  if (file)
+    g_object_unref (file);
+
   if (label_text)
     {
       gtk_label_set_text (GTK_LABEL (priv->label), label_text);


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