alertdialog: Small refactoring
authorMatthias Clasen <mclasen@redhat.com>
Sat, 29 Oct 2022 23:17:37 +0000 (19:17 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 30 Oct 2022 12:52:02 +0000 (08:52 -0400)
Move the deprecated code out into its own function.

gtk/gtkalertdialog.c

index db853ebe4693a78cb323e8f9ea5f0a217cf2fe05..40e67462162d5231a76139116502ded1cd4fc138 100644 (file)
@@ -628,6 +628,44 @@ dialog_response (GtkDialog *dialog,
   response_cb (task, response);
 }
 
+static GtkWidget *
+create_message_dialog (GtkAlertDialog *self,
+                       GtkWindow      *parent)
+{
+  GtkWidget *window;
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  window = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
+                         "transient-for", parent,
+                         "destroy-with-parent", TRUE,
+                         "modal", self->modal,
+                         "text", self->message,
+                         "secondary-text", self->detail,
+                         NULL);
+
+  if (self->buttons && self->buttons[0])
+    {
+      self->cancel_return = -1;
+      for (int i = 0; self->buttons[i]; i++)
+        {
+          gtk_dialog_add_button (GTK_DIALOG (window), self->buttons[i], i);
+          if (self->default_button == i)
+            gtk_dialog_set_default_response (GTK_DIALOG (window), i);
+          if (self->cancel_button == i)
+            self->cancel_return = i;
+        }
+    }
+  else
+    {
+      gtk_dialog_add_button (GTK_DIALOG (window), _("_Close"), 0);
+      gtk_dialog_set_default_response (GTK_DIALOG (window), 0);
+      self->cancel_return = 0;
+    }
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+  return window;
+}
+
 /* }}} */
 /* {{{ Async API */
 
@@ -652,45 +690,18 @@ dialog_response (GtkDialog *dialog,
  * Since: 4.10
  */
 void
-gtk_alert_dialog_choose (GtkAlertDialog       *self,
+gtk_alert_dialog_choose (GtkAlertDialog      *self,
                          GtkWindow           *parent,
                          GCancellable        *cancellable,
                          GAsyncReadyCallback  callback,
                          gpointer             user_data)
 {
-  GtkMessageDialog *window;
+  GtkWidget *window;
   GTask *task;
 
   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,
-                         "modal", self->modal,
-                         "text", self->message,
-                         "secondary-text", self->detail,
-                         NULL);
-
-  if (self->buttons && self->buttons[0])
-    {
-      self->cancel_return = -1;
-      for (int i = 0; self->buttons[i]; i++)
-        {
-          gtk_dialog_add_button (GTK_DIALOG (window), self->buttons[i], i);
-          if (self->default_button == i)
-            gtk_dialog_set_default_response (GTK_DIALOG (window), i);
-          if (self->cancel_button == i)
-            self->cancel_return = i;
-        }
-    }
-  else
-    {
-      gtk_dialog_add_button (GTK_DIALOG (window), _("_Close"), 0);
-      gtk_dialog_set_default_response (GTK_DIALOG (window), 0);
-      self->cancel_return = 0;
-    }
-G_GNUC_END_IGNORE_DEPRECATIONS
+  window = create_message_dialog (self, parent);
 
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task, gtk_alert_dialog_choose);