[gtk+] GtkFileChooser: Make preview update more understandable
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkFileChooser: Make preview update more understandable
- Date: Sun, 19 Oct 2014 21:56:57 +0000 (UTC)
commit f678e48a08a376cbed060b52cd9746febf44c6cc
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Oct 19 17:54:28 2014 -0400
GtkFileChooser: Make preview update more understandable
Implement Federico's suggestion:
In single-selection mode, just use the selected row,
In multi-selection mode, use the cursor row as long as it is
in the selection.
https://bugzilla.gnome.org/show_bug.cgi?id=154709
gtk/gtkfilechooserwidget.c | 45 +++++++++++++++++++++++++++++++++++++------
1 files changed, 38 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 404ca8d..984aaf0 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -496,11 +496,13 @@ static gboolean list_select_func (GtkTreeSelection *selection,
gpointer data);
static void list_selection_changed (GtkTreeSelection *tree_selection,
- GtkFileChooserWidget *impl);
+ GtkFileChooserWidget *impl);
static void list_row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
- GtkFileChooserWidget *impl);
+ GtkFileChooserWidget *impl);
+static void list_cursor_changed (GtkTreeView *treeview,
+ GtkFileChooserWidget *impl);
static void path_bar_clicked (GtkPathBar *path_bar,
GFile *file,
@@ -6571,24 +6573,45 @@ static void
check_preview_change (GtkFileChooserWidget *impl)
{
GtkFileChooserWidgetPrivate *priv = impl->priv;
- GtkTreePath *cursor_path;
+ GtkTreePath *path;
GFile *new_file;
char *new_display_name;
GtkTreeModel *model;
+ GtkTreeSelection *selection;
- gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->browse_files_tree_view), &cursor_path, NULL);
model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->browse_files_tree_view));
- if (cursor_path)
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view));
+ if (gtk_tree_selection_get_mode (selection) == GTK_SELECTION_SINGLE ||
+ gtk_tree_selection_get_mode (selection) == GTK_SELECTION_BROWSE)
{
GtkTreeIter iter;
- gtk_tree_model_get_iter (model, &iter, cursor_path);
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ path = gtk_tree_model_get_path (model, &iter);
+ else
+ path = NULL;
+ }
+ else
+ {
+ gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->browse_files_tree_view), &path, NULL);
+ if (path && !gtk_tree_selection_path_is_selected (selection, path))
+ {
+ gtk_tree_path_free (path);
+ path = NULL;
+ }
+ }
+
+ if (path)
+ {
+ GtkTreeIter iter;
+
+ gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter,
MODEL_COL_FILE, &new_file,
MODEL_COL_NAME, &new_display_name,
-1);
- gtk_tree_path_free (cursor_path);
+ gtk_tree_path_free (path);
}
else
{
@@ -6696,6 +6719,13 @@ list_selection_changed (GtkTreeSelection *selection,
g_signal_emit_by_name (impl, "selection-changed", 0);
}
+static void
+list_cursor_changed (GtkTreeView *list,
+ GtkFileChooserWidget *impl)
+{
+ check_preview_change (impl);
+}
+
/* Callback used when a row in the file list is activated */
static void
list_row_activated (GtkTreeView *tree_view,
@@ -7382,6 +7412,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_callback (widget_class, list_row_activated);
gtk_widget_class_bind_template_callback (widget_class, file_list_drag_motion_cb);
gtk_widget_class_bind_template_callback (widget_class, list_selection_changed);
+ gtk_widget_class_bind_template_callback (widget_class, list_cursor_changed);
gtk_widget_class_bind_template_callback (widget_class, renderer_editing_canceled_cb);
gtk_widget_class_bind_template_callback (widget_class, renderer_edited_cb);
gtk_widget_class_bind_template_callback (widget_class, filter_combo_changed);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]