fix(settings): use localization
This commit is contained in:
@@ -159,9 +159,7 @@ impl Notedeck {
|
|||||||
1024usize * 1024usize * 1024usize * 1024usize
|
1024usize * 1024usize * 1024usize * 1024usize
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut settings_handler = SettingsHandler::new(&path);
|
let settings_handler = SettingsHandler::new(&path).load();
|
||||||
|
|
||||||
settings_handler.load();
|
|
||||||
|
|
||||||
let config = Config::new().set_ingester_threads(2).set_mapsize(map_size);
|
let config = Config::new().set_ingester_threads(2).set_mapsize(map_size);
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,9 @@ impl SettingsHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(&mut self) {
|
pub fn load(mut self) -> Self {
|
||||||
if self.migrate_to_settings_file().is_ok() {
|
if self.migrate_to_settings_file().is_ok() {
|
||||||
return;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.directory.get_file(SETTINGS_FILE.to_string()) {
|
match self.directory.get_file(SETTINGS_FILE.to_string()) {
|
||||||
@@ -107,6 +107,8 @@ impl SettingsHandler {
|
|||||||
self.current_settings = Some(Settings::default());
|
self.current_settings = Some(Settings::default());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self) {
|
pub fn save(&self) {
|
||||||
|
|||||||
@@ -112,9 +112,7 @@ impl ChromePanelAction {
|
|||||||
fn process(&self, ctx: &mut AppContext, chrome: &mut Chrome, ui: &mut egui::Ui) {
|
fn process(&self, ctx: &mut AppContext, chrome: &mut Chrome, ui: &mut egui::Ui) {
|
||||||
match self {
|
match self {
|
||||||
Self::SaveTheme(theme) => {
|
Self::SaveTheme(theme) => {
|
||||||
ui.ctx().options_mut(|o| {
|
ui.ctx().set_theme(*theme);
|
||||||
o.theme_preference = *theme;
|
|
||||||
});
|
|
||||||
ctx.settings_handler.set_theme(*theme);
|
ctx.settings_handler.set_theme(*theme);
|
||||||
ctx.settings_handler.save();
|
ctx.settings_handler.save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ use strum::Display;
|
|||||||
|
|
||||||
use crate::{nav::RouterAction, Damus, Route};
|
use crate::{nav::RouterAction, Damus, Route};
|
||||||
|
|
||||||
|
const THEME_LIGHT: &str = "Light";
|
||||||
|
const THEME_DARK: &str = "Dark";
|
||||||
|
|
||||||
|
const MIN_ZOOM: f32 = 0.5;
|
||||||
|
const MAX_ZOOM: f32 = 3.0;
|
||||||
|
const ZOOM_STEP: f32 = 0.1;
|
||||||
|
const RESET_ZOOM: f32 = 1.0;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Display)]
|
#[derive(Clone, Copy, PartialEq, Eq, Display)]
|
||||||
pub enum ShowSourceClientOption {
|
pub enum ShowSourceClientOption {
|
||||||
Hide,
|
Hide,
|
||||||
@@ -62,6 +70,26 @@ impl ShowSourceClientOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn label<'a>(&self, i18n: &'a mut Localization) -> String {
|
||||||
|
match self {
|
||||||
|
ShowSourceClientOption::Hide => tr!(
|
||||||
|
i18n,
|
||||||
|
"Hide",
|
||||||
|
"Option in settings section to hide the source client label in note display"
|
||||||
|
),
|
||||||
|
ShowSourceClientOption::Top => tr!(
|
||||||
|
i18n,
|
||||||
|
"Top",
|
||||||
|
"Option in settings section to show the source client label at the top of the note"
|
||||||
|
),
|
||||||
|
ShowSourceClientOption::Bottom => tr!(
|
||||||
|
i18n,
|
||||||
|
"Bottom",
|
||||||
|
"Option in settings section to show the source client label at the bottom of the note"
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SettingsAction {
|
pub enum SettingsAction {
|
||||||
@@ -86,34 +114,32 @@ impl SettingsAction {
|
|||||||
let mut route_action: Option<RouterAction> = None;
|
let mut route_action: Option<RouterAction> = None;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
SettingsAction::OpenRelays => {
|
Self::OpenRelays => {
|
||||||
route_action = Some(RouterAction::route_to(Route::Relays));
|
route_action = Some(RouterAction::route_to(Route::Relays));
|
||||||
}
|
}
|
||||||
SettingsAction::SetZoomFactor(zoom_factor) => {
|
Self::SetZoomFactor(zoom_factor) => {
|
||||||
ctx.set_zoom_factor(zoom_factor);
|
ctx.set_zoom_factor(zoom_factor);
|
||||||
settings_handler.set_zoom_factor(zoom_factor);
|
settings_handler.set_zoom_factor(zoom_factor);
|
||||||
}
|
}
|
||||||
SettingsAction::SetShowSourceClient(option) => {
|
Self::SetShowSourceClient(option) => {
|
||||||
option.set_note_options(&mut app.note_options);
|
option.set_note_options(&mut app.note_options);
|
||||||
|
|
||||||
settings_handler.set_show_source_client(option);
|
settings_handler.set_show_source_client(option);
|
||||||
}
|
}
|
||||||
SettingsAction::SetTheme(theme) => {
|
Self::SetTheme(theme) => {
|
||||||
ctx.options_mut(|o| {
|
ctx.set_theme(theme);
|
||||||
o.theme_preference = theme;
|
|
||||||
});
|
|
||||||
settings_handler.set_theme(theme);
|
settings_handler.set_theme(theme);
|
||||||
}
|
}
|
||||||
SettingsAction::SetLocale(language) => {
|
Self::SetLocale(language) => {
|
||||||
if i18n.set_locale(language.clone()).is_ok() {
|
if i18n.set_locale(language.clone()).is_ok() {
|
||||||
settings_handler.set_locale(language.to_string());
|
settings_handler.set_locale(language.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SettingsAction::OpenCacheFolder => {
|
Self::OpenCacheFolder => {
|
||||||
use opener;
|
use opener;
|
||||||
let _ = opener::open(img_cache.base_path.clone());
|
let _ = opener::open(img_cache.base_path.clone());
|
||||||
}
|
}
|
||||||
SettingsAction::ClearCacheFolder => {
|
Self::ClearCacheFolder => {
|
||||||
let _ = img_cache.clear_folder_contents();
|
let _ = img_cache.clear_folder_contents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,27 +208,6 @@ impl<'a> SettingsView<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the localized label for ShowNoteClientOption
|
|
||||||
fn get_show_note_client_label(&mut self, option: ShowSourceClientOption) -> String {
|
|
||||||
match option {
|
|
||||||
ShowSourceClientOption::Hide => tr!(
|
|
||||||
self.i18n,
|
|
||||||
"Hide",
|
|
||||||
"Option in settings section to hide the source client label in note display"
|
|
||||||
),
|
|
||||||
ShowSourceClientOption::Top => tr!(
|
|
||||||
self.i18n,
|
|
||||||
"Top",
|
|
||||||
"Option in settings section to show the source client label at the top of the note"
|
|
||||||
),
|
|
||||||
ShowSourceClientOption::Bottom => tr!(
|
|
||||||
self.i18n,
|
|
||||||
"Bottom",
|
|
||||||
"Option in settings section to show the source client label at the bottom of the note"
|
|
||||||
),
|
|
||||||
}.to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn appearance_section(&mut self, ui: &mut egui::Ui) -> Option<SettingsAction> {
|
pub fn appearance_section(&mut self, ui: &mut egui::Ui) -> Option<SettingsAction> {
|
||||||
let mut action = None;
|
let mut action = None;
|
||||||
let title = tr!(
|
let title = tr!(
|
||||||
@@ -220,11 +225,19 @@ impl<'a> SettingsView<'a> {
|
|||||||
"Label for zoom level, Appearance settings section",
|
"Label for zoom level, Appearance settings section",
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let min_reached = current_zoom <= MIN_ZOOM;
|
||||||
|
let max_reached = current_zoom >= MAX_ZOOM;
|
||||||
|
|
||||||
if ui
|
if ui
|
||||||
.button(RichText::new("-").text_style(NotedeckTextStyle::Small.text_style()))
|
.add_enabled(
|
||||||
|
!min_reached,
|
||||||
|
Button::new(
|
||||||
|
RichText::new("-").text_style(NotedeckTextStyle::Small.text_style()),
|
||||||
|
),
|
||||||
|
)
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
let new_zoom = (current_zoom - 0.1).max(0.1);
|
let new_zoom = (current_zoom - ZOOM_STEP).max(MIN_ZOOM);
|
||||||
action = Some(SettingsAction::SetZoomFactor(new_zoom));
|
action = Some(SettingsAction::SetZoomFactor(new_zoom));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -234,10 +247,15 @@ impl<'a> SettingsView<'a> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ui
|
if ui
|
||||||
.button(RichText::new("+").text_style(NotedeckTextStyle::Small.text_style()))
|
.add_enabled(
|
||||||
|
!max_reached,
|
||||||
|
Button::new(
|
||||||
|
RichText::new("+").text_style(NotedeckTextStyle::Small.text_style()),
|
||||||
|
),
|
||||||
|
)
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
let new_zoom = (current_zoom + 0.1).min(10.0);
|
let new_zoom = (current_zoom + ZOOM_STEP).min(MAX_ZOOM);
|
||||||
action = Some(SettingsAction::SetZoomFactor(new_zoom));
|
action = Some(SettingsAction::SetZoomFactor(new_zoom));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -249,7 +267,7 @@ impl<'a> SettingsView<'a> {
|
|||||||
))
|
))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
action = Some(SettingsAction::SetZoomFactor(1.0));
|
action = Some(SettingsAction::SetZoomFactor(RESET_ZOOM));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -288,10 +306,10 @@ impl<'a> SettingsView<'a> {
|
|||||||
if ui
|
if ui
|
||||||
.selectable_value(
|
.selectable_value(
|
||||||
self.theme,
|
self.theme,
|
||||||
"Light".into(),
|
THEME_LIGHT.into(),
|
||||||
small_richtext(
|
small_richtext(
|
||||||
self.i18n,
|
self.i18n,
|
||||||
"Light",
|
THEME_LIGHT.into(),
|
||||||
"Label for Theme Light, Appearance settings section",
|
"Label for Theme Light, Appearance settings section",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -302,10 +320,10 @@ impl<'a> SettingsView<'a> {
|
|||||||
if ui
|
if ui
|
||||||
.selectable_value(
|
.selectable_value(
|
||||||
self.theme,
|
self.theme,
|
||||||
"Dark".into(),
|
THEME_DARK.into(),
|
||||||
small_richtext(
|
small_richtext(
|
||||||
self.i18n,
|
self.i18n,
|
||||||
"Dark",
|
THEME_DARK.into(),
|
||||||
"Label for Theme Dark, Appearance settings section",
|
"Label for Theme Dark, Appearance settings section",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -428,13 +446,12 @@ impl<'a> SettingsView<'a> {
|
|||||||
ShowSourceClientOption::Top,
|
ShowSourceClientOption::Top,
|
||||||
ShowSourceClientOption::Bottom,
|
ShowSourceClientOption::Bottom,
|
||||||
] {
|
] {
|
||||||
let label = self.get_show_note_client_label(option);
|
|
||||||
|
|
||||||
if ui
|
if ui
|
||||||
.selectable_value(
|
.selectable_value(
|
||||||
self.show_note_client,
|
self.show_note_client,
|
||||||
option,
|
option,
|
||||||
RichText::new(label).text_style(NotedeckTextStyle::Small.text_style()),
|
RichText::new(option.label(self.i18n))
|
||||||
|
.text_style(NotedeckTextStyle::Small.text_style()),
|
||||||
)
|
)
|
||||||
.changed()
|
.changed()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user