Skip to content

Commit

Permalink
Avalonia updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Mar 28, 2024
1 parent 9199011 commit 94dd254
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/PicView.Avalonia/Views/AppearanceView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
BorderBrush="{StaticResource MainBorderColor}"
BorderThickness="1"
FontFamily="/Assets/Fonts/Roboto-Medium.ttf#Roboto"
SelectedIndex="0">
<ComboBoxItem Content="test" />
<ComboBoxItem Content="95%" />
</ComboBox>
SelectedIndex="0" />

<TextBlock
Margin="0,10,0,10"
Expand Down
79 changes: 79 additions & 0 deletions src/PicView.Avalonia/Views/AppearanceView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using PicView.Avalonia.ViewModels;
using PicView.Core.Config;
using PicView.Core.Localization;

namespace PicView.Avalonia.Views;

Expand All @@ -12,5 +19,77 @@ public AppearanceView()
{
TaskBarToggleButton.IsVisible = false;
}
Loaded += AppearanceView_Loaded;
}

private void AppearanceView_Loaded(object? sender, RoutedEventArgs e)
{
try
{
var languages = TranslationHelper.GetLanguages();
foreach (var language in languages)
{
var lang = Path.GetFileNameWithoutExtension(language);
var isSelected = lang.Length switch
{
>= 4 => lang[^2..] == SettingsHelper.Settings.UIProperties.UserLanguage[^2..],
2 => lang[..2] == SettingsHelper.Settings.UIProperties.UserLanguage[..2],
_ => lang == SettingsHelper.Settings.UIProperties.UserLanguage
};

var comboBoxItem = new ComboBoxItem
{
Content = new CultureInfo(lang).DisplayName,
IsSelected = isSelected,
Tag = lang
};

LanguageBox.Items.Add(comboBoxItem);
if (isSelected)
{
LanguageBox.SelectedItem = comboBoxItem;
}
}
LanguageBox.SelectionChanged += async delegate
{
if (LanguageBox.SelectedItem is not ComboBoxItem comboBoxItem)
{
return;
}
var language = Path.GetFileNameWithoutExtension(comboBoxItem.Tag as string ?? string.Empty);
if (string.IsNullOrEmpty(language))
{
return;
}
SettingsHelper.Settings.UIProperties.UserLanguage = language;

await TranslationHelper.LoadLanguage(language).ConfigureAwait(false);
await Dispatcher.UIThread.InvokeAsync(() =>
{
if (DataContext is not MainViewModel vm)
{
return;
}
vm.UpdateLanguage();

var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is not Window window)
{
return;
}
window.Close();

vm.ShowSettingsWindowCommand.Execute(null);
});

await SettingsHelper.SaveSettingsAsync();
};
}
catch (Exception exception)
{
#if DEBUG
Trace.WriteLine($"{nameof(AppearanceView)} Add language caught exception: \n {exception}");
#endif
}
}
}
8 changes: 4 additions & 4 deletions src/PicView.Avalonia/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MainView()
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 0, 168, 0),
Opacity = 1
IsVisible = false
};

MainGrid.Children.Add(fileMenu);
Expand All @@ -31,7 +31,7 @@ public MainView()
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 0, 64.5, 0),
Opacity = 1
IsVisible = false
};

MainGrid.Children.Add(imageMenu);
Expand All @@ -41,7 +41,7 @@ public MainView()
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(127, 0, 0, 0),
Opacity = 1
IsVisible = false
};

MainGrid.Children.Add(settingsMenu);
Expand All @@ -51,7 +51,7 @@ public MainView()
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(120, 0, 0, 0),
Opacity = 1
IsVisible = false
};

MainGrid.Children.Add(toolsMenu);
Expand Down

0 comments on commit 94dd254

Please sign in to comment.