[gtk/ebassi/run-dialog-run: 354/363] Remove gtk_native_dialog_run()



commit a62e985a1f9002466aa20c43c00da9090a168d0a
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 30 13:56:41 2020 +0100

    Remove gtk_native_dialog_run()
    
    Nested main loops are bad, as they introduce layers of complexity caused
    by the potential re-entrancy in the case of multiple event sources, like
    IPC, threads, etc. Additionally, the programming model they provide—stop
    the world while spinning a new loop—does not conform to the event-driven
    model employed by GTK.

 docs/reference/gtk/gtk4-sections.txt |  1 -
 gtk/gtknativedialog.c                | 97 ------------------------------------
 gtk/gtknativedialog.h                |  3 --
 3 files changed, 101 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 807d92b3a9..bf155b1a37 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1799,7 +1799,6 @@ gtk_native_dialog_set_title
 gtk_native_dialog_get_title
 gtk_native_dialog_set_transient_for
 gtk_native_dialog_get_transient_for
-gtk_native_dialog_run
 <SUBSECTION Standard>
 GtkNativeDialog
 <SUBSECTION Private>
diff --git a/gtk/gtknativedialog.c b/gtk/gtknativedialog.c
index c97c6c0697..465503bc31 100644
--- a/gtk/gtknativedialog.c
+++ b/gtk/gtknativedialog.c
@@ -56,10 +56,6 @@
  * various common properties on the dialog, as well as show and hide
  * it and get a #GtkNativeDialog::response signal when the user finished
  * with the dialog.
- *
- * There is also a gtk_native_dialog_run() helper that makes it easy
- * to run any native dialog in a modal way with a recursive mainloop,
- * similar to gtk_dialog_run().
  */
 
 typedef struct _GtkNativeDialogPrivate GtkNativeDialogPrivate;
@@ -530,96 +526,3 @@ gtk_native_dialog_get_transient_for (GtkNativeDialog *self)
 
   return priv->transient_for;
 }
-
-static void
-run_response_cb (GtkNativeDialog *self,
-                 gint response_id,
-                 gpointer data)
-{
-  GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self);
-
-  priv->run_response_id = response_id;
-  if (priv->run_loop && g_main_loop_is_running (priv->run_loop))
-    g_main_loop_quit (priv->run_loop);
-}
-
-/**
- * gtk_native_dialog_run:
- * @self: a #GtkNativeDialog
- *
- * Blocks in a recursive main loop until @self emits the
- * #GtkNativeDialog::response signal. It then returns the response ID
- * from the ::response signal emission.
- *
- * Before entering the recursive main loop, gtk_native_dialog_run()
- * calls gtk_native_dialog_show() on the dialog for you.
- *
- * After gtk_native_dialog_run() returns, then dialog will be hidden.
- *
- * Typical usage of this function might be:
- * |[<!-- language="C" -->
- *   gint result = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
- *   switch (result)
- *     {
- *       case GTK_RESPONSE_ACCEPT:
- *          do_application_specific_something ();
- *          break;
- *       default:
- *          do_nothing_since_dialog_was_cancelled ();
- *          break;
- *     }
- *   g_object_unref (dialog);
- * ]|
- *
- * Note that even though the recursive main loop gives the effect of a
- * modal dialog (it prevents the user from interacting with other
- * windows in the same window group while the dialog is run), callbacks
- * such as timeouts, IO channel watches, DND drops, etc, will
- * be triggered during a gtk_native_dialog_run() call.
- *
- * Returns: response ID
- **/
-gint
-gtk_native_dialog_run (GtkNativeDialog *self)
-{
-  GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self);
-  gboolean was_modal;
-  guint response_handler;
-
-  g_return_val_if_fail (GTK_IS_NATIVE_DIALOG (self), -1);
-  g_return_val_if_fail (!priv->visible, -1);
-  g_return_val_if_fail (priv->run_loop == NULL, -1);
-
-  if (priv->visible || priv->run_loop != NULL)
-    return -1;
-
-  g_object_ref (self);
-
-  priv->run_response_id = GTK_RESPONSE_NONE;
-  priv->run_loop = g_main_loop_new (NULL, FALSE);
-
-  was_modal = priv->modal;
-  gtk_native_dialog_set_modal (self, TRUE);
-
-  response_handler =
-    g_signal_connect (self,
-                      "response",
-                      G_CALLBACK (run_response_cb),
-                      NULL);
-
-  gtk_native_dialog_show (self);
-
-  g_main_loop_run (priv->run_loop);
-
-  g_signal_handler_disconnect (self, response_handler);
-
-  g_main_loop_unref (priv->run_loop);
-  priv->run_loop = NULL;
-
-  if (!was_modal)
-    gtk_native_dialog_set_modal (self, FALSE);
-
-  g_object_unref (self);
-
-  return priv->run_response_id;
-}
diff --git a/gtk/gtknativedialog.h b/gtk/gtknativedialog.h
index 00d34532d0..f6a2dc20ae 100644
--- a/gtk/gtknativedialog.h
+++ b/gtk/gtknativedialog.h
@@ -73,9 +73,6 @@ void                  gtk_native_dialog_set_transient_for (GtkNativeDialog *self
 GDK_AVAILABLE_IN_ALL
 GtkWindow *           gtk_native_dialog_get_transient_for (GtkNativeDialog *self);
 
-GDK_AVAILABLE_IN_ALL
-gint                  gtk_native_dialog_run (GtkNativeDialog *self);
-
 G_END_DECLS
 
 #endif /* __GTK_NATIVE_DIALOG_H__ */


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