Deprecate GtkDialog

GtkDialog is too flexible in terms of UI (headerbars vs action bar,
etc), and has archaic APIs. It is time to retire it.
This commit is contained in:
Matthias Clasen 2022-10-29 13:53:47 -04:00
parent f1af8046d0
commit 9948053cd7
34 changed files with 91 additions and 35 deletions

2
NEWS
View File

@ -22,6 +22,8 @@ feedback on our plans.
* GtkMessageDialog has been deprecated and
replaced by a new async dialog API
* GtkDialog has been deprecated
* GtkColorChooser, GtkFontChooser, GtkFileChooser
interfaces and their implementations have been
deprecated. A new family of async dialog APIs

View File

@ -35,6 +35,7 @@ do_spinner (GtkWidget *do_widget)
if (!window)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
window = gtk_dialog_new_with_buttons ("Spinner",
GTK_WINDOW (do_widget),
0,
@ -48,6 +49,7 @@ do_spinner (GtkWidget *do_widget)
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
G_GNUC_END_IGNORE_DEPRECATIONS
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_widget_set_margin_start (vbox, 5);

View File

@ -1467,7 +1467,9 @@ close_selection_dialog (GtkWidget *dialog, int response, GtkWidget *tv)
if (response == GTK_RESPONSE_CANCEL)
return;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
box = gtk_widget_get_first_child (gtk_dialog_get_content_area (GTK_DIALOG (dialog)));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert (GTK_IS_FLOW_BOX (box));
children = gtk_flow_box_get_selected_children (GTK_FLOW_BOX (box));

View File

@ -89,3 +89,11 @@ There are also equivalents for some of the 'button' widgets:
Like the Chooser interfaces, GtkMessageDialog has been replaced by
a new async API that will be more convenient, in particular for
language binding. The new API is [class@Gtk.AlertDialog].
## GtkDialog is going away
After gtk_dialog_run() was removed, the usefulness of GtkDialog
is much reduced, and it has awkward, archaice APIs. Therefore,
it is dropped. The recommended replacement is to just create
your own window and add buttons as required, either in the header
or elsewhere.

View File

@ -1,6 +1,8 @@
#include <stdlib.h>
#include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct
{
GtkApplication parent_instance;

View File

@ -29,7 +29,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gio/gio.h>
G_BEGIN_DECLS

View File

@ -22,7 +22,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
G_BEGIN_DECLS

View File

@ -43,6 +43,8 @@
#include "gtktypebuiltins.h"
#include "gtksizegroup.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkDialog:
*

View File

@ -127,51 +127,51 @@ struct _GtkDialogClass
GDK_AVAILABLE_IN_ALL
GType gtk_dialog_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_new (void);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_new_with_buttons (const char *title,
GtkWindow *parent,
GtkDialogFlags flags,
const char *first_button_text,
...) G_GNUC_NULL_TERMINATED;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_add_action_widget (GtkDialog *dialog,
GtkWidget *child,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_add_button (GtkDialog *dialog,
const char *button_text,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_add_buttons (GtkDialog *dialog,
const char *first_button_text,
...) G_GNUC_NULL_TERMINATED;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_set_response_sensitive (GtkDialog *dialog,
int response_id,
gboolean setting);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_set_default_response (GtkDialog *dialog,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_get_widget_for_response (GtkDialog *dialog,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
int gtk_dialog_get_response_for_widget (GtkDialog *dialog,
GtkWidget *widget);
/* Emit response signal */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_response (GtkDialog *dialog,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_dialog_get_content_area (GtkDialog *dialog);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_dialog_get_header_bar (GtkDialog *dialog);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkDialog, g_object_unref)

View File

@ -23,7 +23,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gtk/deprecated/gtkfilechooser.h>
G_BEGIN_DECLS

View File

@ -22,7 +22,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
G_BEGIN_DECLS

View File

@ -29,7 +29,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gtk/gtkenums.h>
G_BEGIN_DECLS

View File

@ -23,6 +23,7 @@ gtk_deprecated_sources = [
'deprecated/gtkcolorchooser.c',
'deprecated/gtkcombobox.c',
'deprecated/gtkcomboboxtext.c',
'deprecated/gtkdialog.c',
'deprecated/gtkentrycompletion.c',
'deprecated/gtkfilechooser.c',
'deprecated/gtkfontbutton.c',
@ -71,6 +72,7 @@ gtk_deprecated_headers = [
'deprecated/gtkcolorchooserwidget.h',
'deprecated/gtkcombobox.h',
'deprecated/gtkcomboboxtext.h',
'deprecated/gtkdialog.h',
'deprecated/gtkentrycompletion.h',
'deprecated/gtkfilechooser.h',
'deprecated/gtkfilechooserdialog.h',

View File

@ -97,7 +97,7 @@
#include <gtk/gtkcustomlayout.h>
#include <gtk/gtkcustomsorter.h>
#include <gtk/gtkdebug.h>
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gtk/gtkdialogerror.h>
#include <gtk/gtkdirectorylist.h>
#include <gtk/gtkdragicon.h>

View File

@ -663,6 +663,7 @@ gtk_alert_dialog_choose (GtkAlertDialog *self,
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
window = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
"transient-for", parent,
"destroy-with-parent", TRUE,
@ -689,6 +690,7 @@ gtk_alert_dialog_choose (GtkAlertDialog *self,
gtk_dialog_set_default_response (GTK_DIALOG (window), 0);
self->cancel_return = 0;
}
G_GNUC_END_IGNORE_DEPRECATIONS
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_alert_dialog_choose);

View File

@ -17,8 +17,8 @@
#include "config.h"
#include "gtkdialog.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialog.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtkbutton.h"
#include "gtkbox.h"
#include "gtkprivate.h"

View File

@ -37,7 +37,7 @@
#include "gtkcustompaperunixdialog.h"
#include "gtkprintbackendprivate.h"
#include "gtkprintutils.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#define LEGACY_CUSTOM_PAPER_FILENAME ".gtk-custom-papers"
#define CUSTOM_PAPER_FILENAME "custom-papers"
@ -283,7 +283,9 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
GListModel *full_list;
GtkFilter *filter;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
dialog->print_backends = NULL;
@ -318,6 +320,7 @@ gtk_custom_paper_unix_dialog_constructed (GObject *object)
G_OBJECT_CLASS (gtk_custom_paper_unix_dialog_parent_class)->constructed (object);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_object_get (object, "use-header-bar", &use_header, NULL);
if (!use_header)
{
@ -326,6 +329,7 @@ gtk_custom_paper_unix_dialog_constructed (GObject *object)
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_CLOSE);
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@ -847,7 +851,10 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
GtkSelectionModel *model;
GtkListItemFactory *factory;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
content_area = gtk_dialog_get_content_area (cpu_dialog);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);

View File

@ -31,7 +31,7 @@
#include "gtksettings.h"
#include "gtktogglebutton.h"
#include "gtkheaderbar.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtklabel.h"
#include "gtkfilechooserentry.h"
#include "gtkbox.h"

View File

@ -23,7 +23,7 @@
#include "gtknativedialogprivate.h"
#include "gtkprivate.h"
#include "gtkdialog.h"
#include "deprecated/gtkdialog.h"
#include "gtkfilechooserprivate.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"

View File

@ -21,7 +21,7 @@
#include "gtkfiledialog.h"
#include "gtkdialog.h"
#include "deprecated/gtkdialog.h"
#include "deprecated/gtkfilechoosernative.h"
#include "gtkdialogerror.h"
#include <glib/gi18n-lib.h>

View File

@ -32,7 +32,7 @@
#include "gtkprivate.h"
#include "gtkwidget.h"
#include "gtksettings.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtktogglebutton.h"
#include "gtkheaderbar.h"
#include "gtkactionable.h"

View File

@ -48,7 +48,7 @@
#include "gtktextview.h"
#include "gtkwidgetprivate.h"
#include "gtksettings.h"
#include "gtkdialog.h"
#include "deprecated/gtkdialog.h"
#include "gtkgestureclick.h"
#include "gtkeventcontrollerscroll.h"
#include "gtkroot.h"

View File

@ -38,7 +38,7 @@
#include "gtklabel.h"
#include "gtkbutton.h"
#include "gtkenums.h"
#include "gtkdialog.h"
#include "deprecated/gtkdialog.h"
#include "gtkrevealer.h"
#include "gtkprivate.h"
#include "gtktypebuiltins.h"

View File

@ -29,7 +29,7 @@
#include "gtkbox.h"
#include "gtkbuildable.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include <glib/gi18n-lib.h>
#include "gtklabel.h"
#include "gtkprivate.h"

View File

@ -45,7 +45,7 @@
#include "gtkicontheme.h"
#include "gtkmain.h"
#include "gtksettings.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtkpopover.h"
#include "gtksnapshot.h"
#include "gdktextureprivate.h"
@ -468,9 +468,11 @@ pw_dialog_verify_input (GtkEditable *editable,
gboolean is_valid;
is_valid = pw_dialog_input_is_valid (operation);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
GTK_RESPONSE_OK,
is_valid);
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@ -493,9 +495,11 @@ pw_dialog_anonymous_toggled (GtkWidget *widget,
gtk_widget_set_sensitive (GTK_WIDGET (l->data), !priv->anonymous);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
GTK_RESPONSE_OK,
is_valid);
G_GNUC_END_IGNORE_DEPRECATIONS
}
@ -593,6 +597,7 @@ gtk_mount_operation_ask_password_do_gtk (GtkMountOperation *operation,
priv->dialog = dialog;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
content_area = gtk_dialog_get_content_area (dialog);
gtk_window_set_resizable (window, FALSE);
@ -604,6 +609,7 @@ gtk_mount_operation_ask_password_do_gtk (GtkMountOperation *operation,
_("Co_nnect"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
G_GNUC_END_IGNORE_DEPRECATIONS
/* Build contents */
@ -794,7 +800,11 @@ gtk_mount_operation_ask_password_do_gtk (GtkMountOperation *operation,
g_signal_emit_by_name (priv->anonymous_toggle, "toggled");
}
else if (! pw_dialog_input_is_valid (operation))
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, FALSE);
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, FALSE);
G_GNUC_END_IGNORE_DEPRECATIONS
}
g_object_notify (G_OBJECT (operation), "is-showing");
@ -1459,13 +1469,17 @@ create_show_processes_dialog (GtkMountOperation *op,
primary = g_strndup (message, primary - message);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
dialog = gtk_dialog_new ();
G_GNUC_END_IGNORE_DEPRECATIONS
if (priv->parent_window != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->parent_window);
gtk_window_set_title (GTK_WINDOW (dialog), "");
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_widget_set_margin_top (vbox, 12);
gtk_widget_set_margin_bottom (vbox, 12);

View File

@ -35,7 +35,7 @@
#include "gtkprintbackendprivate.h"
#include "gtkpapersize.h"
#include "gtkprintutils.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
/**
* GtkPageSetupUnixDialog:
@ -276,12 +276,15 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
dialog->print_backends = NULL;
gtk_widget_init_template (GTK_WIDGET (dialog));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Apply"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
G_GNUC_END_IGNORE_DEPRECATIONS
dialog->page_setup_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);
dialog->custom_paper_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);

View File

@ -633,12 +633,14 @@ request_password (GtkPrintBackend *backend,
priv->auth_info = g_new0 (char *, length + 1);
priv->store_auth_info = FALSE;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
dialog = gtk_dialog_new_with_buttons ( _("Authentication"), NULL, GTK_DIALOG_MODAL,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_OK"), GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
G_GNUC_END_IGNORE_DEPRECATIONS
main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
@ -665,7 +667,9 @@ request_password (GtkPrintBackend *backend,
g_free (markup);
/* Packing */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_box_append (GTK_BOX (content_area), main_box);
gtk_box_append (GTK_BOX (main_box), icon);

View File

@ -52,11 +52,13 @@
#include <glib/gi18n-lib.h>
#include "gtkprivate.h"
#include "gtktypebuiltins.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkcsscolorvalueprivate.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkPrintUnixDialog:
*

View File

@ -6142,7 +6142,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
"application to break or crash."));
area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
check = gtk_check_button_new_with_label (_("Dont show this message again"));
gtk_widget_set_margin_start (check, 10);
gtk_widget_show (check);
@ -6154,6 +6153,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
g_object_set_data (G_OBJECT (inspector_window), "warning_dialog", dialog);
gtk_widget_show (dialog);
G_GNUC_END_IGNORE_DEPRECATIONS
}
if (select)

View File

@ -199,7 +199,6 @@ gtk_public_sources = files([
'gtkcustomfilter.c',
'gtkcustomlayout.c',
'gtkcustomsorter.c',
'gtkdialog.c',
'gtkdialogerror.c',
'gtkdirectorylist.c',
'gtkdragicon.c',
@ -455,7 +454,6 @@ gtk_public_headers = files([
'gtkcustomlayout.h',
'gtkcustomsorter.h',
'gtkdebug.h',
'gtkdialog.h',
'gtkdialogerror.h',
'gtkdirectorylist.h',
'gtkdragicon.h',

View File

@ -19,6 +19,8 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/* a fake permission implementation */
#define G_TYPE_TEST_PERMISSION (g_test_permission_get_type ())

View File

@ -1,6 +1,8 @@
/* gcc -g -Wall -O2 -o dialog-test dialog-test.c `pkg-config --cflags --libs gtk4` */
#include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static GtkWidget *window;
static GtkWidget *width_chars_spin;
static GtkWidget *max_width_chars_spin;

View File

@ -1,5 +1,7 @@
#include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void
dialog_role (void)
{