[gtk/gbsneto/filechooser-column-view: 73/82] filechooserwidget: Listen to items-changed too




commit af8a91a31f5fc8623618846e63fefd04ac1d5590
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 10 19:53:36 2022 -0400

    filechooserwidget: Listen to items-changed too
    
    To track changes of the selected items in a selection
    model, we need to listen to both ::selection-changed
    and ::items-changed.
    
    This fixes the open button not turning sensitive
    when initially loading a new folder.

 gtk/gtkfilechooserwidget.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index b866c1687b..6eb8844024 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -474,6 +474,11 @@ static void list_selection_changed     (GtkSelectionModel    *selection_model,
                                         guint                 position,
                                         guint                 n_items,
                                         GtkFileChooserWidget *impl);
+static void list_items_changed         (GListModel           *model,
+                                        guint                 position,
+                                        guint                 removed,
+                                        guint                 added,
+                                        GtkFileChooserWidget *impl);
 static void path_bar_clicked (GtkPathBar            *path_bar,
                               GFile                 *file,
                               GFile                 *child,
@@ -6216,6 +6221,19 @@ list_selection_changed (GtkSelectionModel    *selection_model,
   update_default (impl);
 }
 
+static void
+list_items_changed (GListModel           *model,
+                    guint                 position,
+                    guint                 removed,
+                    guint                 added,
+                    GtkFileChooserWidget *impl)
+{
+  if (get_current_model (impl) == NULL)
+    return;
+
+  update_default (impl);
+}
+
 static gboolean
 browse_files_column_view_keynav_failed_cb (GtkWidget        *widget,
                                            GtkDirectionType  direction,
@@ -7065,10 +7083,10 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
   impl->auto_selecting_first_row = FALSE;
   impl->renamed_file = NULL;
 
-  g_signal_connect (impl->selection_model,
-                    "selection-changed",
-                    G_CALLBACK (list_selection_changed),
-                    impl);
+  g_signal_connect (impl->selection_model, "selection-changed",
+                    G_CALLBACK (list_selection_changed), impl);
+  g_signal_connect (impl->selection_model, "items-changed",
+                    G_CALLBACK (list_items_changed), impl);
 
   /* Ensure private types used by the template
    * definition before calling gtk_widget_init_template()


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