Commit f35f9618 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Move more actions to window

parent 3b28bd39
......@@ -23,7 +23,7 @@
<property name="icon-name">left-large-symbolic</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="action-name">app.previous-page</property>
<property name="action-name">win.previous-page</property>
<property name="tooltip-text" translatable="yes">Previous</property>
<style>
<class name="circular" />
......@@ -36,7 +36,7 @@
<property name="icon-name">right-large-symbolic</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="action-name">app.next-page</property>
<property name="action-name">win.next-page</property>
<property name="tooltip-text" translatable="yes">Next</property>
<style>
<class name="circular" />
......@@ -49,7 +49,7 @@
<property name="icon-name">right-large-symbolic</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="action-name">app.start-tour</property>
<property name="action-name">win.start-tour</property>
<property name="tooltip-text" translatable="yes">Start</property>
<style>
<class name="suggested-action" />
......
......@@ -39,36 +39,10 @@ mod imp {
let quit = gio::ActionEntry::builder("quit")
.activate(move |app: &Self::Type, _, _| app.quit())
.build();
// Start Tour
let start_tour = gio::ActionEntry::builder("start-tour")
.activate(move |app: &Self::Type, _, _| app.window().start_tour())
.build();
// Skip Tour
let skip_tour = gio::ActionEntry::builder("skip-tour")
.activate(move |app: &Self::Type, _, _| app.quit())
.build();
// Next page
let next_page = gio::ActionEntry::builder("next-page")
.activate(move |app: &Self::Type, _, _| {
let window = app.window();
if window.paginator().try_next().is_none() {
window.close();
}
})
.build();
// Previous page
let previous_page = gio::ActionEntry::builder("previous-page")
.activate(move |app: &Self::Type, _, _| {
let window = app.window();
if window.paginator().try_previous().is_none() {
window.reset_tour();
}
})
.build();
application.add_action_entries([quit, start_tour, skip_tour, next_page, previous_page]);
application.add_action_entries([quit]);
application.set_accels_for_action("app.quit", &["<Control>q"]);
application.set_accels_for_action("app.skip-tour", &["Escape"]);
application.set_accels_for_action("win.skip-tour", &["Escape"]);
}
}
impl GtkApplicationImpl for Application {}
......@@ -82,10 +56,6 @@ glib::wrapper! {
}
impl Application {
fn window(&self) -> Window {
self.imp().window.get().and_then(|w| w.upgrade()).unwrap()
}
pub fn run() -> glib::ExitCode {
log::info!("GNOME Tour ({})", config::APP_ID);
log::info!("Version: {} ({})", config::VERSION, config::PROFILE);
......
......@@ -110,7 +110,7 @@ impl PaginatorWidget {
Some(())
}
pub fn add_page(&self, page: impl IsA<gtk::Widget>) {
fn add_page(&self, page: impl IsA<gtk::Widget>) {
let imp = self.imp();
let page_nr = imp.pages.borrow().len();
imp.carousel.insert(&page, page_nr as i32);
......
......@@ -29,6 +29,24 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
// Start Tour
klass.install_action("win.start-tour", None, |win, _, _| win.start_tour());
// Skip Tour
klass.install_action("win.skip-tour", None, |win, _, _| {
win.application().unwrap().quit();
});
// Next page
klass.install_action("win.next-page", None, |win, _, _| {
if win.imp().paginator.try_next().is_none() {
win.close();
}
});
// Previous page
klass.install_action("win.previous-page", None, |win, _, _| {
if win.imp().paginator.try_previous().is_none() {
win.reset_tour();
}
});
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
......@@ -74,10 +92,6 @@ impl Window {
glib::Object::builder().property("application", app).build()
}
pub fn paginator(&self) -> PaginatorWidget {
self.imp().paginator.clone()
}
pub fn start_tour(&self) {
self.imp().paginator.set_page(1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment