[libdazzle] menus: add simple joined menu test



commit 366dac7bbfd69c7872e4615880fe58218d82dea5
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 10 16:52:40 2017 -0700

    menus: add simple joined menu test

 tests/data/menus/joined1.ui |   45 +++++++++++++++++++++++++++++
 tests/data/menus/joined2.ui |   20 +++++++++++++
 tests/meson.build           |    6 ++++
 tests/test-joined-menu.c    |   65 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 136 insertions(+), 0 deletions(-)
---
diff --git a/tests/data/menus/joined1.ui b/tests/data/menus/joined1.ui
new file mode 100644
index 0000000..8c522a0
--- /dev/null
+++ b/tests/data/menus/joined1.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<interface>
+  <menu id="document-menu">
+    <section id="editor-document-section">
+      <attribute name="label" translatable="yes">Document</attribute>
+      <item>
+        <attribute name="id">editor-document-open-in-new-frame</attribute>
+        <attribute name="label" translatable="yes">Open in New Frame</attribute>
+        <attribute name="action">layoutstack.open-in-new-frame</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Split</attribute>
+        <attribute name="action">layoutstack.split-view</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Print…</attribute>
+        <attribute name="action">editor-view.print</attribute>
+      </item>
+    </section>
+    <section id="editor-document-preferences-section">
+      <attribute name="after">editor-document-section</attribute>
+      <item>
+        <attribute name="label" translatable="yes">Document Preferences</attribute>
+      </item>
+    </section>
+    <section id="editor-document-save-section">
+      <attribute name="after">editor-document-preferences-section</attribute>
+      <item>
+        <attribute name="action">editor-view.save</attribute>
+        <attribute name="label" translatable="yes">_Save</attribute>
+      </item>
+      <item>
+        <attribute name="action">editor-view.save-as</attribute>
+        <attribute name="label" translatable="yes">Save _As</attribute>
+      </item>
+    </section>
+    <section id="editor-document-close-section">
+      <attribute name="after">editor-document-save-section</attribute>
+      <item>
+        <attribute name="action">layoutstack.close-view</attribute>
+        <attribute name="label" translatable="yes">Close</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/tests/data/menus/joined2.ui b/tests/data/menus/joined2.ui
new file mode 100644
index 0000000..4f49bac
--- /dev/null
+++ b/tests/data/menus/joined2.ui
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<interface>
+  <menu id="frame-menu">
+    <section id="ide-layout-stack-frame-section">
+      <attribute name="label" translatable="yes">Frame</attribute>
+      <item>
+        <attribute name="label" translatable="yes">Move Left</attribute>
+        <attribute name="action">layoutstack.move-left</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Move Right</attribute>
+        <attribute name="action">layoutstack.move-right</attribute>
+      </item>
+      <item>
+        <attribute name="action">layoutgrid.close-stack</attribute>
+        <attribute name="label" translatable="yes">Close</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/tests/meson.build b/tests/meson.build
index 57344c3..18a65d7 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -300,4 +300,10 @@ test_list_store = executable('test-list-store', 'test-list-store.c',
 )
 test('test-list-store', test_list_store, env: test_env)
 
+test_joined_menu = executable('test-joined-menu', 'test-joined-menu.c',
+        c_args: test_cflags,
+     link_args: test_link_args,
+  dependencies: libdazzle_deps + [libdazzle_dep],
+)
+
 endif
diff --git a/tests/test-joined-menu.c b/tests/test-joined-menu.c
new file mode 100644
index 0000000..f453888
--- /dev/null
+++ b/tests/test-joined-menu.c
@@ -0,0 +1,65 @@
+#include <dazzle.h>
+
+static void
+load_css (void)
+{
+  g_autoptr(GtkCssProvider) provider = NULL;
+
+  provider = dzl_css_provider_new ("resource:///org/gnome/dazzle/themes");
+  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+                                             GTK_STYLE_PROVIDER (provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
+gint
+main (gint argc,
+      gchar *argv[])
+{
+  GtkWidget *window;
+  GtkWidget *menu_button;
+  g_autoptr(DzlMenuManager) manager = NULL;
+  g_autoptr(DzlJoinedMenu) joined = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autofree gchar *filename1 = g_build_filename (TEST_DATA_DIR, "menus/joined1.ui", NULL);
+  g_autofree gchar *filename2 = g_build_filename (TEST_DATA_DIR, "menus/joined2.ui", NULL);
+  GMenu *menu1;
+  GMenu *menu2;
+
+  gtk_init (&argc, &argv);
+
+  load_css ();
+
+  manager = dzl_menu_manager_new ();
+
+  dzl_menu_manager_add_filename (manager, filename1, &error);
+  g_assert_no_error (error);
+  menu1 = dzl_menu_manager_get_menu_by_id (manager, "document-menu");
+
+  dzl_menu_manager_add_filename (manager, filename2, &error);
+  g_assert_no_error (error);
+  menu2 = dzl_menu_manager_get_menu_by_id (manager, "frame-menu");
+
+  joined = dzl_joined_menu_new ();
+  dzl_joined_menu_append_menu (joined, G_MENU_MODEL (menu1));
+  dzl_joined_menu_append_menu (joined, G_MENU_MODEL (menu2));
+
+  window = g_object_new (GTK_TYPE_WINDOW,
+                         "default-width", 100,
+                         "default-height", 100,
+                         "border-width", 32,
+                         "title", "Joined Menu Test",
+                         NULL);
+  menu_button = g_object_new (DZL_TYPE_MENU_BUTTON,
+                              "show-arrow", TRUE,
+                              "icon-name", "document-open-symbolic",
+                              "model", joined,
+                              "visible", TRUE,
+                              NULL);
+  gtk_container_add (GTK_CONTAINER (window), menu_button);
+  g_signal_connect (window, "delete-event", gtk_main_quit, NULL);
+  gtk_window_present (GTK_WINDOW (window));
+
+  gtk_main ();
+
+  return 0;
+}


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