Create several ways to quit the application #197
|
@ -34,6 +34,20 @@ const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
|
||||||
|
|
||||||
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/";
|
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/";
|
||||||
|
|
||||||
|
/// Sets up an application-global action, `app.quit`, which will terminate the application.
|
||||||
|
fn setup_app_close_action(app: &adw::Application) {
|
||||||
|
let action = ActionEntry::builder("quit")
|
||||||
|
.activate(|app: &adw::Application, _, _| {
|
||||||
|
// right now, stopping the application is dirt simple. But we could use this
|
||||||
|
// block to add extra code that does additional shutdown steps if we ever want
|
||||||
|
// some states that shouldn't be discarded.
|
||||||
|
app.quit();
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
app.add_action_entries([action]);
|
||||||
|
app.set_accels_for_action("app.quit", &["<Ctrl>Q"]);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// I still don't fully understand gio resources. resources_register_include! is convenient
|
// I still don't fully understand gio resources. resources_register_include! is convenient
|
||||||
// because I don't have to deal with filesystem locations at runtime. However, I think other
|
// because I don't have to deal with filesystem locations at runtime. However, I think other
|
||||||
|
@ -67,13 +81,7 @@ fn main() {
|
||||||
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
|
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
|
||||||
icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions"));
|
icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions"));
|
||||||
|
|
||||||
let app_close_action = ActionEntry::builder("quit")
|
setup_app_close_action(&adw_app);
|
||||||
.activate(|app: &adw::Application, _, _| {
|
|
||||||
app.quit();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
adw_app.add_action_entries([app_close_action]);
|
|
||||||
adw_app.set_accels_for_action("app.quit", &["<Ctrl>Q"]);
|
|
||||||
|
|
||||||
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());
|
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue