Browse Source

Remove path picker when exporting file

Equbuxu 3 years ago
parent
commit
244a58d808

+ 4 - 4
PixiEditor/Models/Dialogs/ExportFileDialog.cs

@@ -1,5 +1,5 @@
-using System.Windows;
-using PixiEditor.Views;
+using PixiEditor.Views;
+using System.Windows;
 
 namespace PixiEditor.Models.Dialogs
 {
@@ -58,7 +58,7 @@ namespace PixiEditor.Models.Dialogs
 
         public override bool ShowDialog()
         {
-            SaveFilePopup popup = new SaveFilePopup
+            ExportFilePopup popup = new ExportFilePopup
             {
                 SaveWidth = FileWidth,
                 SaveHeight = FileHeight
@@ -74,4 +74,4 @@ namespace PixiEditor.Models.Dialogs
             return (bool)popup.DialogResult;
         }
     }
-}
+}

+ 8 - 49
PixiEditor/ViewModels/SaveFilePopupViewModel.cs

@@ -8,51 +8,17 @@ namespace PixiEditor.ViewModels
     {
         private string _filePath;
 
-
-        private string _pathButtonBorder = "#f08080";
-
-
-        private bool _pathIsCorrect;
-
         public SaveFilePopupViewModel()
         {
             CloseButtonCommand = new RelayCommand(CloseWindow);
             DragMoveCommand = new RelayCommand(MoveWindow);
-            ChoosePathCommand = new RelayCommand(ChoosePath);
-            OkCommand = new RelayCommand(OkButton, CanClickOk);
+            OkCommand = new RelayCommand(OkButton);
         }
 
         public RelayCommand CloseButtonCommand { get; set; }
         public RelayCommand DragMoveCommand { get; set; }
-        public RelayCommand ChoosePathCommand { get; set; }
         public RelayCommand OkCommand { get; set; }
 
-        public string PathButtonBorder
-        {
-            get => _pathButtonBorder;
-            set
-            {
-                if (_pathButtonBorder != value)
-                {
-                    _pathButtonBorder = value;
-                    RaisePropertyChanged("PathButtonBorder");
-                }
-            }
-        }
-
-        public bool PathIsCorrect
-        {
-            get => _pathIsCorrect;
-            set
-            {
-                if (_pathIsCorrect != value)
-                {
-                    _pathIsCorrect = value;
-                    RaisePropertyChanged("PathIsCorrect");
-                }
-            }
-        }
-
         public string FilePath
         {
             get => _filePath;
@@ -69,7 +35,7 @@ namespace PixiEditor.ViewModels
         /// <summary>
         ///     Command that handles Path choosing to save file
         /// </summary>
-        private void ChoosePath(object parameter)
+        private string ChoosePath()
         {
             SaveFileDialog path = new SaveFileDialog
             {
@@ -82,16 +48,10 @@ namespace PixiEditor.ViewModels
             {
                 if (string.IsNullOrEmpty(path.FileName) == false)
                 {
-                    PathButtonBorder = "#b8f080";
-                    PathIsCorrect = true;
-                    FilePath = path.FileName;
-                }
-                else
-                {
-                    PathButtonBorder = "#f08080";
-                    PathIsCorrect = false;
+                    return path.FileName;
                 }
             }
+            return null;
         }
 
         private void CloseWindow(object parameter)
@@ -107,13 +67,12 @@ namespace PixiEditor.ViewModels
 
         private void OkButton(object parameter)
         {
+            string path = ChoosePath();
+            if (path == null)
+                return;
+            FilePath = path;
             ((Window)parameter).DialogResult = true;
             CloseButton(parameter);
         }
-
-        private bool CanClickOk(object property)
-        {
-            return PathIsCorrect;
-        }
     }
 }

+ 1 - 4
PixiEditor/Views/Dialogs/SaveFilePopup.xaml → PixiEditor/Views/Dialogs/ExportFilePopup.xaml

@@ -1,4 +1,4 @@
-<Window x:Class="PixiEditor.Views.SaveFilePopup"
+<Window x:Class="PixiEditor.Views.ExportFilePopup"
         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"
@@ -41,9 +41,6 @@
                                   x:Name="sizePicker"
                                   ChosenHeight="{Binding Path=SaveHeight, Mode=TwoWay, ElementName=saveFilePopup}"
                                   ChosenWidth="{Binding Path=SaveWidth, Mode=TwoWay, ElementName=saveFilePopup}" />
-            <Button Foreground="Snow" Height="40" Width="160" Margin="0,10,0,0" Content="Path"
-                        Background="{StaticResource MainColor}" BorderBrush="{Binding PathButtonBorder}"
-                        Command="{Binding ChoosePathCommand}" />
         </StackPanel>
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" IsDefault="True"
                     Margin="10" Style="{StaticResource DarkRoundButton}" Content="OK" Command="{Binding OkCommand}"

+ 8 - 11
PixiEditor/Views/Dialogs/SaveFilePopup.xaml.cs → PixiEditor/Views/Dialogs/ExportFilePopup.xaml.cs

@@ -1,23 +1,20 @@
 using PixiEditor.ViewModels;
 using System.Windows;
-using System.Windows.Input;
-
+using System.Windows.Input;
+
 namespace PixiEditor.Views
 {
-    /// <summary>
-    ///     Interaction logic for SaveFilePopup.xaml
-    /// </summary>
-    public partial class SaveFilePopup : Window
+    public partial class ExportFilePopup : Window
     {
         public static readonly DependencyProperty SaveHeightProperty =
-            DependencyProperty.Register("SaveHeight", typeof(int), typeof(SaveFilePopup), new PropertyMetadata(32));
+            DependencyProperty.Register("SaveHeight", typeof(int), typeof(ExportFilePopup), new PropertyMetadata(32));
 
 
         public static readonly DependencyProperty SaveWidthProperty =
-            DependencyProperty.Register("SaveWidth", typeof(int), typeof(SaveFilePopup), new PropertyMetadata(32));
+            DependencyProperty.Register("SaveWidth", typeof(int), typeof(ExportFilePopup), new PropertyMetadata(32));
+
+        private readonly SaveFilePopupViewModel dataContext = new SaveFilePopupViewModel();
 
-        private readonly SaveFilePopupViewModel dataContext = new SaveFilePopupViewModel();
-
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         {
             e.CanExecute = true;
@@ -28,7 +25,7 @@ namespace PixiEditor.Views
             SystemCommands.CloseWindow(this);
         }
 
-        public SaveFilePopup()
+        public ExportFilePopup()
         {
             InitializeComponent();
             Owner = Application.Current.MainWindow;