summaryrefslogtreecommitdiffstats
path: root/tests/interactive/gapplication.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
commitf9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7 (patch)
treece9e8db2d4e8799780fa72ae8f1953039373e2ee /tests/interactive/gapplication.js
parentInitial commit. (diff)
downloadgnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.tar.xz
gnome-shell-f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7.zip
Adding upstream version 3.38.6.upstream/3.38.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/interactive/gapplication.js')
-rwxr-xr-xtests/interactive/gapplication.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/interactive/gapplication.js b/tests/interactive/gapplication.js
new file mode 100755
index 0000000..ec38b80
--- /dev/null
+++ b/tests/interactive/gapplication.js
@@ -0,0 +1,104 @@
+#!/usr/bin/env gjs
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+imports.gi.versions = { Gdk: '3.0', Gtk: '3.0' };
+const { Gdk, Gio, GLib, Gtk } = imports.gi;
+
+function do_action(action, parameter) {
+ print ("Action '" + action.name + "' invoked");
+}
+
+function do_action_param(action, parameter) {
+ print ("Action '" + action.name + "' invoked with parameter " + parameter.print(true));
+}
+
+function do_action_toggle(action) {
+ action.set_state(GLib.Variant.new('b', !action.state.deep_unpack()));
+ print ("Toggled");
+}
+
+function do_action_state_change(action) {
+ print ("Action '" + action.name + "' has now state " + action.state.print(true));
+}
+
+function main() {
+ Gtk.init(null);
+ Gdk.set_program_class('test-gjsgapp');
+
+ let app = new Gtk.Application({ application_id: 'org.gnome.Shell.GtkApplicationTest' });
+ app.connect('activate', () => {
+ print ("Activated");
+ });
+
+ let action = new Gio.SimpleAction({ name: 'one' });
+ action.connect('activate', do_action);
+ app.add_action(action);
+
+ action = new Gio.SimpleAction({ name: 'two' });
+ action.connect('activate', do_action);
+ app.add_action(action);
+
+ action = new Gio.SimpleAction({ name: 'toggle', state: GLib.Variant.new('b', false) });
+ action.connect('activate', do_action_toggle);
+ action.connect('notify::state', do_action_state_change);
+ app.add_action(action);
+
+ action = new Gio.SimpleAction({ name: 'disable', enabled: false });
+ action.set_enabled(false);
+ action.connect('activate', do_action);
+ app.add_action(action);
+
+ action = new Gio.SimpleAction({ name: 'parameter-int', parameter_type: GLib.VariantType.new('u') });
+ action.connect('activate', do_action_param);
+ app.add_action(action);
+
+ action = new Gio.SimpleAction({ name: 'parameter-string', parameter_type: GLib.VariantType.new('s') });
+ action.connect('activate', do_action_param);
+ app.add_action(action);
+
+ let menu = new Gio.Menu();
+ menu.append('An action', 'app.one');
+
+ let section = new Gio.Menu();
+ section.append('Another action', 'app.two');
+ section.append('Same as above', 'app.two');
+ menu.append_section(null, section);
+
+ // another section, to check separators
+ section = new Gio.Menu();
+ section.append('Checkbox', 'app.toggle');
+ section.append('Disabled', 'app.disable');
+ section.append('Missing Action', 'app.no-action');
+ menu.append_section('Subsection', section);
+
+ // empty sections or submenus should be invisible
+ menu.append_section('Empty section', new Gio.Menu());
+ menu.append_submenu('Empty submenu', new Gio.Menu());
+
+ let submenu = new Gio.Menu();
+ submenu.append('Open c:\\', 'app.parameter-string::c:\\');
+ submenu.append('Open /home', 'app.parameter-string::/home');
+ menu.append_submenu('Recent files', submenu);
+
+ let item = Gio.MenuItem.new('Say 42', null);
+ item.set_action_and_target_value('app.parameter-int', GLib.Variant.new('u', 42));
+ menu.append_item(item);
+
+ item = Gio.MenuItem.new('Say 43', null);
+ item.set_action_and_target_value('app.parameter-int', GLib.Variant.new('u', 43));
+ menu.append_item(item);
+
+ let window = null;
+
+ app.connect_after('startup', app => {
+ app.set_app_menu(menu);
+ window = new Gtk.ApplicationWindow({ title: "Test Application", application: app });
+ });
+ app.connect('activate', app => {
+ window.present();
+ });
+
+ app.run(null);
+}
+
+main();