Commit ba2f81ad authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

subclass Window

parent 11723557
......@@ -16,7 +16,7 @@ mod imp {
#[derive(Debug, Default)]
pub struct Application {
pub(super) window: OnceCell<Window>,
pub(super) window: OnceCell<WeakRef<Window>>,
}
#[glib::object_subclass]
......@@ -30,11 +30,12 @@ mod imp {
impl ApplicationImpl for Application {
fn activate(&self, application: &Self::Type) {
let window = Window::new(&application);
application.add_window(&window.widget);
window.widget.present();
self.window.set(window);
application.add_window(&window);
window.present();
self.window.set(window.downgrade()).unwrap();
self.parent_activate(application);
}
fn startup(&self, application: &Self::Type) {
// Quit
utils::action(
......@@ -68,8 +69,8 @@ mod imp {
"next-page",
clone!(@weak application => move |_, _| {
let window = application.window();
if window.paginator.try_next().is_none() {
window.widget.close();
if window.paginator().try_next().is_none() {
window.close();
}
}),
);
......@@ -79,7 +80,7 @@ mod imp {
"previous-page",
clone!(@weak application => move |_, _| {
let window = application.window();
if window.paginator.try_previous().is_none() {
if window.paginator().try_previous().is_none() {
window.reset_tour();
}
}),
......@@ -107,9 +108,8 @@ impl Application {
.unwrap()
}
fn window(&self) -> &Window {
// and_then(|w| w.upgrade())
self.imp().window.get().unwrap()
fn window(&self) -> Window {
self.imp().window.get().and_then(|w| w.upgrade()).unwrap()
}
pub fn run() {
......
......@@ -212,3 +212,9 @@ impl PaginatorWidget {
}
}
}
impl Default for PaginatorWidget {
fn default() -> Self {
Self::new()
}
}
use adw::prelude::*;
use gettextrs::gettext;
use gtk::subclass::prelude::*;
use gtk::{gio, glib};
use super::pages::{ImagePageWidget, WelcomePageWidget};
use super::paginator::PaginatorWidget;
use crate::config::{APP_ID, PROFILE};
use crate::Application;
#[derive(Debug)]
pub struct Window {
pub widget: adw::ApplicationWindow,
pub paginator: PaginatorWidget,
mod imp {
use super::*;
use crate::config;
use adw::subclass::prelude::*;
#[derive(Debug, Default)]
pub struct Window {
pub(super) paginator: PaginatorWidget,
}
#[glib::object_subclass]
impl ObjectSubclass for Window {
const NAME: &'static str = "Window";
type Type = super::Window;
type ParentType = adw::ApplicationWindow;
}
impl ObjectImpl for Window {
fn constructed(&self, widget: &Self::Type) {
widget.set_default_size(960, 720);
widget.set_icon_name(Some(config::APP_ID));
// Devel Profile
if config::PROFILE == "Devel" {
widget.add_css_class("devel");
}
self.paginator.add_page(WelcomePageWidget::new().widget);
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/overview.svg",
gettext("Get an Overview"),
gettext("Press the Super key to see open windows and apps."),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/search.svg",
gettext("Just Type to Search"),
gettext("Type in the overview to search. Launch apps, find things."),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/workspaces.svg",
gettext("Keep on Top with Workspaces"),
gettext("Easily organize windows with the workspaces view."),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/blank.svg",
gettext("Up/Down for the Overview"),
gettext("On a touchpad, use three-finger vertical swipes. Try it!"),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/blank.svg",
gettext("Left/Right for Workspaces"),
gettext("On a touchpad, use three-finger horizontal swipes. Try it!"),
));
let last_page = ImagePageWidget::new(
"/org/gnome/Tour/ready-to-go.svg",
gettext("That's it. Have a nice day!"),
gettext("To get more advice and tips, see the Help app."),
);
last_page.add_css_class("last-page");
self.paginator.add_page(last_page);
widget.set_content(Some(&self.paginator));
self.parent_constructed(widget);
}
}
impl WidgetImpl for Window {}
impl WindowImpl for Window {}
impl ApplicationWindowImpl for Window {}
impl AdwApplicationWindowImpl for Window {}
}
glib::wrapper! {
pub struct Window(ObjectSubclass<imp::Window>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::ApplicationWindow,
@implements gio::ActionMap, gio::ActionGroup;
}
impl Window {
pub fn new(app: &Application) -> Self {
let widget = adw::ApplicationWindow::new(app);
let paginator = PaginatorWidget::new();
let mut window_widget = Window { widget, paginator };
glib::Object::new(&[("application", app)]).unwrap()
}
window_widget.init();
window_widget
pub fn paginator(&self) -> PaginatorWidget {
self.imp().paginator.clone()
}
pub fn start_tour(&self) {
self.paginator.set_page(1);
self.imp().paginator.set_page(1);
}
pub fn reset_tour(&self) {
self.paginator.set_page(0);
}
fn init(&mut self) {
self.widget.set_default_size(960, 720);
self.widget.set_icon_name(Some(APP_ID));
// Devel Profile
if PROFILE == "Devel" {
self.widget.add_css_class("devel");
}
self.paginator.add_page(WelcomePageWidget::new().widget);
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/overview.svg",
gettext("Get an Overview"),
gettext("Press the Super key to see open windows and apps."),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/search.svg",
gettext("Just Type to Search"),
gettext("Type in the overview to search. Launch apps, find things."),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/workspaces.svg",
gettext("Keep on Top with Workspaces"),
gettext("Easily organize windows with the workspaces view."),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/blank.svg",
gettext("Up/Down for the Overview"),
gettext("On a touchpad, use three-finger vertical swipes. Try it!"),
));
self.paginator.add_page(ImagePageWidget::new(
"/org/gnome/Tour/blank.svg",
gettext("Left/Right for Workspaces"),
gettext("On a touchpad, use three-finger horizontal swipes. Try it!"),
));
let last_page = ImagePageWidget::new(
"/org/gnome/Tour/ready-to-go.svg",
gettext("That's it. Have a nice day!"),
gettext("To get more advice and tips, see the Help app."),
);
last_page.add_css_class("last-page");
self.paginator.add_page(last_page);
self.widget.set_content(Some(&self.paginator));
self.imp().paginator.set_page(0);
}
}
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