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>
<item>
<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>
</item>
<item>
<attribute name="label" translatable="yes">_Import Shows</attribute>
<attribute name="action">app.import</attribute>
<attribute name="action">win.import</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Export Shows</attribute>
<attribute name="action">app.export</attribute>
<attribute name="action">win.export</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
<attribute name="action">win.preferences</attribute>
</item>
</section>
<section>
@ -30,11 +30,11 @@
</item>
<item>
<attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">app.help</attribute>
<attribute name="action">win.help</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About</attribute>
<attribute name="action">app.about</attribute>
<attribute name="action">win.about</attribute>
</item>
</section>
</menu>

View File

@ -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", &["<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| {
// 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: &gtk::Application, sender: &Sender<Action>) {
fn setup_gactions(win: &gtk::ApplicationWindow, sender: &Sender<Action>) {
// 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", &["<primary>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", &["<primary>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) {

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"))
}
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 gtk::{FileChooserAction, FileChooserNative, FileFilter, ResponseType};

View File

@ -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: &gtk::Window) {
pub fn about_dialog(window: &gtk::ApplicationWindow) {
// Feel free to add yourself if you contribured.
let authors = &[
"Constantin Nickel",