mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 22:10:08 +00:00
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.
This commit is contained in:
parent
3212b07cf1
commit
5d272a12cb
@ -1767,7 +1767,6 @@ gtk_native_dialog_set_title
|
|||||||
gtk_native_dialog_get_title
|
gtk_native_dialog_get_title
|
||||||
gtk_native_dialog_set_transient_for
|
gtk_native_dialog_set_transient_for
|
||||||
gtk_native_dialog_get_transient_for
|
gtk_native_dialog_get_transient_for
|
||||||
gtk_native_dialog_run
|
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
GtkNativeDialog
|
GtkNativeDialog
|
||||||
<SUBSECTION Private>
|
<SUBSECTION Private>
|
||||||
|
@ -56,10 +56,6 @@
|
|||||||
* various common properties on the dialog, as well as show and hide
|
* various common properties on the dialog, as well as show and hide
|
||||||
* it and get a #GtkNativeDialog::response signal when the user finished
|
* it and get a #GtkNativeDialog::response signal when the user finished
|
||||||
* with the dialog.
|
* 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;
|
typedef struct _GtkNativeDialogPrivate GtkNativeDialogPrivate;
|
||||||
@ -558,96 +554,3 @@ gtk_native_dialog_get_transient_for (GtkNativeDialog *self)
|
|||||||
|
|
||||||
return priv->transient_for;
|
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;
|
|
||||||
}
|
|
||||||
|
@ -73,9 +73,6 @@ void gtk_native_dialog_set_transient_for (GtkNativeDialog *self
|
|||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
GtkWindow * gtk_native_dialog_get_transient_for (GtkNativeDialog *self);
|
GtkWindow * gtk_native_dialog_get_transient_for (GtkNativeDialog *self);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_ALL
|
|
||||||
gint gtk_native_dialog_run (GtkNativeDialog *self);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GTK_NATIVE_DIALOG_H__ */
|
#endif /* __GTK_NATIVE_DIALOG_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user