Hello! I have been trying to add a back button to an accelerator in gtk4.
I am not sure if I am going in the right direction and would like some pointers here.
use gtk;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};
use gtk::gio;
fn main() {
let application = Application::builder()
.application_id("com.example.FirstGtkApp")
.build();
application.connect_activate(|app| {
let window = ApplicationWindow::builder()
.application(app)
.title("First GTK Program")
.default_width(350)
.default_height(70)
.build();
let back_action = gio::SimpleAction::new("back", None);
back_action.connect_activate(|_, _| {
eprintln!("Back!");
});
app.set_accels_for_action("app.back", &["<Alt>Left", "Back"]);
app.add_action(&back_action);
let button = Button::with_label("Click me!");
button.connect_clicked(|_| {
eprintln!("Clicked!");
});
window.set_child(Some(&button));
window.show();
});
application.run();
}
I modified the example to include an action on the button press.
Here the action gets called if I use the Left combo, but not if I press the back button.
Should I go a different route binding it?
So If I press Alt+Left now it activates the action, but not on the back button.
I don’t want to connect a button, the button is just here because it is from the gtk4-rs example and I thought it would be easier for people to understand if it is something familiar.
This is a more minimal example:
use gtk;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};
use gtk::gio;
fn main() {
let application = Application::builder().build();
application.connect_activate(|app| {
let window = ApplicationWindow::builder()
.application(app).build();
let back_action = gio::SimpleAction::new("back", None);
back_action.connect_activate(|_, _| {
eprintln!("Back!");
});
app.set_accels_for_action("app.back", &["<Alt>Left", "Back"]);
app.add_action(&back_action);
window.show();
});
application.run();
}