Browse Source

ResizeDocumentPopup and ResizeCanvasPopup functionality moved to a base class.

tomaszkot 3 years ago
parent
commit
0f05ed5c6e

+ 15 - 23
PixiEditor/Models/Dialogs/ResizeDocumentDialog.cs

@@ -50,29 +50,12 @@ namespace PixiEditor.Models.Dialogs
             return OpenResizeCanvas ? ShowResizeCanvasDialog() : ShowResizeDocumentCanvas();
             return OpenResizeCanvas ? ShowResizeCanvasDialog() : ShowResizeDocumentCanvas();
         }
         }
 
 
-        private bool ShowResizeDocumentCanvas()
-        {
-            ResizeDocumentPopup popup = new ResizeDocumentPopup
-            {
-                NewHeight = Height,
-                NewWidth = Width
-            };
-
-            popup.ShowDialog();
-            if (popup.DialogResult == true)
+        bool ShowDialog<T>()
+            where T : ResizeablePopup, new()
+        {
+            var popup = new T()
             {
             {
-                Width = popup.NewWidth;
-                Height = popup.NewHeight;
-            }
-
-            return (bool)popup.DialogResult;
-        }
-
-        private bool ShowResizeCanvasDialog()
-        {
-            ResizeCanvasPopup popup = new ResizeCanvasPopup
-            {
-                NewAbsoluteHeight = Height,
+                NewAbsoluteHeight = Height,
                 NewAbsoluteWidth = Width,
                 NewAbsoluteWidth = Width,
                 NewPercentageSize = 100,
                 NewPercentageSize = 100,
                 NewSelectedUnit = SizeUnit.Pixel
                 NewSelectedUnit = SizeUnit.Pixel
@@ -83,10 +66,19 @@ namespace PixiEditor.Models.Dialogs
             {
             {
                 Width = popup.NewAbsoluteWidth;
                 Width = popup.NewAbsoluteWidth;
                 Height = popup.NewAbsoluteHeight;
                 Height = popup.NewAbsoluteHeight;
-                ResizeAnchor = popup.SelectedAnchorPoint;
             }
             }
 
 
             return (bool)popup.DialogResult;
             return (bool)popup.DialogResult;
         }
         }
+
+        private bool ShowResizeDocumentCanvas()
+        {
+            return ShowDialog<ResizeDocumentPopup>();
+        }
+
+        private bool ShowResizeCanvasDialog()
+        {
+            return ShowDialog<ResizeCanvasPopup>();
+        }
     }
     }
 }
 }

+ 4 - 4
PixiEditor/Views/Dialogs/ResizeCanvasPopup.xaml

@@ -1,4 +1,4 @@
-<Window x:Class="PixiEditor.Views.ResizeCanvasPopup"
+<base:ResizeablePopup x:Class="PixiEditor.Views.ResizeCanvasPopup"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -6,7 +6,8 @@
         xmlns:local="clr-namespace:PixiEditor.Views"
         xmlns:local="clr-namespace:PixiEditor.Views"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
         xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
-        mc:Ignorable="d" Name="window"
+        mc:Ignorable="d" x:Name="window"
+        xmlns:base="clr-namespace:PixiEditor.Views"
         Title="ResizeCanvasPopup" Topmost="True" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
         Title="ResizeCanvasPopup" Topmost="True" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
         Height="450" Width="400" WindowStyle="None">
         Height="450" Width="400" WindowStyle="None">
 
 
@@ -42,7 +43,6 @@
                               ChosenHeight="{Binding NewAbsoluteHeight, Mode=TwoWay, ElementName=window}"
                               ChosenHeight="{Binding NewAbsoluteHeight, Mode=TwoWay, ElementName=window}"
                               ChosenWidth="{Binding NewAbsoluteWidth, Mode=TwoWay, ElementName=window}"
                               ChosenWidth="{Binding NewAbsoluteWidth, Mode=TwoWay, ElementName=window}"
                               ChosenPercentageSize="{Binding NewPercentageSize, Mode=TwoWay, ElementName=window}"
                               ChosenPercentageSize="{Binding NewPercentageSize, Mode=TwoWay, ElementName=window}"
-                              x:Name="ThisSizePicker"
                               SelectedUnit="{ Binding NewSelectedUnit, Mode=TwoWay, ElementName=window}"
                               SelectedUnit="{ Binding NewSelectedUnit, Mode=TwoWay, ElementName=window}"
                               SizeUnitSelectionVisibility="Visible"
                               SizeUnitSelectionVisibility="Visible"
                               />
                               />
@@ -55,4 +55,4 @@
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10"
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10"
                 Style="{StaticResource DarkRoundButton}" Content="OK" Click="Button_Click" />
                 Style="{StaticResource DarkRoundButton}" Content="OK" Click="Button_Click" />
     </Grid>
     </Grid>
-</Window>
+</base:ResizeablePopup>

+ 2 - 41
PixiEditor/Views/Dialogs/ResizeCanvasPopup.xaml.cs

@@ -7,65 +7,26 @@ namespace PixiEditor.Views
     /// <summary>
     /// <summary>
     ///     Interaction logic for ResizeCanvasPopup.xaml
     ///     Interaction logic for ResizeCanvasPopup.xaml
     /// </summary>
     /// </summary>
-    public partial class ResizeCanvasPopup : Window
+    public partial class ResizeCanvasPopup : ResizeablePopup
     {
     {
         // Using a DependencyProperty as the backing store for SelectedAnchorPoint.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for SelectedAnchorPoint.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty SelectedAnchorPointProperty =
         public static readonly DependencyProperty SelectedAnchorPointProperty =
             DependencyProperty.Register("SelectedAnchorPoint", typeof(AnchorPoint), typeof(ResizeCanvasPopup),
             DependencyProperty.Register("SelectedAnchorPoint", typeof(AnchorPoint), typeof(ResizeCanvasPopup),
                 new PropertyMetadata(AnchorPoint.Top | AnchorPoint.Left));
                 new PropertyMetadata(AnchorPoint.Top | AnchorPoint.Left));
 
 
-        // Using a DependencyProperty as the backing store for NewHeight.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty NewAbsoluteHeightProperty =
-            DependencyProperty.Register("NewAbsoluteHeight", typeof(int), typeof(ResizeCanvasPopup), new PropertyMetadata(0));
-
-        // Using a DependencyProperty as the backing store for NewWidth.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty NewAbsoluteWidthProperty =
-            DependencyProperty.Register("NewAbsoluteWidth", typeof(int), typeof(ResizeCanvasPopup), new PropertyMetadata(0));
-
-        public static readonly DependencyProperty NewPercentageSizeProperty =
-            DependencyProperty.Register("NewPercentageSize", typeof(int), typeof(ResizeCanvasPopup), new PropertyMetadata(0));
-
-        public static readonly DependencyProperty NewSelectedUnitProperty =
-            DependencyProperty.Register(nameof(NewSelectedUnit), typeof(SizeUnit), typeof(SizePicker), new PropertyMetadata(SizeUnit.Pixel));
-
+        
         public ResizeCanvasPopup()
         public ResizeCanvasPopup()
         {
         {
             InitializeComponent();
             InitializeComponent();
             Owner = Application.Current.MainWindow;
             Owner = Application.Current.MainWindow;
         }
         }
 
 
-
         public AnchorPoint SelectedAnchorPoint
         public AnchorPoint SelectedAnchorPoint
         {
         {
             get => (AnchorPoint)GetValue(SelectedAnchorPointProperty);
             get => (AnchorPoint)GetValue(SelectedAnchorPointProperty);
             set => SetValue(SelectedAnchorPointProperty, value);
             set => SetValue(SelectedAnchorPointProperty, value);
         }
         }
 
 
-
-        public int NewAbsoluteHeight
-        {
-            get => (int)GetValue(NewAbsoluteHeightProperty);
-            set => SetValue(NewAbsoluteHeightProperty, value);
-        }
-
-        public int NewAbsoluteWidth
-        {
-            get => (int)GetValue(NewAbsoluteWidthProperty);
-            set => SetValue(NewAbsoluteWidthProperty, value);
-        }
-
-        public int NewPercentageSize 
-        {
-            get => (int)GetValue(NewPercentageSizeProperty);
-            set => SetValue(NewPercentageSizeProperty, value);
-        }
-
-        public SizeUnit NewSelectedUnit
-        {
-            get => (SizeUnit)GetValue(NewSelectedUnitProperty);
-            set => SetValue(NewSelectedUnitProperty, value);
-        }
-
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         {
         {
             e.CanExecute = true;
             e.CanExecute = true;

+ 11 - 6
PixiEditor/Views/Dialogs/ResizeDocumentPopup.xaml

@@ -1,11 +1,13 @@
-<Window x:Class="PixiEditor.Views.ResizeDocumentPopup"
+<base:ResizeablePopup x:Class="PixiEditor.Views.ResizeDocumentPopup"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
-        xmlns:local="clr-namespace:PixiEditor.Views" xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
-        mc:Ignorable="d" Name="window"
+        xmlns:local="clr-namespace:PixiEditor.Views" 
+        xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
+        mc:Ignorable="d" x:Name="window"
+        xmlns:base="clr-namespace:PixiEditor.Views"
         Title="ResizeDocumentPopup" Topmost="True" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
         Title="ResizeDocumentPopup" Topmost="True" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
         Height="400" Width="400" WindowStyle="None">
         Height="400" Width="400" WindowStyle="None">
 
 
@@ -37,12 +39,15 @@
                Content="Resize document" />
                Content="Resize document" />
         <StackPanel HorizontalAlignment="Center" Margin="0,50,0,0" Background="{StaticResource MainColor}"
         <StackPanel HorizontalAlignment="Center" Margin="0,50,0,0" Background="{StaticResource MainColor}"
                     VerticalAlignment="Top" Grid.Row="1" Width="350" Height="250">
                     VerticalAlignment="Top" Grid.Row="1" Width="350" Height="250">
-            <local:SizePicker Margin="0,20" ChosenHeight="{Binding Path=NewHeight, Mode=TwoWay, ElementName=window}"
-                              ChosenWidth="{Binding Path=NewWidth, Mode=TwoWay, ElementName=window}"
+            <local:SizePicker Margin="0,20" Width="300" Height="180"
+                              ChosenHeight="{Binding NewAbsoluteHeight, Mode=TwoWay, ElementName=window}"
+                              ChosenWidth="{Binding NewAbsoluteWidth, Mode=TwoWay, ElementName=window}"
+                              ChosenPercentageSize="{Binding NewPercentageSize, Mode=TwoWay, ElementName=window}"
+                              SelectedUnit="{ Binding NewSelectedUnit, Mode=TwoWay, ElementName=window}"
                               SizeUnitSelectionVisibility="Visible"
                               SizeUnitSelectionVisibility="Visible"
                               />
                               />
         </StackPanel>
         </StackPanel>
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10"
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10"
                 Style="{StaticResource DarkRoundButton}" Content="OK" Click="Button_Click" />
                 Style="{StaticResource DarkRoundButton}" Content="OK" Click="Button_Click" />
     </Grid>
     </Grid>
-</Window>
+</base:ResizeablePopup>

+ 1 - 21
PixiEditor/Views/Dialogs/ResizeDocumentPopup.xaml.cs

@@ -6,14 +6,8 @@ namespace PixiEditor.Views
     /// <summary>
     /// <summary>
     ///     Interaction logic for ResizeDocumentPopup.xaml
     ///     Interaction logic for ResizeDocumentPopup.xaml
     /// </summary>
     /// </summary>
-    public partial class ResizeDocumentPopup : Window
+    public partial class ResizeDocumentPopup : ResizeablePopup
     {
     {
-        public static readonly DependencyProperty NewHeightProperty =
-            DependencyProperty.Register("NewHeight", typeof(int), typeof(ResizeDocumentPopup), new PropertyMetadata(0));
-
-        public static readonly DependencyProperty NewWidthProperty =
-            DependencyProperty.Register("NewWidth", typeof(int), typeof(ResizeDocumentPopup), new PropertyMetadata(0));
-
         public ResizeDocumentPopup()
         public ResizeDocumentPopup()
         {
         {
             InitializeComponent();
             InitializeComponent();
@@ -21,20 +15,6 @@ namespace PixiEditor.Views
             DataContext = this;
             DataContext = this;
         }
         }
 
 
-        public int NewHeight
-        {
-            get => (int)GetValue(NewHeightProperty);
-            set => SetValue(NewHeightProperty, value);
-        }
-
-
-        public int NewWidth
-        {
-            get => (int)GetValue(NewWidthProperty);
-            set => SetValue(NewWidthProperty, value);
-        }
-
-
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         {
         {
             e.CanExecute = true;
             e.CanExecute = true;

+ 46 - 0
PixiEditor/Views/Dialogs/ResizeablePopup.cs

@@ -0,0 +1,46 @@
+using PixiEditor.Models.Enums;
+using System.Windows;
+
+namespace PixiEditor.Views
+{
+    public class ResizeablePopup : Window
+    {
+        public static readonly DependencyProperty NewPercentageSizeProperty =
+            DependencyProperty.Register(nameof(NewPercentageSize), typeof(int), typeof(ResizeablePopup), new PropertyMetadata(0));
+
+        public static readonly DependencyProperty NewSelectedUnitProperty =
+            DependencyProperty.Register(nameof(NewSelectedUnit), typeof(SizeUnit), typeof(SizePicker), new PropertyMetadata(SizeUnit.Pixel));
+
+        // Using a DependencyProperty as the backing store for NewAbsoluteHeight.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty NewAbsoluteHeightProperty =
+            DependencyProperty.Register(nameof(NewAbsoluteHeight), typeof(int), typeof(ResizeablePopup), new PropertyMetadata(0));
+
+        // Using a DependencyProperty as the backing store for NewAbsoluteWidth.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty NewAbsoluteWidthProperty =
+            DependencyProperty.Register(nameof(NewAbsoluteWidth), typeof(int), typeof(ResizeablePopup), new PropertyMetadata(0));
+
+        public int NewPercentageSize
+        {
+            get => (int)GetValue(NewPercentageSizeProperty);
+            set => SetValue(NewPercentageSizeProperty, value);
+        }
+
+        public SizeUnit NewSelectedUnit
+        {
+            get => (SizeUnit)GetValue(NewSelectedUnitProperty);
+            set => SetValue(NewSelectedUnitProperty, value);
+        }
+
+        public int NewAbsoluteHeight
+        {
+            get => (int)GetValue(NewAbsoluteHeightProperty);
+            set => SetValue(NewAbsoluteHeightProperty, value);
+        }
+
+        public int NewAbsoluteWidth
+        {
+            get => (int)GetValue(NewAbsoluteWidthProperty);
+            set => SetValue(NewAbsoluteWidthProperty, value);
+        }
+    }
+}