diff src/main.rs @ 5:cdbf3a2c9af8

Add a very simple menu.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 01 Nov 2020 14:34:02 +0100
parents 2e074d185151
children dd10331549c6
line wrap: on
line diff
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,6 @@
 use gio::prelude::*;
 use gtk::prelude::*;
+use glib::clone;
 
 use std::env::args;
 use std::fs::{File, OpenOptions};
@@ -200,6 +201,38 @@ struct State {
 }
 
 fn build_ui(application: &gtk::Application) {
+    let quit = gio::SimpleAction::new("quit", None);
+    application.set_accels_for_action("app.quit", &["<Control>q"]);
+    application.add_action(&quit);
+    quit.connect_activate(clone!(@weak application => move |_, _| application.quit()));
+
+    let about = gio::SimpleAction::new("about", None);
+    application.add_action(&about);
+    about.connect_activate(|_, _| {
+        let about = gtk::AboutDialog::new();
+        about.set_program_name("TabletEmu");
+        about.set_logo_icon_name(Some("input-tablet"));
+        about.set_website(Some("https://hg.linkmauve.fr/tablet-emu"));
+        about.set_version(Some("0.1"));
+        about.set_license_type(gtk::License::Agpl30);
+        about.set_program_name("TabletEmu");
+        about.run();
+        unsafe { about.destroy(); }
+    });
+
+    let menu = gio::Menu::new();
+    {
+        let file = gio::Menu::new();
+        file.append(Some("_Quit"), Some("app.quit"));
+        menu.append_submenu(Some("_File"), &file);
+    }
+    {
+        let help = gio::Menu::new();
+        help.append(Some("_About"), Some("app.about"));
+        menu.append_submenu(Some("_Help"), &help);
+    }
+    application.set_menubar(Some(&menu));
+
     let dev = match create_uinput_device() {
         Ok(dev) => dev,
         Err(err) => {