From ee23df176df143a2808a3ae2c4a68029124670f4 Mon Sep 17 00:00:00 2001 From: Zander Brown Date: Thu, 7 Jun 2018 18:06:36 +0100 Subject: [PATCH] Our GActions don't need to be in the app namespace --- hammond-gtk/resources/gtk/menus.ui | 12 ++++----- hammond-gtk/src/app.rs | 36 ++++++++++++++------------ hammond-gtk/src/utils.rs | 2 +- hammond-gtk/src/widgets/aboutdialog.rs | 2 +- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/hammond-gtk/resources/gtk/menus.ui b/hammond-gtk/resources/gtk/menus.ui index 58de81a..55d2877 100644 --- a/hammond-gtk/resources/gtk/menus.ui +++ b/hammond-gtk/resources/gtk/menus.ui @@ -5,22 +5,22 @@
_Check for new episodes - app.refresh + win.refresh <primary>r _Import Shows - app.import + win.import _Export Shows - app.export + win.export
_Preferences - app.preferences + win.preferences
@@ -30,11 +30,11 @@ _Help - app.help + win.help _About - app.about + win.about
diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 8490fa5..3d9f4fb 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -77,7 +77,10 @@ impl App { application.connect_startup(clone!(settings => move |app| { let (sender, receiver) = unbounded(); - App::setup_gactions(&app, &sender); + app.set_accels_for_action("win.refresh", &["r"]); + app.set_accels_for_action("win.quit", &["q"]); + // Bind the hamburger menu button to `F10` + app.set_accels_for_action("win.menu", &["F10"]); app.connect_activate(clone!(sender, settings => move |app| { // Get the current window (if any) @@ -90,6 +93,8 @@ impl App { let window = gtk::ApplicationWindow::new(&app); window.set_title("Hammond"); + App::setup_gactions(&window, &sender); + window.connect_delete_event(clone!(app, settings => move |window, _| { WindowGeometry::from_window(&window).write(&settings); app.quit(); @@ -240,12 +245,12 @@ impl App { /// Define the `GAction`s. /// /// Used in menus and the keyboard shortcuts dialog. - fn setup_gactions(app: >k::Application, sender: &Sender) { + fn setup_gactions(win: >k::ApplicationWindow, sender: &Sender) { // Create the `refresh` action. // // This will trigger a refresh of all the shows in the database. action!( - app, + win, "refresh", clone!(sender => move |_, _| { gtk::idle_add(clone!(sender => move || { @@ -255,34 +260,31 @@ impl App { })); }) ); - app.set_accels_for_action("app.refresh", &["r"]); // Create the `OPML` import action action!( - app, + win, "import", - clone!(sender, app => move |_, _| { - let window = app.get_active_window().expect("Failed to get active window"); - utils::on_import_clicked(&window, &sender); + clone!(sender, win => move |_, _| { + utils::on_import_clicked(&win, &sender); }) ); // Create the action that shows a `gtk::AboutDialog` action!( - app, + win, "about", - clone!(app => move |_, _| { - let window = app.get_active_window().expect("Failed to get active window"); - about_dialog(&window); + clone!(win => move |_, _| { + about_dialog(&win); }) ); // Create the quit action - action!(app, "quit", clone!(app => move |_, _| app.quit())); - app.set_accels_for_action("app.quit", &["q"]); - - // Bind the hamburger menu button to `F10` - app.set_accels_for_action("win.menu", &["F10"]); + action!( + win, + "quit", + clone!(win => move |_, _| win.get_application().expect("Failed to get application").quit()) + ); } pub fn run(self) { diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 4c44368..d6d7b6f 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -334,7 +334,7 @@ fn lookup_id(id: u32) -> Result { .ok_or_else(|| format_err!("Failed to get url from itunes response")) } -pub fn on_import_clicked(window: >k::Window, sender: &Sender) { +pub fn on_import_clicked(window: >k::ApplicationWindow, sender: &Sender) { use glib::translate::ToGlib; use gtk::{FileChooserAction, FileChooserNative, FileFilter, ResponseType}; diff --git a/hammond-gtk/src/widgets/aboutdialog.rs b/hammond-gtk/src/widgets/aboutdialog.rs index eaf9374..1b2a4ac 100644 --- a/hammond-gtk/src/widgets/aboutdialog.rs +++ b/hammond-gtk/src/widgets/aboutdialog.rs @@ -4,7 +4,7 @@ use gtk::prelude::*; // Totally copied it from fractal. // https://gitlab.gnome.org/danigm/fractal/blob/503e311e22b9d7540089d735b92af8e8f93560c5/fractal-gtk/src/app.rs#L1883-1912 /// Given a `window` create and attach an `gtk::AboutDialog` to it. -pub fn about_dialog(window: >k::Window) { +pub fn about_dialog(window: >k::ApplicationWindow) { // Feel free to add yourself if you contribured. let authors = &[ "Constantin Nickel",