-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
92 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
mod zoom_controls; | ||
pub use zoom_controls::*; | ||
|
||
mod style_switcher; | ||
pub use style_switcher::*; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
use glib::Properties; | ||
use gtk::subclass::prelude::*; | ||
use gtk::{prelude::*, CompositeTemplate}; | ||
/// This file is work derived from Black Box | ||
/// | ||
/// Copyright 2023 Paulo Queiroz <[email protected]> | ||
|
@@ -17,29 +20,27 @@ | |
/// | ||
/// SPDX-License-Identifier: GPL-3.0-or-later | ||
/// | ||
use glib::clone; | ||
use gtk::subclass::prelude::*; | ||
use gtk::{prelude::*, CompositeTemplate}; | ||
use std::cell::RefCell; | ||
use tracing::*; | ||
|
||
use crate::settings::{Settings, StylePreference}; | ||
|
||
#[derive(Debug, Default, CompositeTemplate)] | ||
#[template(resource = "/io/github/vhdirk/Terms/gtk/style_switcher.ui")] | ||
#[derive(Debug, Default, CompositeTemplate, Properties)] | ||
#[template(resource = "/io/github/vhdirk/Tile/gtk/style_switcher.ui")] | ||
#[properties(wrapper_type=super::StyleSwitcher)] | ||
pub struct StyleSwitcher { | ||
settings: Settings, | ||
|
||
#[template_child] | ||
pub system_selector: TemplateChild<gtk::CheckButton>, | ||
#[template_child] | ||
pub light_selector: TemplateChild<gtk::CheckButton>, | ||
#[template_child] | ||
pub dark_selector: TemplateChild<gtk::CheckButton>, | ||
|
||
#[property(get, set=Self::set_style_preference ,construct, default="system")] | ||
pub preference: RefCell<String>, | ||
} | ||
|
||
#[glib::object_subclass] | ||
impl ObjectSubclass for StyleSwitcher { | ||
const NAME: &'static str = "TermsStyleSwitcher"; | ||
const NAME: &'static str = "TileStyleSwitcher"; | ||
type Type = super::StyleSwitcher; | ||
type ParentType = gtk::Widget; | ||
|
||
|
@@ -53,63 +54,53 @@ impl ObjectSubclass for StyleSwitcher { | |
obj.init_template(); | ||
} | ||
} | ||
|
||
#[glib::derived_properties] | ||
impl ObjectImpl for StyleSwitcher { | ||
fn constructed(&self) { | ||
self.parent_constructed(); | ||
|
||
self.settings | ||
.connect_style_preference_changed(clone!(@weak self as this => move |_| this.on_style_changed())); | ||
self.on_style_changed(); | ||
} | ||
} | ||
|
||
impl WidgetImpl for StyleSwitcher {} | ||
|
||
#[gtk::template_callbacks] | ||
impl StyleSwitcher { | ||
fn on_style_changed(&self) { | ||
info!("on style changed"); | ||
fn set_style_preference(&self, preference: &str) { | ||
let _system_guard = self.system_selector.freeze_notify(); | ||
let _light_guard = self.light_selector.freeze_notify(); | ||
let _dark_guard = self.dark_selector.freeze_notify(); | ||
|
||
match self.settings.style_preference() { | ||
StylePreference::System => { | ||
match preference { | ||
"system" => { | ||
self.system_selector.set_active(true); | ||
self.light_selector.set_active(false); | ||
self.dark_selector.set_active(false); | ||
}, | ||
StylePreference::Light => { | ||
"light" => { | ||
self.system_selector.set_active(false); | ||
self.light_selector.set_active(true); | ||
self.dark_selector.set_active(false); | ||
}, | ||
StylePreference::Dark => { | ||
"dark" => { | ||
self.system_selector.set_active(false); | ||
self.light_selector.set_active(false); | ||
self.dark_selector.set_active(true); | ||
}, | ||
_ => { | ||
warn!("Invalid style preference: {:?}", preference) | ||
}, | ||
} | ||
} | ||
|
||
#[template_callback] | ||
fn theme_check_active_changed(&self) { | ||
info!("theme_check_active_changed"); | ||
|
||
if self.system_selector.is_active() { | ||
self.change_style_preference(StylePreference::System); | ||
self.preference.set("system".to_string()); | ||
} else if self.light_selector.is_active() { | ||
self.change_style_preference(StylePreference::Light); | ||
self.preference.set("light".to_string()); | ||
} else if self.dark_selector.is_active() { | ||
self.change_style_preference(StylePreference::Dark); | ||
} | ||
} | ||
|
||
fn change_style_preference(&self, style_pref: StylePreference) { | ||
if self.settings.style_preference() != style_pref { | ||
info!("Setting style preference {:?}", style_pref); | ||
self.settings.set_style_preference(style_pref); | ||
self.preference.set("dark".to_string()); | ||
} | ||
self.obj().notify_preference(); | ||
} | ||
} |
Oops, something went wrong.