Browse Source

Avalonia updates

Ruben 1 year ago
parent
commit
dac93d021b

+ 3 - 2
src/PicView.Avalonia.MacOS/Views/MacMainWindow.axaml

@@ -17,10 +17,11 @@
     xmlns:views="clr-namespace:PicView.Avalonia.Views;assembly=PicView.Avalonia"
     xmlns:views1="clr-namespace:PicView.Avalonia.MacOS.Views"
     xmlns:vm="using:PicView.Avalonia.ViewModels"
-    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:uc="clr-namespace:PicView.Avalonia.Views.UC;assembly=PicView.Avalonia">
     <DockPanel LastChildFill="True">
         <views1:MacOSTitlebar DockPanel.Dock="Top" />
-        <views:BottomBar DockPanel.Dock="Bottom" />
+        <uc:BottomBar DockPanel.Dock="Bottom" />
         <views:MainView />
     </DockPanel>
 </Window>

+ 5 - 1
src/PicView.Avalonia.Theme/Controls/Button.axaml

@@ -22,6 +22,7 @@
                     TextElement.Foreground="{TemplateBinding Foreground}" />
             </ControlTemplate>
         </Setter>
+
         <Style Selector="^.hover:pointerover /template/ ContentPresenter#PART_ContentPresenter">
             <Style.Animations>
                 <Animation IterationCount="1" Duration=".35">
@@ -73,7 +74,10 @@
             </Style.Animations>
             <Setter Property="Background" Value="{StaticResource AltBackgroundHoverColor}" />
         </Style>
-        <Style Selector="^:pressed  /template/ ContentPresenter#PART_ContentPresenter">
+        <Style Selector="^.hover:pressed  /template/ ContentPresenter#PART_ContentPresenter">
+            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
+        </Style>
+        <Style Selector="^.alphaHover:pressed  /template/ ContentPresenter#PART_ContentPresenter">
             <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
         </Style>
         <Style Selector="^:disabled">

+ 1 - 0
src/PicView.Avalonia.Theme/Dark/DarkTheme.axaml

@@ -61,4 +61,5 @@
             <Setter Property="Background" Value="{DynamicResource AccentColor}" />
         </Style>
     </Style>
+
 </Styles>

+ 0 - 23
src/PicView.Avalonia.Theme/IBitmapToImageConverter.cs

@@ -1,23 +0,0 @@
-using System;
-using System.Globalization;
-using Avalonia.Controls;
-using Avalonia.Data.Converters;
-using Avalonia.Media.Imaging;
-
-namespace PicView.Avalonia.Theme;
-
-internal class BitmapToImageConverter : IValueConverter
-{
-    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
-    {
-        if (value is Bitmap bm)
-            return new Image { Source = bm };
-
-        return null;
-    }
-
-    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
-    {
-        throw new NotImplementedException();
-    }
-}

+ 2 - 1
src/PicView.Avalonia.Win32/App.axaml

@@ -2,10 +2,11 @@
     x:Class="PicView.Avalonia.Win32.App"
     xmlns="https://github.com/avaloniaui"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:theme="clr-namespace:PicView.Avalonia.Theme;assembly=PicView.Avalonia.Theme"
     RequestedThemeVariant="Default">
 
     <Application.Styles>
         <SimpleTheme />
-        <StyleInclude Source="avares://PicView.Avalonia.Theme/Dark/DarkTheme.axaml" />
+        <theme:DarkTheme />
     </Application.Styles>
 </Application>

+ 3 - 3
src/PicView.Avalonia.Win32/App.axaml.cs

@@ -3,9 +3,9 @@ using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Markup.Xaml;
 using PicView.Avalonia.ViewModels;
 using System.Threading.Tasks;
+using PicView.Avalonia.Win32.Views;
 using PicView.Core.Config;
 using PicView.Core.Localization;
-using MainWindow = PicView.Avalonia.Win32.Views.MainWindow;
 
 namespace PicView.Avalonia.Win32;
 
@@ -21,11 +21,11 @@ public partial class App : Application
         Task.Run(async () =>
         {
             await SettingsHelper.LoadSettingsAsync();
-            TranslationHelper.LoadLanguage(SettingsHelper.Settings.UIProperties.UserLanguage);
+            await TranslationHelper.LoadLanguage(SettingsHelper.Settings.UIProperties.UserLanguage);
         });
         if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
         {
-            var w = desktop.MainWindow = new MainWindow();
+            var w = desktop.MainWindow = new WinMainWindow();
             w.DataContext = new MainViewModel();
         }
 

+ 2 - 2
src/PicView.Avalonia.Win32/PicView.Avalonia.Win32.csproj

@@ -30,8 +30,8 @@
     <Compile Update="App.axaml.cs">
       <DependentUpon>%(Filename)</DependentUpon>
     </Compile>
-    <Compile Update="Views\MainWindow.axaml.cs">
-      <DependentUpon>%(Filename)</DependentUpon>
+    <Compile Update="Views\WinMainWindow.axaml.cs">
+      <DependentUpon>WinMainWindow.axaml</DependentUpon>
     </Compile>
     <Compile Update="Views\WinTitleBar.axaml.cs">
       <DependentUpon>WinTitleBar.axaml</DependentUpon>

+ 3 - 2
src/PicView.Avalonia.Win32/Views/MainWindow.axaml → src/PicView.Avalonia.Win32/Views/WinMainWindow.axaml

@@ -1,5 +1,5 @@
 <Window
-    x:Class="PicView.Avalonia.Win32.Views.MainWindow"
+    x:Class="PicView.Avalonia.Win32.Views.WinMainWindow"
     xmlns="https://github.com/avaloniaui"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -7,6 +7,7 @@
     xmlns:views="clr-namespace:PicView.Avalonia.Views;assembly=PicView.Avalonia"
     xmlns:views1="clr-namespace:PicView.Avalonia.Win32.Views"
     xmlns:win32="clr-namespace:PicView.Avalonia.Win32"
+    xmlns:uc="clr-namespace:PicView.Avalonia.Views.UC;assembly=PicView.Avalonia"
     Title="PicView.Avalonia"
     MinWidth="435"
     MinHeight="400"
@@ -19,7 +20,7 @@
     <Border BorderBrush="{StaticResource MainBorderColor}" BorderThickness="1,0,1,1">
         <DockPanel Background="{StaticResource NoisyTexture}" LastChildFill="True">
             <views1:WinTitleBar x:Name="TitleBar" DockPanel.Dock="Top" />
-            <views:BottomBar DockPanel.Dock="Bottom" />
+            <uc:BottomBar DockPanel.Dock="Bottom" />
             <views:MainView />
         </DockPanel>
     </Border>

+ 4 - 4
src/PicView.Avalonia.Win32/Views/MainWindow.axaml.cs → src/PicView.Avalonia.Win32/Views/WinMainWindow.axaml.cs

@@ -4,19 +4,19 @@ using System;
 
 namespace PicView.Avalonia.Win32.Views;
 
-public partial class MainWindow : Window
+public partial class WinMainWindow : Window
 {
-    public MainWindow()
+    public WinMainWindow()
     {
         InitializeComponent();
     }
 
-    protected override void OnClosing(WindowClosingEventArgs e)
+    protected override async void OnClosing(WindowClosingEventArgs e)
     {
         e.Cancel = true;
         Hide();
 
-        SettingsHelper.SaveSettingsAsync().ConfigureAwait(false);
+        await SettingsHelper.SaveSettingsAsync().ConfigureAwait(false);
         Environment.Exit(0);
     }
 }

+ 32 - 1
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -11,10 +11,41 @@ namespace PicView.Avalonia.ViewModels;
 
 public class MainViewModel : ViewModelBase
 {
+    #region Localization
+
+    private string? _currentLanguageKey;
+
+    public string CurrentLanguageValue
+    {
+        get => SettingsHelper.Settings.UIProperties.UserLanguage;
+    }
+
+    public string? CurrentLanguageKey
+    {
+        get => _currentLanguageKey ?? "en";
+        set
+        {
+            if (_currentLanguageKey == value)
+            {
+                return;
+            }
+
+            _currentLanguageKey = value;
+            this.RaisePropertyChanged(nameof(CurrentLanguageValue));
+            this.RaisePropertyChanged(nameof(CurrentLanguageValue));
+            this.RaisePropertyChanged(nameof(SelectFile));
+            this.RaisePropertyChanged(nameof(OpenLastFile));
+            this.RaisePropertyChanged(nameof(Paste));
+        }
+    }
+
     public string SelectFile => TranslationHelper.GetTranslation("OpenFileDialog");
 
     public string OpenLastFile => TranslationHelper.GetTranslation("OpenLastFile");
-    public string Paste => TranslationHelper.GetTranslation("Paste");
+    public string Paste => TranslationHelper.GetTranslation("FilePaste");
+
+    #endregion Localization
+
     public ICommand? ExitCommand { get; }
     public ICommand? MinimizeCommand { get; }
     public ICommand? MaximizeCommand { get; }

+ 1 - 5
src/PicView.Avalonia/Views/MainView.axaml.cs

@@ -1,8 +1,4 @@
 using Avalonia.Controls;
-using PicView.Core.Config;
-using PicView.Core.Localization;
-using ReactiveUI;
-using System.Reactive.Concurrency;
 
 namespace PicView.Avalonia.Views;
 
@@ -12,4 +8,4 @@ public partial class MainView : UserControl
     {
         InitializeComponent();
     }
-}
+}

+ 1 - 1
src/PicView.Avalonia/Views/UC/BottomBar.axaml

@@ -1,5 +1,5 @@
 <UserControl
-    x:Class="PicView.Avalonia.Views.BottomBar"
+    x:Class="PicView.Avalonia.Views.UC.BottomBar"
     xmlns="https://github.com/avaloniaui"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

+ 1 - 1
src/PicView.Avalonia/Views/UC/BottomBar.axaml.cs

@@ -4,7 +4,7 @@ using Avalonia.Input;
 using Avalonia.Media;
 using Avalonia.Styling;
 
-namespace PicView.Avalonia.Views;
+namespace PicView.Avalonia.Views.UC;
 
 public partial class BottomBar : UserControl
 {

+ 6 - 4
src/PicView.Avalonia/Views/UC/StartUpMenu.axaml

@@ -61,7 +61,8 @@
             HorizontalAlignment="Center"
             VerticalAlignment="Center"
             Orientation="Horizontal">
-            <Button x:Name="SelectFile">
+
+            <Button x:Name="SelectFileButton">
                 <StackPanel Orientation="Horizontal">
                     <Image Height="20.091">
                         <Image.Source>
@@ -98,6 +99,7 @@
                         Foreground="{StaticResource MainTextColor}" />
                 </StackPanel>
             </Button>
+
             <Button x:Name="OpenLastFileButton">
                 <StackPanel Height="30" Orientation="Horizontal">
                     <Image Height="20.091">
@@ -138,14 +140,14 @@
             <Button x:Name="PasteButton">
                 <StackPanel Height="30" Orientation="Horizontal">
                     <Path
-                        Width="16"
-                        Height="16"
+                        Width="20"
+                        Height="20"
                         Data="M768 1664h896v-640h-416q-40 0-68-28t-28-68v-416h-384v1152zm256-1440v-64q0-13-9.5-22.5t-22.5-9.5h-704q-13 0-22.5 9.5t-9.5 22.5v64q0 13 9.5 22.5t22.5 9.5h704q13 0 22.5-9.5t9.5-22.5zm256 672h299l-299-299v299zm512 128v672q0 40-28 68t-68 28h-960q-40 0-68-28t-28-68v-160h-544q-40 0-68-28t-28-68v-1344q0-40 28-68t68-28h1088q40 0 68 28t28 68v328q21 13 36 28l408 408q28 28 48 76t20 88z"
                         Fill="{StaticResource MainIconColor}"
                         Stretch="Fill" />
                     <Label
                         x:Name="FilePasteLabel"
-                        Padding="8,8,15,0"
+                        Padding="8,8,15,5"
                         Content="{Binding Paste}"
                         Foreground="{StaticResource MainTextColor}" />
                 </StackPanel>

+ 1 - 4
src/PicView.Core/Localization/TranslationHelper.cs

@@ -11,10 +11,7 @@ public static class TranslationHelper
 {
     public static string GetTranslation(string key)
     {
-        if (Language is null)
-            return string.Empty;
-
-        return Language.TryGetValue(key, out var translation) ? translation : key;
+        return Language is null ? string.Empty : Language.GetValueOrDefault(key, key);
     }
 
     /// <summary>