Merge branch 'master' into 'master'

Our GActions don't need to be in the app namespace

See merge request World/hammond!39
This commit is contained in:
Jordan Petridis 2018-06-07 17:37:12 +00:00
commit b0f0940605
4 changed files with 27 additions and 25 deletions

View File

@ -5,22 +5,22 @@
<section> <section>
<item> <item>
<attribute name="label" translatable="yes">_Check for new episodes</attribute> <attribute name="label" translatable="yes">_Check for new episodes</attribute>
<attribute name="action">app.refresh</attribute> <attribute name="action">win.refresh</attribute>
<attribute name="accel">&lt;primary&gt;r</attribute> <attribute name="accel">&lt;primary&gt;r</attribute>
</item> </item>
<item> <item>
<attribute name="label" translatable="yes">_Import Shows</attribute> <attribute name="label" translatable="yes">_Import Shows</attribute>
<attribute name="action">app.import</attribute> <attribute name="action">win.import</attribute>
</item> </item>
<item> <item>
<attribute name="label" translatable="yes">_Export Shows</attribute> <attribute name="label" translatable="yes">_Export Shows</attribute>
<attribute name="action">app.export</attribute> <attribute name="action">win.export</attribute>
</item> </item>
</section> </section>
<section> <section>
<item> <item>
<attribute name="label" translatable="yes">_Preferences</attribute> <attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute> <attribute name="action">win.preferences</attribute>
</item> </item>
</section> </section>
<section> <section>
@ -30,11 +30,11 @@
</item> </item>
<item> <item>
<attribute name="label" translatable="yes">_Help</attribute> <attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">app.help</attribute> <attribute name="action">win.help</attribute>
</item> </item>
<item> <item>
<attribute name="label" translatable="yes">_About</attribute> <attribute name="label" translatable="yes">_About</attribute>
<attribute name="action">app.about</attribute> <attribute name="action">win.about</attribute>
</item> </item>
</section> </section>
</menu> </menu>

View File

@ -77,7 +77,10 @@ impl App {
application.connect_startup(clone!(settings => move |app| { application.connect_startup(clone!(settings => move |app| {
let (sender, receiver) = unbounded(); let (sender, receiver) = unbounded();
App::setup_gactions(&app, &sender); app.set_accels_for_action("win.refresh", &["<primary>r"]);
app.set_accels_for_action("win.quit", &["<primary>q"]);
// Bind the hamburger menu button to `F10`
app.set_accels_for_action("win.menu", &["F10"]);
app.connect_activate(clone!(sender, settings => move |app| { app.connect_activate(clone!(sender, settings => move |app| {
// Get the current window (if any) // Get the current window (if any)
@ -90,6 +93,8 @@ impl App {
let window = gtk::ApplicationWindow::new(&app); let window = gtk::ApplicationWindow::new(&app);
window.set_title("Hammond"); window.set_title("Hammond");
App::setup_gactions(&window, &sender);
window.connect_delete_event(clone!(app, settings => move |window, _| { window.connect_delete_event(clone!(app, settings => move |window, _| {
WindowGeometry::from_window(&window).write(&settings); WindowGeometry::from_window(&window).write(&settings);
app.quit(); app.quit();
@ -240,12 +245,12 @@ impl App {
/// Define the `GAction`s. /// Define the `GAction`s.
/// ///
/// Used in menus and the keyboard shortcuts dialog. /// Used in menus and the keyboard shortcuts dialog.
fn setup_gactions(app: &gtk::Application, sender: &Sender<Action>) { fn setup_gactions(win: &gtk::ApplicationWindow, sender: &Sender<Action>) {
// Create the `refresh` action. // Create the `refresh` action.
// //
// This will trigger a refresh of all the shows in the database. // This will trigger a refresh of all the shows in the database.
action!( action!(
app, win,
"refresh", "refresh",
clone!(sender => move |_, _| { clone!(sender => move |_, _| {
gtk::idle_add(clone!(sender => move || { gtk::idle_add(clone!(sender => move || {
@ -255,34 +260,31 @@ impl App {
})); }));
}) })
); );
app.set_accels_for_action("app.refresh", &["<primary>r"]);
// Create the `OPML` import action // Create the `OPML` import action
action!( action!(
app, win,
"import", "import",
clone!(sender, app => move |_, _| { clone!(sender, win => move |_, _| {
let window = app.get_active_window().expect("Failed to get active window"); utils::on_import_clicked(&win, &sender);
utils::on_import_clicked(&window, &sender);
}) })
); );
// Create the action that shows a `gtk::AboutDialog` // Create the action that shows a `gtk::AboutDialog`
action!( action!(
app, win,
"about", "about",
clone!(app => move |_, _| { clone!(win => move |_, _| {
let window = app.get_active_window().expect("Failed to get active window"); about_dialog(&win);
about_dialog(&window);
}) })
); );
// Create the quit action // Create the quit action
action!(app, "quit", clone!(app => move |_, _| app.quit())); action!(
app.set_accels_for_action("app.quit", &["<primary>q"]); win,
"quit",
// Bind the hamburger menu button to `F10` clone!(win => move |_, _| win.get_application().expect("Failed to get application").quit())
app.set_accels_for_action("win.menu", &["F10"]); );
} }
pub fn run(self) { pub fn run(self) {

View File

@ -334,7 +334,7 @@ fn lookup_id(id: u32) -> Result<String, Error> {
.ok_or_else(|| format_err!("Failed to get url from itunes response")) .ok_or_else(|| format_err!("Failed to get url from itunes response"))
} }
pub fn on_import_clicked(window: &gtk::Window, sender: &Sender<Action>) { pub fn on_import_clicked(window: &gtk::ApplicationWindow, sender: &Sender<Action>) {
use glib::translate::ToGlib; use glib::translate::ToGlib;
use gtk::{FileChooserAction, FileChooserNative, FileFilter, ResponseType}; use gtk::{FileChooserAction, FileChooserNative, FileFilter, ResponseType};

View File

@ -4,7 +4,7 @@ use gtk::prelude::*;
// Totally copied it from fractal. // Totally copied it from fractal.
// https://gitlab.gnome.org/danigm/fractal/blob/503e311e22b9d7540089d735b92af8e8f93560c5/fractal-gtk/src/app.rs#L1883-1912 // 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. /// Given a `window` create and attach an `gtk::AboutDialog` to it.
pub fn about_dialog(window: &gtk::Window) { pub fn about_dialog(window: &gtk::ApplicationWindow) {
// Feel free to add yourself if you contribured. // Feel free to add yourself if you contribured.
let authors = &[ let authors = &[
"Constantin Nickel", "Constantin Nickel",