[gnome-builder] libide/tweaks: allow displaying tweaks in GTK window



commit 8ac4fe4ebfe1200115845780c6e3326e0f5e6e28
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jul 31 14:08:49 2022 -0700

    libide/tweaks: allow displaying tweaks in GTK window

 src/libide/tweaks/tests/test-tweaks.c | 61 +++++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 21 deletions(-)
---
diff --git a/src/libide/tweaks/tests/test-tweaks.c b/src/libide/tweaks/tests/test-tweaks.c
index cf45b967a..7631f5bc6 100644
--- a/src/libide/tweaks/tests/test-tweaks.c
+++ b/src/libide/tweaks/tests/test-tweaks.c
@@ -37,12 +37,15 @@ main (int   argc,
   g_autoptr(GError) error = NULL;
   g_autofree char *expected = NULL;
   g_autofree char *expected_contents = NULL;
+  gboolean display = FALSE;
   gsize len = 0;
   const GOptionEntry entries[] = {
     { "expected", 'e', 0, G_OPTION_ARG_FILENAME, &expected, "File containing expected output" },
+    { "display", 'd', 0, G_OPTION_ARG_NONE, &display, "Display a window containin the tweaks" },
     { NULL }
   };
 
+  gtk_init ();
   gtk_source_init ();
   _ide_tweaks_init ();
 
@@ -88,28 +91,44 @@ main (int   argc,
   _ide_tweaks_item_printf (IDE_TWEAKS_ITEM (tweaks), string, 0);
 
   if (!expected)
+    g_print ("%s", string->str);
+
+  if (expected)
+    {
+      if (!g_file_get_contents (expected, &expected_contents, &len, &error))
+        g_error ("Failed to load expected contents: %s: %s", expected, error->message);
+
+      if (!ide_str_equal0 (expected_contents, string->str))
+        {
+          g_printerr ("Contents did not match.\n"
+                      "\n"
+                      "Expected:\n"
+                      "=========\n"
+                      "%s\n"
+                      "\n"
+                      "Got:\n"
+                      "====\n"
+                      "%s\n",
+                      expected_contents,
+                      string->str);
+          return EXIT_FAILURE;
+        }
+    }
+
+  if (display)
     {
-      g_print ("%s", string->str);
-      return EXIT_SUCCESS;
+      GtkWidget *window = ide_tweaks_window_new ();
+      g_autoptr(GMainLoop) main_loop = g_main_loop_new (NULL, FALSE);
+
+      ide_tweaks_window_set_tweaks (IDE_TWEAKS_WINDOW (window), tweaks);
+
+      g_signal_connect_swapped (window,
+                                "close-request",
+                                G_CALLBACK (g_main_loop_quit),
+                                main_loop);
+      gtk_window_present (GTK_WINDOW (window));
+      g_main_loop_run (main_loop);
     }
 
-  if (!g_file_get_contents (expected, &expected_contents, &len, &error))
-    g_error ("Failed to load expected contents: %s: %s", expected, error->message);
-
-  if (ide_str_equal0 (expected_contents, string->str))
-    return EXIT_SUCCESS;
-
-  g_printerr ("Contents did not match.\n"
-              "\n"
-              "Expected:\n"
-              "=========\n"
-              "%s\n"
-              "\n"
-              "Got:\n"
-              "====\n"
-              "%s\n",
-              expected_contents,
-              string->str);
-
-  return EXIT_FAILURE;
+  return EXIT_SUCCESS;
 }


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