[gtk/file-chooser-api-cleanup-2] filechooser: Drop the ::selection-changed signal



commit 2746a2d929615231af10f221fc2ab416537285f3
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 9 02:06:31 2020 -0400

    filechooser: Drop the ::selection-changed signal
    
    This signal does not work on native file choosers,
    and it exposes internals of the widget that should
    not be public. And it is just not very interesting.

 gtk/gtkfilechooser.c           | 23 ----------------
 gtk/gtkfilechooserbutton.c     |  3 ---
 gtk/gtkfilechooserdialog.c     | 23 ----------------
 gtk/gtkfilechoosernative.c     |  6 -----
 gtk/gtkfilechooserutils.c      | 11 --------
 gtk/gtkfilechooserwidget.c     | 59 +++++++++++++++++++++++++++++++++++++++---
 gtk/ui/gtkfilechooserdialog.ui |  1 -
 7 files changed, 55 insertions(+), 71 deletions(-)
---
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c
index 9248b0ecca..a6c28424ad 100644
--- a/gtk/gtkfilechooser.c
+++ b/gtk/gtkfilechooser.c
@@ -79,29 +79,6 @@ G_DEFINE_INTERFACE (GtkFileChooser, gtk_file_chooser, G_TYPE_OBJECT);
 static void
 gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
 {
-  GType iface_type = G_TYPE_FROM_INTERFACE (iface);
-
-  /**
-   * GtkFileChooser::selection-changed:
-   * @chooser: the object which received the signal.
-   *
-   * This signal is emitted when there is a change in the set of selected files
-   * in a #GtkFileChooser.  This can happen when the user modifies the selection
-   * with the mouse or the keyboard, or when explicitly calling functions to
-   * change the selection.
-   *
-   * Normally you do not need to connect to this signal, as it is easier to wait
-   * for the file chooser to finish running, and then to get the list of
-   * selected files using the functions mentioned below.
-   */
-  g_signal_new (I_("selection-changed"),
-                iface_type,
-                G_SIGNAL_RUN_LAST,
-                G_STRUCT_OFFSET (GtkFileChooserIface, selection_changed),
-                NULL, NULL,
-                NULL,
-                G_TYPE_NONE, 0);
-
   g_object_interface_install_property (iface,
                                        g_param_spec_enum ("action",
                                                           P_("Action"),
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index cf63e745b6..3708da6588 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -627,7 +627,6 @@ emit_selection_changed_if_changing_selection (GtkFileChooserButton *button)
   if (button->is_changing_selection)
     {
       button->is_changing_selection = FALSE;
-      g_signal_emit_by_name (button, "selection-changed");
     }
 }
 
@@ -2516,8 +2515,6 @@ common_response_cb (GtkFileChooserButton *button,
       response == GTK_RESPONSE_OK)
     {
       save_inactive_state (button);
-
-      g_signal_emit_by_name (button, "selection-changed");
     }
   else
     {
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 8e8e70c1d6..a7bc1dd15f 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -267,8 +267,6 @@ static void     gtk_file_chooser_dialog_size_allocate (GtkWidget            *wid
                                                        int                    baseline);
 static void     file_chooser_widget_response_requested (GtkWidget            *widget,
                                                         GtkFileChooserDialog *dialog);
-static void     file_chooser_widget_selection_changed (GtkWidget            *widget,
-                                                        GtkFileChooserDialog *dialog);
 
 static void response_cb (GtkDialog *dialog,
                          gint       response_id);
@@ -309,7 +307,6 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserDialog, buttons);
   gtk_widget_class_bind_template_callback (widget_class, response_cb);
   gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_response_requested);
-  gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_selection_changed);
 }
 
 static void
@@ -364,26 +361,6 @@ is_accept_response_id (gint response_id)
           response_id == GTK_RESPONSE_APPLY);
 }
 
-static void
-file_chooser_widget_selection_changed (GtkWidget            *widget,
-                                       GtkFileChooserDialog *dialog)
-{
-  GtkFileChooserDialogPrivate *priv = gtk_file_chooser_dialog_get_instance_private (dialog);
-  GtkWidget *button;
-  GListModel *files;
-  gboolean sensitive;
-
-  button = get_accept_action_widget (GTK_DIALOG (dialog), FALSE);
-  if (button == NULL)
-    return;
-
-  files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->widget));
-  sensitive = (g_list_model_get_n_items (files) > 0);
-  gtk_widget_set_sensitive (button, sensitive);
-
-  g_object_unref (files);
-}
-
 static void
 file_chooser_widget_response_requested (GtkWidget            *widget,
                                         GtkFileChooserDialog *dialog)
diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c
index 6dfd296002..b6f7a9b01b 100644
--- a/gtk/gtkfilechoosernative.c
+++ b/gtk/gtkfilechoosernative.c
@@ -158,12 +158,6 @@
  * possible to use with #GtkFileChooserNative, as such use would
  * prohibit the use of a native dialog.
  *
- * There is no support for the signals that are emitted when the user
- * navigates in the dialog, including:
- * * #GtkFileChooser::selection-changed
- *
- * If you need any of the above you will have to use #GtkFileChooserDialog directly.
- *
  * No operations that change the dialog work while the dialog is visible.
  * Set all the properties that are required before showing the dialog.
  *
diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index b68fe534ff..0c62e8d590 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -56,8 +56,6 @@ static GListModel *   delegate_get_shortcut_folders   (GtkFileChooser    *choose
 static void           delegate_notify                 (GObject           *object,
                                                       GParamSpec        *pspec,
                                                       gpointer           data);
-static void           delegate_selection_changed      (GtkFileChooser    *chooser,
-                                                      gpointer           data);
 
 static void           delegate_add_choice             (GtkFileChooser  *chooser,
                                                        const char      *id,
@@ -164,8 +162,6 @@ _gtk_file_chooser_set_delegate (GtkFileChooser *receiver,
   g_object_set_data (G_OBJECT (receiver), I_("gtk-file-chooser-delegate"), delegate);
   g_signal_connect (delegate, "notify",
                    G_CALLBACK (delegate_notify), receiver);
-  g_signal_connect (delegate, "selection-changed",
-                   G_CALLBACK (delegate_selection_changed), receiver);
 }
 
 GQuark
@@ -307,13 +303,6 @@ delegate_notify (GObject    *object,
     g_object_notify (data, pspec->name);
 }
 
-static void
-delegate_selection_changed (GtkFileChooser *chooser,
-                           gpointer        data)
-{
-  g_signal_emit_by_name (data, "selection-changed");
-}
-
 GSettings *
 _gtk_file_chooser_get_settings_for_widget (GtkWidget *widget)
 {
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 01443dcba7..ac9e8721a1 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -2220,14 +2220,66 @@ set_icon_cell_renderer_fixed_size (GtkFileChooserWidget *impl)
                                     ypad * 2 + ICON_SIZE);
 }
 
+static GtkWidget *
+get_accept_action_widget (GtkDialog *dialog,
+                          gboolean   sensitive_only)
+{
+  gint response[] = {
+    GTK_RESPONSE_ACCEPT,
+    GTK_RESPONSE_OK,
+    GTK_RESPONSE_YES,
+    GTK_RESPONSE_APPLY
+  };
+  gint i;
+  GtkWidget *widget;
+
+  for (i = 0; i < G_N_ELEMENTS (response); i++)
+    {
+      widget = gtk_dialog_get_widget_for_response (dialog, response[i]);
+      if (widget)
+        {
+          if (!sensitive_only)
+            return widget;
+
+          if (gtk_widget_is_sensitive (widget))
+            return widget;
+        }
+    }
+
+  return NULL;
+}
+
+static void
+update_default (GtkFileChooserWidget *impl)
+{
+  GtkWidget *dialog;
+  GtkWidget *button;
+  GListModel *files;
+  gboolean sensitive;
+
+  dialog = gtk_widget_get_ancestor (GTK_WIDGET (impl), GTK_TYPE_DIALOG);
+  if (dialog == NULL)
+    return;
+
+  button = get_accept_action_widget (GTK_DIALOG (dialog), FALSE);
+  if (button == NULL)
+    return;
+
+  files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (impl));
+  sensitive = (g_list_model_get_n_items (files) > 0);
+  gtk_widget_set_sensitive (button, sensitive);
+
+  g_object_unref (files);
+}
+
 static gboolean
 location_changed_timeout_cb (gpointer user_data)
 {
   GtkFileChooserWidget *impl = user_data;
 
   gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (impl));
-  g_signal_emit_by_name (impl, "selection-changed", 0);
 
+  update_default (impl);
   impl->location_changed_id = 0;
 
   return G_SOURCE_REMOVE;
@@ -5084,7 +5136,7 @@ update_current_folder_get_info_cb (GCancellable *cancellable,
 
   g_object_notify (G_OBJECT (impl), "subtitle");
 
-  g_signal_emit_by_name (impl, "selection-changed", 0);
+  update_default (impl);
 
 out:
   g_object_unref (data->impl);
@@ -7004,8 +7056,7 @@ list_selection_changed (GtkTreeSelection     *selection,
     update_chooser_entry (impl);
 
   location_bar_update (impl);
-
-  g_signal_emit_by_name (impl, "selection-changed", 0);
+  update_default (impl);
 }
 
 static gboolean
diff --git a/gtk/ui/gtkfilechooserdialog.ui b/gtk/ui/gtkfilechooserdialog.ui
index 57d5f3b770..99b3700c69 100644
--- a/gtk/ui/gtkfilechooserdialog.ui
+++ b/gtk/ui/gtkfilechooserdialog.ui
@@ -21,7 +21,6 @@
             <property name="hexpand">1</property>
             <property name="vexpand">1</property>
             <signal name="response-requested" handler="file_chooser_widget_response_requested" swapped="no"/>
-            <signal name="selection-changed" handler="file_chooser_widget_selection_changed" swapped="no"/>
           </object>
         </child>
       </object>


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