[nautilus] eel-stock-dialogs: Add eel_show_simple_dialog



commit 67812f918d0162de0bc7cf0325d7eedc2d3f85bb
Author: Matthew Jakeman <mjakeman26 outlook co nz>
Date:   Fri Dec 24 01:02:33 2021 +1300

    eel-stock-dialogs: Add eel_show_simple_dialog
    
    Extracts the creation of simple dialogs to a new function
    that does not depend on gtk_dialog_run. It is the caller's
    responsibility to obtain a response from the dialog.
    
    Part of #1992

 eel/eel-stock-dialogs.c | 57 ++++++++++++++++++++++++++++++++++++++-----------
 eel/eel-stock-dialogs.h |  7 +++++-
 2 files changed, 51 insertions(+), 13 deletions(-)
---
diff --git a/eel/eel-stock-dialogs.c b/eel/eel-stock-dialogs.c
index 499af99d5..9929e4064 100644
--- a/eel/eel-stock-dialogs.c
+++ b/eel/eel-stock-dialogs.c
@@ -318,19 +318,16 @@ eel_timed_wait_stop (EelCancelCallback cancel_callback,
     timed_wait_free (wait);
 }
 
-int
-eel_run_simple_dialog (GtkWidget     *parent,
-                       gboolean       ignore_close_box,
-                       GtkMessageType message_type,
-                       const char    *primary_text,
-                       const char    *secondary_text,
-                       ...)
+static GtkDialog *
+eel_show_simple_dialogv (GtkWidget      *parent,
+                         GtkMessageType  message_type,
+                         const char     *primary_text,
+                         const char     *secondary_text,
+                         va_list         button_title_args)
 {
-    va_list button_title_args;
     const char *button_title;
     GtkWidget *dialog;
     GtkWidget *top_widget, *chosen_parent;
-    int result;
     int response_id;
 
     /* Parent it if asked to. */
@@ -356,7 +353,6 @@ eel_run_simple_dialog (GtkWidget     *parent,
                   "secondary-text", secondary_text,
                   NULL);
 
-    va_start (button_title_args, secondary_text);
     response_id = 0;
     while (1)
     {
@@ -369,17 +365,54 @@ eel_run_simple_dialog (GtkWidget     *parent,
         gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
         response_id++;
     }
+
+
+    gtk_widget_show_all (dialog);
+
+    return GTK_DIALOG (dialog);
+}
+
+GtkDialog *
+eel_show_simple_dialog (GtkWidget     *parent,
+                        GtkMessageType message_type,
+                        const char    *primary_text,
+                        const char    *secondary_text,
+                        ...)
+{
+    va_list button_title_args;
+    GtkDialog *dialog;
+
+    va_start (button_title_args, secondary_text);
+    dialog = eel_show_simple_dialogv (parent, message_type, primary_text, secondary_text, button_title_args);
+    va_end (button_title_args);
+
+    return dialog;
+}
+
+int
+eel_run_simple_dialog (GtkWidget     *parent,
+                       gboolean       ignore_close_box,
+                       GtkMessageType message_type,
+                       const char    *primary_text,
+                       const char    *secondary_text,
+                       ...)
+{
+    va_list button_title_args;
+    GtkDialog *dialog;
+    int result;
+
+    va_start (button_title_args, secondary_text);
+    dialog = eel_show_simple_dialogv (parent, message_type, primary_text, secondary_text, button_title_args);
     va_end (button_title_args);
 
     /* Run it. */
-    gtk_widget_show (dialog);
     result = gtk_dialog_run (GTK_DIALOG (dialog));
     while ((result == GTK_RESPONSE_NONE || result == GTK_RESPONSE_DELETE_EVENT) && ignore_close_box)
     {
         gtk_widget_show (GTK_WIDGET (dialog));
         result = gtk_dialog_run (GTK_DIALOG (dialog));
     }
-    gtk_widget_destroy (dialog);
+    gtk_widget_destroy (GTK_WIDGET (dialog));
 
     return result;
 }
diff --git a/eel/eel-stock-dialogs.h b/eel/eel-stock-dialogs.h
index 792686152..cea8e1fed 100644
--- a/eel/eel-stock-dialogs.h
+++ b/eel/eel-stock-dialogs.h
@@ -40,6 +40,11 @@ void       eel_timed_wait_stop                (EelCancelCallback  cancel_callbac
                                               gpointer           callback_data);
 
 /* Basic dialog with buttons. */
+GtkDialog *eel_show_simple_dialog             (GtkWidget         *parent,
+                                              GtkMessageType     message_type,
+                                              const char        *primary_text,
+                                              const char        *secondary_text,
+                                              ...);
 int        eel_run_simple_dialog              (GtkWidget         *parent,
                                               gboolean           ignore_close_box,
                                               GtkMessageType     message_type,
@@ -72,4 +77,4 @@ GtkDialog *eel_create_question_dialog         (const char        *primary_text,
                                               int                response_one,
                                               const char        *answer_two,
                                               int                response_two,
-                                              GtkWindow         *parent);
\ No newline at end of file
+                                              GtkWindow         *parent);


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