Browse Source

Removed import file popup

CPKreuz 2 years ago
parent
commit
47bef99138

+ 1 - 0
src/PixiEditor.DrawingApi.Core/Numerics/VecI.cs

@@ -16,6 +16,7 @@ public struct VecI : IEquatable<VecI>
 
 
     public static VecI Zero { get; } = new(0, 0);
     public static VecI Zero { get; } = new(0, 0);
     public static VecI One { get; } = new(1, 1);
     public static VecI One { get; } = new(1, 1);
+    public static VecI NegativeOne { get; } = new(-1, -1);
 
 
     public VecI(int x, int y)
     public VecI(int x, int y)
     {
     {

+ 4 - 0
src/PixiEditor/Helpers/DocumentViewModelBuilder.cs

@@ -27,6 +27,8 @@ internal class DocumentViewModelBuilder : ChildrenBuilder
 
 
         return this;
         return this;
     }
     }
+
+    public DocumentViewModelBuilder WithSize(VecI size) => WithSize(size.X, size.Y);
     
     
     public DocumentViewModelBuilder WithSwatches(IEnumerable<Color> swatches)
     public DocumentViewModelBuilder WithSwatches(IEnumerable<Color> swatches)
     {
     {
@@ -207,6 +209,8 @@ internal class DocumentViewModelBuilder : ChildrenBuilder
             Height = height;
             Height = height;
             return this;
             return this;
         }
         }
+
+        public LayerBuilder WithSize(VecI size) => WithSize(size.X, size.Y);
         
         
         public LayerBuilder WithRect(int width, int height, int offsetX, int offsetY)
         public LayerBuilder WithRect(int width, int height, int offsetX, int offsetY)
         {
         {

+ 0 - 72
src/PixiEditor/Models/Dialogs/ImportFileDialog.cs

@@ -1,72 +0,0 @@
-using PixiEditor.Views;
-using PixiEditor.Views.Dialogs;
-
-namespace PixiEditor.Models.Dialogs;
-
-internal class ImportFileDialog : CustomDialog
-{
-    private int fileHeight;
-
-    private string filePath;
-    private int fileWidth;
-
-    public int FileWidth
-    {
-        get => fileWidth;
-        set
-        {
-            if (fileWidth != value)
-            {
-                fileWidth = value;
-                RaisePropertyChanged("Width");
-            }
-        }
-    }
-
-    public int FileHeight
-    {
-        get => fileHeight;
-        set
-        {
-            if (fileHeight != value)
-            {
-                fileHeight = value;
-                RaisePropertyChanged("FileHeight");
-            }
-        }
-    }
-
-    public string FilePath
-    {
-        get => filePath;
-        set
-        {
-            if (filePath != value)
-            {
-                filePath = value;
-                RaisePropertyChanged("FilePath");
-            }
-        }
-    }
-
-    public override bool ShowDialog()
-    {
-        ImportFilePopup popup = new ImportFilePopup
-        {
-            FilePath = FilePath
-        };
-
-        if (FileWidth != 0) popup.ImportWidth = FileWidth;
-        if (FileHeight != 0) popup.ImportHeight = FileHeight;
-        
-        popup.ShowDialog();
-        if (popup.DialogResult == true)
-        {
-            FileHeight = popup.ImportHeight;
-            FileWidth = popup.ImportWidth;
-            FilePath = popup.FilePath;
-        }
-
-        return (bool)popup.DialogResult;
-    }
-}

+ 6 - 5
src/PixiEditor/Models/IO/Importer.cs

@@ -30,13 +30,14 @@ internal class Importer : NotifyableObject
     public static Surface ImportImage(string path, VecI size)
     public static Surface ImportImage(string path, VecI size)
     {
     {
         Surface original = Surface.Load(path);
         Surface original = Surface.Load(path);
-        if (original.Size != size)
+        if (original.Size == size || size == VecI.NegativeOne)
         {
         {
-            Surface resized = original.ResizeNearestNeighbor(size);
-            original.Dispose();
-            return resized;
+            return original;
         }
         }
-        return original;
+
+        Surface resized = original.ResizeNearestNeighbor(size);
+        original.Dispose();
+        return resized;
     }
     }
 
 
     public static WriteableBitmap ImportWriteableBitmap(string path)
     public static WriteableBitmap ImportWriteableBitmap(string path)

+ 7 - 29
src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -227,24 +227,14 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
     /// </summary>
     /// </summary>
     private void OpenRegularImage(string path, bool associatePath)
     private void OpenRegularImage(string path, bool associatePath)
     {
     {
-        ImportFileDialog dialog = new ImportFileDialog();
+        var image = Importer.ImportImage(path, VecI.NegativeOne);
 
 
-        if (path != null && File.Exists(path))
-        {
-            dialog.FilePath = path;
-        }
-
-        if (!dialog.ShowDialog())
-        {
-            return;
-        }
-
-        DocumentViewModel doc = NewDocument(b => b
-            .WithSize(dialog.FileWidth, dialog.FileHeight)
+        var doc = NewDocument(b => b
+            .WithSize(image.Size)
             .WithLayer(l => l
             .WithLayer(l => l
                 .WithName("Image")
                 .WithName("Image")
-                .WithSize(dialog.FileWidth, dialog.FileHeight)
-                .WithSurface(Importer.ImportImage(dialog.FilePath, new VecI(dialog.FileWidth, dialog.FileHeight)))));
+                .WithSize(image.Size)
+                .WithSurface(image)));
 
 
         if (associatePath)
         if (associatePath)
         {
         {
@@ -259,23 +249,11 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
     /// </summary>
     /// </summary>
     private void OpenRegularImage(Surface surface, string path)
     private void OpenRegularImage(Surface surface, string path)
     {
     {
-        ImportFileDialog dialog = new ImportFileDialog( );
-
-        dialog.FileWidth = surface.Size.X;
-        dialog.FileHeight = surface.Size.Y;
-        
-        if (!dialog.ShowDialog())
-        {
-            return;
-        }
-
-        surface.ResizeNearestNeighbor(new VecI(dialog.FileWidth, dialog.FileHeight));
-            
         DocumentViewModel doc = NewDocument(b => b
         DocumentViewModel doc = NewDocument(b => b
-            .WithSize(dialog.FileWidth, dialog.FileHeight)
+            .WithSize(surface.Size)
             .WithLayer(l => l
             .WithLayer(l => l
                 .WithName("Image")
                 .WithName("Image")
-                .WithSize(dialog.FileWidth, dialog.FileHeight)
+                .WithSize(surface.Size)
                 .WithSurface(surface)));
                 .WithSurface(surface)));
 
 
         if (path == null)
         if (path == null)

+ 0 - 51
src/PixiEditor/Views/Dialogs/ImportFilePopup.xaml

@@ -1,51 +0,0 @@
-<Window x:Class="PixiEditor.Views.Dialogs.ImportFilePopup"
-        x:ClassModifier="internal"
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        xmlns:local="clr-namespace:PixiEditor.Views"
-        xmlns:dial="clr-namespace:PixiEditor.Views.Dialogs"
-        xmlns:vm="clr-namespace:PixiEditor.ViewModels"
-        xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours" 
-        xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
-        xmlns:userControls="clr-namespace:PixiEditor.Views.UserControls"
-        xmlns:helpers="clr-namespace:PixiEditor.Helpers"
-        mc:Ignorable="d" BorderBrush="Black" BorderThickness="1"
-        ShowInTaskbar="False" 
-        MinHeight="250" MinWidth="300" Height="250" Width="300" 
-        WindowStyle="None" 
-        WindowStartupLocation="CenterScreen" 
-        Name="importFilePopup"
-        local:Translator.Key="IMPORT_FILE_TITLE"
-        DataContext="{DynamicResource ImportFilePopupViewModel}"
-        FlowDirection="{helpers:Localization FlowDirection}">
-    <Window.Resources>
-        <vm:ImportFilePopupViewModel x:Key="ImportFilePopupViewModel" />
-    </Window.Resources>
-    <WindowChrome.WindowChrome>
-        <WindowChrome CaptionHeight="32"  GlassFrameThickness="0.1"
-                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
-    </WindowChrome.WindowChrome>
-
-    <Window.CommandBindings>
-        <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute"
-                        Executed="CommandBinding_Executed_Close" />
-    </Window.CommandBindings>
-
-    <DockPanel Background="{StaticResource AccentColor}">
-        <i:Interaction.Behaviors>
-            <behaviours:ClearFocusOnClickBehavior/>
-        </i:Interaction.Behaviors>
-
-        <dial:DialogTitleBar DockPanel.Dock="Top"
-            TitleKey="IMPORT_FILE_TITLE" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"/>
-        <Button DockPanel.Dock="Bottom" Width="70" HorizontalAlignment="Center" IsDefault="True"
-                    Margin="15" Style="{StaticResource DarkRoundButton}" Content="Import" Command="{Binding OkCommand}"
-                    CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
-        <userControls:SizePicker x:Name="sizePicker" Width="230" Height="125" Margin="0,30,0,0"
-                                  ChosenWidth="{Binding ImportWidth, Mode=TwoWay}"
-                                  ChosenHeight="{Binding ImportHeight, Mode=TwoWay}" />
-
-    </DockPanel>
-</Window>

+ 0 - 48
src/PixiEditor/Views/Dialogs/ImportFilePopup.xaml.cs

@@ -1,48 +0,0 @@
-using System.Windows;
-using System.Windows.Input;
-using PixiEditor.ViewModels;
-
-namespace PixiEditor.Views.Dialogs;
-
-internal partial class ImportFilePopup : Window
-{
-    private readonly ImportFilePopupViewModel dc = new ImportFilePopupViewModel();
-
-    public ImportFilePopup()
-    {
-        InitializeComponent();
-        DataContext = dc;
-        Loaded += (_, _) => sizePicker.FocusWidthPicker();
-    }
-
-
-    public int ImportHeight
-    {
-        get => dc.ImportHeight;
-        set => dc.ImportHeight = value;
-    }
-
-
-    public int ImportWidth
-    {
-        get => dc.ImportWidth;
-        set => dc.ImportWidth = value;
-    }
-
-
-    public string FilePath
-    {
-        get => dc.FilePath;
-        set => dc.FilePath = value;
-    }
-
-    private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
-    {
-        e.CanExecute = true;
-    }
-
-    private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
-    {
-        SystemCommands.CloseWindow(this);
-    }
-}