filechooserbutton: Don't ever use gtk_file_chooser_get_files()

The file chooser button only supports single-selection modes, so
switch the code to a simpler gtk_file_chooser_get_file() to avoid
dealing with GSLists of a single file.
Signed-off-by: Federico Mena Quintero's avatarFederico Mena Quintero <federico@gnome.org>
parent a41b73fb
......@@ -2346,13 +2346,13 @@ static void
update_combo_box (GtkFileChooserButton *button)
{
GtkFileChooserButtonPrivate *priv = button->priv;
GSList *files;
GFile *file;
GtkTreeIter iter;
gboolean row_found;
gtk_tree_model_get_iter_first (priv->filter_model, &iter);
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->dialog));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
row_found = FALSE;
......@@ -2375,9 +2375,7 @@ update_combo_box (GtkFileChooserButton *button)
case ROW_TYPE_SHORTCUT:
case ROW_TYPE_BOOKMARK:
case ROW_TYPE_CURRENT_FOLDER:
row_found = (files &&
files->data &&
g_file_equal (data, files->data));
row_found = (file && g_file_equal (data, file));
break;
case ROW_TYPE_VOLUME:
{
......@@ -2386,9 +2384,7 @@ update_combo_box (GtkFileChooserButton *button)
base_file = _gtk_file_system_volume_get_root (data);
if (base_file)
{
row_found = (files &&
files->data &&
g_file_equal (base_file, files->data));
row_found = (file && g_file_equal (base_file, file));
g_object_unref (base_file);
}
}
......@@ -2410,12 +2406,12 @@ update_combo_box (GtkFileChooserButton *button)
while (!row_found && gtk_tree_model_iter_next (priv->filter_model, &iter));
/* If it hasn't been found already, update & select the current-folder row. */
if (!row_found && files && files->data)
if (!row_found && file)
{
GtkTreeIter filter_iter;
gint pos;
model_update_current_folder (button, files->data);
model_update_current_folder (button, file);
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter_model));
pos = model_get_type_position (button, ROW_TYPE_CURRENT_FOLDER);
......@@ -2429,8 +2425,8 @@ update_combo_box (GtkFileChooserButton *button)
g_signal_handler_unblock (priv->combo_box, priv->combo_box_changed_id);
}
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
g_slist_free (files);
if (file)
g_object_unref (file);
}
/* Button */
......@@ -2476,9 +2472,9 @@ update_label_and_image (GtkFileChooserButton *button)
{
GtkFileChooserButtonPrivate *priv = button->priv;
gchar *label_text;
GSList *files;
GFile *file;
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->dialog));
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
label_text = NULL;
if (priv->update_button_cancellable)
......@@ -2487,13 +2483,10 @@ update_label_and_image (GtkFileChooserButton *button)
priv->update_button_cancellable = NULL;
}
if (files && files->data)
if (file)
{
GFile *file;
GtkFileSystemVolume *volume = NULL;
file = files->data;
volume = _gtk_file_system_get_volume_for_file (priv->fs, file);
if (volume)
{
......@@ -2543,10 +2536,10 @@ update_label_and_image (GtkFileChooserButton *button)
if (pixbuf)
g_object_unref (pixbuf);
}
g_object_unref (file);
}
out:
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
g_slist_free (files);
if (label_text)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment