[console/wip/exalm/gtk4: 3/5] Port to AdwMessageDialog




commit 994c60665c6b597682ef7a7d0733d254289793d0
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Jul 20 06:01:35 2022 +0400

    Port to AdwMessageDialog

 src/kgx-close-dialog.c  |  8 +++----
 src/kgx-close-dialog.ui | 46 ++++++++++++-----------------------------
 src/kgx-pages.c         | 11 ++++------
 src/kgx-terminal.c      | 55 ++++++++++++++++++++-----------------------------
 src/kgx-window.c        | 14 ++++---------
 5 files changed, 47 insertions(+), 87 deletions(-)
---
diff --git a/src/kgx-close-dialog.c b/src/kgx-close-dialog.c
index 375e181..0956373 100644
--- a/src/kgx-close-dialog.c
+++ b/src/kgx-close-dialog.c
@@ -47,14 +47,14 @@ kgx_close_dialog_new (KgxCloseDialogContext  context,
   switch (context) {
     case KGX_CONTEXT_WINDOW:
       g_object_set (dialog,
-                    "text", _("Close Window?"),
-                    "secondary-text", _("Some commands are still running, closing this window will kill them 
and may lead to unexpected outcomes"),
+                    "heading", _("Close Window?"),
+                    "body", _("Some commands are still running, closing this window will kill them and may 
lead to unexpected outcomes"),
                     NULL);
       break;
     case KGX_CONTEXT_TAB:
       g_object_set (dialog,
-                    "text", _("Close Tab?"),
-                    "secondary-text", _("Some commands are still running, closing this tab will kill them 
and may lead to unexpected outcomes"),
+                    "heading", _("Close Tab?"),
+                    "body", _("Some commands are still running, closing this tab will kill them and may lead 
to unexpected outcomes"),
                     NULL);
       break;
     default:
diff --git a/src/kgx-close-dialog.ui b/src/kgx-close-dialog.ui
index 7c9c501..0b09518 100644
--- a/src/kgx-close-dialog.ui
+++ b/src/kgx-close-dialog.ui
@@ -1,41 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk" version="4.0"/>
-  <object class="GtkMessageDialog" id="dialog">
-    <property name="modal">True</property>
-    <child internal-child="message_area">
-      <object class="GtkBox">
-        <child>
-          <object class="GtkListBox" id="list">
-            <property name="can-focus">False</property>
-            <property name="selection-mode">none</property>
-            <property name="width-request">300</property>
-            <style>
-              <class name="content"/>
-              <class name="process-list"/>
-            </style>
-          </object>
-        </child>
-      </object>
-    </child>
-    <child type="action">
-      <object class="GtkButton" id="button-cancel">
-        <property name="label" translatable="yes">_Cancel</property>
-        <property name="use-underline">True</property>
-      </object>
-    </child>
-    <child type="action">
-      <object class="GtkButton" id="button-ok">
-        <property name="label" translatable="yes">C_lose</property>
-        <property name="use-underline">True</property>
+  <object class="AdwMessageDialog" id="dialog">
+    <property name="close-response">cancel</property>
+    <property name="extra-child">
+      <object class="GtkListBox" id="list">
+        <property name="can-focus">False</property>
+        <property name="selection-mode">none</property>
         <style>
-          <class name="destructive-action"/>
+          <class name="boxed-list"/>
+          <class name="process-list"/>
         </style>
       </object>
-    </child>
-    <action-widgets>
-      <action-widget response="cancel" default="true">button-cancel</action-widget>
-      <action-widget response="ok">button-ok</action-widget>
-    </action-widgets>
+    </property>
+    <responses>
+      <response id="cancel" translatable="yes">_Cancel</response>
+      <response id="close" translatable="yes" appearance="destructive">C_lose</response>
+    </responses>
   </object>
 </interface>
diff --git a/src/kgx-pages.c b/src/kgx-pages.c
index 930fc59..8137fee 100644
--- a/src/kgx-pages.c
+++ b/src/kgx-pages.c
@@ -459,18 +459,15 @@ create_window (AdwTabView *view,
 
 
 static void
-close_response (GtkWidget  *dlg,
-                int         response,
-                AdwTabPage *page)
+close_response (AdwTabPage *page,
+                const char *response)
 {
   KgxTab *tab = KGX_TAB (adw_tab_page_get_child (page));
   KgxPages *self = kgx_tab_get_pages (tab);
   KgxPagesPrivate *priv = kgx_pages_get_instance_private (self);
 
-  gtk_window_destroy (GTK_WINDOW (dlg));
-
   adw_tab_view_close_page_finish (ADW_TAB_VIEW (priv->view), page,
-                                  response == GTK_RESPONSE_OK);
+                                  !g_strcmp0 (response, "close"));
 }
 
 
@@ -495,7 +492,7 @@ close_page (AdwTabView *view,
 
   gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (root));
 
-  g_signal_connect (dlg, "response", G_CALLBACK (close_response), page);
+  g_signal_connect_swapped (dlg, "response", G_CALLBACK (close_response), page);
 
   gtk_widget_show (dlg);
 
diff --git a/src/kgx-terminal.c b/src/kgx-terminal.c
index 9ad6eb6..f048ab1 100644
--- a/src/kgx-terminal.c
+++ b/src/kgx-terminal.c
@@ -488,19 +488,11 @@ clear_paste_data (gpointer data)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (PasteData, clear_paste_data)
 
 static void
-paste_response (GtkDialog *dlg,
-                int        response,
-                PasteData *data)
+paste_response (PasteData *data)
 {
   g_autoptr (PasteData) paste = data;
 
-  if (dlg && GTK_IS_DIALOG (dlg)) {
-    gtk_window_destroy (GTK_WINDOW (dlg));
-  }
-
-  if (response == GTK_RESPONSE_ACCEPT) {
-    vte_terminal_paste_text (VTE_TERMINAL (paste->dest), paste->text);
-  }
+  vte_terminal_paste_text (VTE_TERMINAL (paste->dest), paste->text);
 }
 
 
@@ -796,31 +788,28 @@ kgx_terminal_accept_paste (KgxTerminal *self,
 
   if (g_strstr_len (striped, len, "sudo") != NULL &&
       g_strstr_len (striped, len, "\n") != NULL) {
-    GtkWidget *accept = NULL;
-    GtkWidget *dlg = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))),
-                                             GTK_DIALOG_MODAL,
-                                             GTK_MESSAGE_QUESTION,
-                                             GTK_BUTTONS_NONE,
-                                             _("You are pasting a command that runs as an administrator"));
-    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
-                                              // TRANSLATORS: %s is the command being pasted
-                                              _("Make sure you know what the command does:\n%s"),
-                                              text);
-
-    g_signal_connect (dlg,
-                      "response",
-                      G_CALLBACK (paste_response),
-                      g_steal_pointer (&paste));
-    gtk_dialog_add_button (GTK_DIALOG (dlg),
-                           _("_Cancel"),
-                           GTK_RESPONSE_DELETE_EVENT);
-    accept = gtk_dialog_add_button (GTK_DIALOG (dlg),
-                                    _("_Paste"),
-                                    GTK_RESPONSE_ACCEPT);
-    gtk_widget_add_css_class (accept, "destructive-action");
+    GtkWidget *dlg = adw_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))),
+                                             _("You are pasting a command that runs as an administrator"),
+                                             NULL);
+    adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dlg),
+                                    // TRANSLATORS: %s is the command being pasted
+                                    _("Make sure you know what the command does:\n%s"),
+                                    text);
+    adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dlg),
+                                      "cancel", _("_Cancel"),
+                                      "paste", _("_Paste"),
+                                      NULL);
+    adw_message_dialog_set_response_appearance (ADW_MESSAGE_DIALOG (dlg),
+                                                "paste",
+                                                ADW_RESPONSE_DESTRUCTIVE);
+
+    g_signal_connect_swapped (dlg,
+                              "response::paste",
+                              G_CALLBACK (paste_response),
+                              g_steal_pointer (&paste));
 
     gtk_widget_show (dlg);
   } else {
-    paste_response (NULL, GTK_RESPONSE_ACCEPT, g_steal_pointer (&paste));
+    paste_response (g_steal_pointer (&paste));
   }
 }
diff --git a/src/kgx-window.c b/src/kgx-window.c
index 1970bff..9ffab5e 100644
--- a/src/kgx-window.c
+++ b/src/kgx-window.c
@@ -175,17 +175,11 @@ kgx_window_get_property (GObject    *object,
 
 
 static void
-delete_response (GtkWidget *dlg,
-                 int        response,
-                 KgxWindow *self)
+close_response (KgxWindow *self)
 {
-  gtk_window_destroy (GTK_WINDOW (dlg));
+  self->close_anyway = TRUE;
 
-  if (response == GTK_RESPONSE_OK) {
-    self->close_anyway = TRUE;
-
-    gtk_window_destroy (GTK_WINDOW (self));
-  }
+  gtk_window_destroy (GTK_WINDOW (self));
 }
 
 
@@ -206,7 +200,7 @@ kgx_window_close_request (GtkWindow *window)
 
   gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (self));
 
-  g_signal_connect (dlg, "response", G_CALLBACK (delete_response), self);
+  g_signal_connect_swapped (dlg, "response::close", G_CALLBACK (close_response), self);
 
   gtk_widget_show (dlg);
 


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