1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-22 18:55:29 +03:00
aports/community/xfce4-vala/garcon-1-test.patch
Sertonix df6a394cec community/xfce4-vala: run tests
At least I think these are tests
2025-02-26 13:54:04 +00:00

113 lines
2.7 KiB
Diff

Patch-Source: https://gitlab.xfce.org/bindings/xfce4-vala/-/commit/1bb4b24802e857acf2f642a6dc8269606024badb
From 1bb4b24802e857acf2f642a6dc8269606024badb Mon Sep 17 00:00:00 2001
From: Mike Massonnet <mmassonnet@gmail.com>
Date: Sat, 20 Oct 2012 19:16:53 +0200
Subject: [PATCH] Add small test program for garcon-1
Build an applications menu with GTK+.
---
Makefile.am | 1 +
tests/garcon-1.vala | 91 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+)
create mode 100644 tests/garcon-1.vala
diff --git a/tests/garcon-1.vala b/tests/garcon-1.vala
new file mode 100644
index 0000000..540cf33
--- /dev/null
+++ b/tests/garcon-1.vala
@@ -0,0 +1,91 @@
+using Gtk;
+using Garcon;
+
+public class ButtonMenu : Gtk.Button {
+
+ private Gtk.Menu menu = null;
+ private Garcon.Menu apps_menu = null;
+
+ construct {
+ this.label = "Show Menu";
+ this.clicked.connect (() => {
+ menu.popup (null, null, null, 0, Gtk.get_current_event_time ());
+ });
+
+ init_menu ();
+ }
+
+ private void init_menu () {
+
+ /* Build an apps menu */
+ try {
+ apps_menu = new Garcon.Menu.applications ();
+ apps_menu.load (null);
+ } catch (Error ex) {
+ error ("Couldn't load applications menu.");
+ }
+
+ /* Create the gtk menu */
+ menu = new Gtk.Menu ();
+ create_menu_items (menu, apps_menu);
+ menu.show_all ();
+ }
+
+ private void create_menu_items (Gtk.Menu gtk_menu, Garcon.Menu menu) {
+ unowned List<Garcon.MenuItem> items;
+ Gtk.MenuItem mi = null;
+
+ /* Retrieves menu items */
+ items = @menu.get_elements ();
+
+ /* Create gtk menu items */
+ foreach (Garcon.MenuItem item in items) {
+ if (item is Garcon.MenuItem) {
+ mi = new Gtk.MenuItem.with_label (item.get_name ());
+ mi.set_data ("command", item.get_command());
+ mi.activate.connect ((mi) => {
+ message ("execute `%s'", mi.get_data<string> ("command"));
+ });
+ }
+ else if (item is Garcon.MenuSeparator) {
+ mi = new Gtk.SeparatorMenuItem ();
+ }
+ else if (item is Garcon.Menu) {
+ Garcon.Menu submenu = (Garcon.Menu)item;
+ if (submenu.get_items () == null)
+ continue;
+
+ mi = new Gtk.MenuItem.with_label (item.get_name ());
+
+ Gtk.Menu gtk_submenu = new Gtk.Menu ();
+ create_menu_items (gtk_submenu, submenu);
+ mi.set_submenu (gtk_submenu);
+ }
+ gtk_menu.add (mi);
+ }
+ }
+}
+
+public class GtkSample : Gtk.Window {
+
+ construct {
+ this.title = "Apps Menu";
+ this.destroy.connect (() => { Gtk.main_quit (); });
+
+ var button = new ButtonMenu ();
+ this.add (button);
+ }
+
+ static int main (string[] args) {
+ Gtk.init (ref args);
+ Garcon.set_environment ("XFCE");
+
+ var sample = new GtkSample ();
+ sample.show_all ();
+
+ Gtk.main ();
+
+ return 0;
+ }
+}
+
--
GitLab