Browse Source

Add menus, use local path for files

Ruben 1 year ago
parent
commit
32b18be527

+ 38 - 19
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -1,5 +1,4 @@
-using System.Diagnostics.CodeAnalysis;
-using Avalonia;
+using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Media;
@@ -12,12 +11,15 @@ using PicView.Core.ImageDecoding;
 using PicView.Core.Localization;
 using PicView.Core.Navigation;
 using ReactiveUI;
+using System.Reactive.Disposables;
 using System.Windows.Input;
 
 namespace PicView.Avalonia.ViewModels;
 
-public class MainViewModel : ViewModelBase
+public class MainViewModel : ViewModelBase, IActivatableViewModel
 {
+    public ViewModelActivator? Activator { get; }
+
     #region Localization
 
     private void UpdateLanguage()
@@ -416,24 +418,31 @@ public class MainViewModel : ViewModelBase
 
     private async Task SetImageModelAsync(FileInfo fileInfo)
     {
-        ArgumentNullException.ThrowIfNull(fileInfo);
-        if (!fileInfo.Exists)
+        try
         {
-            throw new FileNotFoundException();
-        }
+            ArgumentNullException.ThrowIfNull(fileInfo);
 
-        var imageModel = new ImageModel
+            CloseMenuCommand?.Execute(null);
+            var imageModel = new ImageModel
+            {
+                FileInfo = fileInfo
+            };
+            ImageService = new ImageService();
+            await ImageModel.LoadImageAsync(imageModel).ConfigureAwait(false);
+            SetImageModel(imageModel);
+            ImageIterator = new ImageIterator(imageModel.FileInfo);
+            ImageIterator.Index = ImageIterator.Pics.IndexOf(fileInfo.FullName);
+            SetTitle(imageModel, ImageIterator);
+            await ImageIterator.AddAsync(ImageIterator.Index, imageModel);
+            await ImageIterator.Preload();
+        }
+        catch (Exception)
         {
-            FileInfo = fileInfo
-        };
-        ImageService = new ImageService();
-        await ImageModel.LoadImageAsync(imageModel).ConfigureAwait(false);
-        SetImageModel(imageModel);
-        ImageIterator = new ImageIterator(imageModel.FileInfo);
-        ImageIterator.Index = ImageIterator.Pics.IndexOf(fileInfo.FullName);
-        SetTitle(imageModel, ImageIterator);
-        await ImageIterator.AddAsync(ImageIterator.Index, imageModel);
-        await ImageIterator.Preload();
+            if (ImageIterator is null)
+            {
+                CurrentView = new StartUpMenu();
+            }
+        }
     }
 
     #endregion Methods
@@ -557,7 +566,8 @@ public class MainViewModel : ViewModelBase
                 return;
             }
             CurrentView = new ImageViewer();
-            await SetImageModelAsync(new FileInfo(file.Path.AbsolutePath));
+
+            await SetImageModelAsync(new FileInfo(file.Path.LocalPath));
         });
 
         ShowInFolderCommand = ReactiveCommand.Create(() =>
@@ -583,5 +593,14 @@ public class MainViewModel : ViewModelBase
         DuplicateFileCommand = ReactiveCommand.Create(() =>
         {
         });
+
+        Activator = new ViewModelActivator();
+        this.WhenActivated((disposables) =>
+        {
+            /* handle activation */
+            Disposable
+                .Create(() => { /* handle deactivation */ })
+                .DisposeWith(disposables);
+        });
     }
 }

+ 42 - 7
src/PicView.Avalonia/Views/MainView.axaml.cs

@@ -1,6 +1,8 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Layout;
+using ReactiveUI;
+using System.Reactive.Concurrency;
 
 namespace PicView.Avalonia.Views;
 
@@ -12,15 +14,48 @@ public partial class MainView : UserControl
 
         Loaded += delegate
         {
-            var fileMenu = new UC.Menus.FileMenu
+            RxApp.MainThreadScheduler.Schedule(() =>
             {
-                VerticalAlignment = VerticalAlignment.Bottom,
-                HorizontalAlignment = HorizontalAlignment.Center,
-                Margin = new Thickness(0, 0, 168, 0),
-                Opacity = 1
-            };
+                var fileMenu = new UC.Menus.FileMenu()
+                {
+                    VerticalAlignment = VerticalAlignment.Bottom,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    Margin = new Thickness(0, 0, 168, 0),
+                    Opacity = 1
+                };
 
-            MainGrid.Children.Add(fileMenu);
+                MainGrid.Children.Add(fileMenu);
+
+                var imageMenu = new UC.Menus.ImageMenu
+                {
+                    VerticalAlignment = VerticalAlignment.Bottom,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    Margin = new Thickness(0, 0, 65, 0),
+                    Opacity = 1
+                };
+
+                MainGrid.Children.Add(imageMenu);
+
+                var settingsMenu = new UC.Menus.SettingsMenu
+                {
+                    VerticalAlignment = VerticalAlignment.Bottom,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    Margin = new Thickness(220, 0, 0, 0),
+                    Opacity = 1
+                };
+
+                MainGrid.Children.Add(settingsMenu);
+
+                var toolsMenu = new UC.Menus.ToolsMenu()
+                {
+                    VerticalAlignment = VerticalAlignment.Bottom,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    Margin = new Thickness(240, 0, 0, 0),
+                    Opacity = 1
+                };
+
+                MainGrid.Children.Add(toolsMenu);
+            });
         };
     }
 }

File diff suppressed because it is too large
+ 287 - 0
src/PicView.Avalonia/Views/UC/Menus/ImageMenu.axaml


+ 11 - 0
src/PicView.Avalonia/Views/UC/Menus/ImageMenu.axaml.cs

@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace PicView.Avalonia.Views.UC.Menus;
+
+public partial class ImageMenu : UserControl
+{
+    public ImageMenu()
+    {
+        InitializeComponent();
+    }
+}

File diff suppressed because it is too large
+ 287 - 0
src/PicView.Avalonia/Views/UC/Menus/SettingsMenu.axaml


+ 11 - 0
src/PicView.Avalonia/Views/UC/Menus/SettingsMenu.axaml.cs

@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace PicView.Avalonia.Views.UC.Menus;
+
+public partial class SettingsMenu : UserControl
+{
+    public SettingsMenu()
+    {
+        InitializeComponent();
+    }
+}

File diff suppressed because it is too large
+ 287 - 0
src/PicView.Avalonia/Views/UC/Menus/ToolsMenu.axaml


+ 11 - 0
src/PicView.Avalonia/Views/UC/Menus/ToolsMenu.axaml.cs

@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace PicView.Avalonia.Views.UC.Menus;
+
+public partial class ToolsMenu : UserControl
+{
+    public ToolsMenu()
+    {
+        InitializeComponent();
+    }
+}

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

@@ -62,7 +62,7 @@
             VerticalAlignment="Center"
             Orientation="Horizontal">
 
-            <Button x:Name="SelectFileButton">
+            <Button x:Name="SelectFileButton" Command="{Binding OpenFileCommand}">
                 <StackPanel Orientation="Horizontal">
                     <Image Height="20.091">
                         <Image.Source>
@@ -100,7 +100,7 @@
                 </StackPanel>
             </Button>
 
-            <Button x:Name="OpenLastFileButton">
+            <Button x:Name="OpenLastFileButton" Command="{Binding OpenLastFileCommand}">
                 <StackPanel Height="30" Orientation="Horizontal">
                     <Image Height="20.091">
                         <Image.Source>
@@ -137,7 +137,8 @@
                         Foreground="{StaticResource MainTextColor}" />
                 </StackPanel>
             </Button>
-            <Button x:Name="PasteButton">
+
+            <Button x:Name="PasteButton" Command="{Binding PasteCommand}">
                 <StackPanel Height="30" Orientation="Horizontal">
                     <Path
                         Width="20"

Some files were not shown because too many files changed in this diff