application: Subclass AdwApplication
AdwApplication automatically handles styling for us.
This commit is contained in:
parent
1687411536
commit
0c62962d06
3 changed files with 7 additions and 8 deletions
|
|
@ -4,6 +4,6 @@
|
||||||
<file compressed="true" preprocess="xml-stripblanks">gtk/help_overlay.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">gtk/help_overlay.ui</file>
|
||||||
<file compressed="true" preprocess="xml-stripblanks">gtk/window.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">gtk/window.ui</file>
|
||||||
<file compressed="true" preprocess="xml-stripblanks">gtk/image_view.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">gtk/image_view.ui</file>
|
||||||
<file>image-viewer.css</file>
|
<file>style.css</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ use glib::subclass::prelude::*;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk_macros::*;
|
use gtk_macros::*;
|
||||||
|
use libadwaita::subclass::prelude::*;
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::window::IvWindow;
|
use crate::window::IvWindow;
|
||||||
|
|
@ -44,7 +45,7 @@ mod imp {
|
||||||
impl ObjectSubclass for IvApplication {
|
impl ObjectSubclass for IvApplication {
|
||||||
const NAME: &'static str = "IvApplication";
|
const NAME: &'static str = "IvApplication";
|
||||||
type Type = super::IvApplication;
|
type Type = super::IvApplication;
|
||||||
type ParentType = gtk::Application;
|
type ParentType = libadwaita::Application;
|
||||||
|
|
||||||
// Initialize with default values
|
// Initialize with default values
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
|
|
@ -60,11 +61,7 @@ mod imp {
|
||||||
fn constructed(&self, obj: &Self::Type) {
|
fn constructed(&self, obj: &Self::Type) {
|
||||||
self.parent_constructed(obj);
|
self.parent_constructed(obj);
|
||||||
|
|
||||||
// Set up the CSS and force dark theme
|
// Force dark theme
|
||||||
let display = gdk::Display::default().unwrap();
|
|
||||||
let provider = gtk::CssProvider::new();
|
|
||||||
provider.load_from_resource("/org/gnome/ImageViewer/image-viewer.css");
|
|
||||||
gtk::StyleContext::add_provider_for_display(&display, &provider, 600);
|
|
||||||
self.gtk_settings
|
self.gtk_settings
|
||||||
.set_gtk_application_prefer_dark_theme(true);
|
.set_gtk_application_prefer_dark_theme(true);
|
||||||
|
|
||||||
|
|
@ -93,6 +90,7 @@ mod imp {
|
||||||
// This is empty, but we still need to provide an
|
// This is empty, but we still need to provide an
|
||||||
// empty implementation for each type we subclass.
|
// empty implementation for each type we subclass.
|
||||||
impl GtkApplicationImpl for IvApplication {}
|
impl GtkApplicationImpl for IvApplication {}
|
||||||
|
impl AdwApplicationImpl for IvApplication {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a wrapper struct that inherits the functions
|
// Creates a wrapper struct that inherits the functions
|
||||||
|
|
@ -101,7 +99,7 @@ mod imp {
|
||||||
// IvApplication without casting.
|
// IvApplication without casting.
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct IvApplication(ObjectSubclass<imp::IvApplication>)
|
pub struct IvApplication(ObjectSubclass<imp::IvApplication>)
|
||||||
@extends gio::Application, gtk::Application,
|
@extends gio::Application, gtk::Application, libadwaita::Application,
|
||||||
@implements gio::ActionGroup, gio::ActionMap;
|
@implements gio::ActionGroup, gio::ActionMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,6 +110,7 @@ impl IvApplication {
|
||||||
glib::Object::new(&[
|
glib::Object::new(&[
|
||||||
("application-id", &config::APP_ID.to_string()),
|
("application-id", &config::APP_ID.to_string()),
|
||||||
("flags", &gio::ApplicationFlags::HANDLES_OPEN),
|
("flags", &gio::ApplicationFlags::HANDLES_OPEN),
|
||||||
|
("resource-base-path", &"/org/gnome/ImageViewer/".to_string()),
|
||||||
])
|
])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue