SaveFilePopupViewModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Microsoft.Win32;
  2. using PixiEditor.Helpers;
  3. using PixiEditor.Views;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. namespace PixiEditor.ViewModels
  14. {
  15. class SaveFilePopupViewModel : ViewModelBase
  16. {
  17. public RelayCommand CloseButtonCommand { get; set; }
  18. public RelayCommand DragMoveCommand { get; set; }
  19. public RelayCommand ChoosePathCommand { get; set; }
  20. public RelayCommand OkCommand { get; set; }
  21. private string _pathButtonBorder = "#f08080";
  22. public string PathButtonBorder
  23. {
  24. get { return _pathButtonBorder; }
  25. set { if (_pathButtonBorder != value) { _pathButtonBorder = value; RaisePropertyChanged("PathButtonBorder"); } }
  26. }
  27. private bool _pathIsCorrect;
  28. public bool PathIsCorrect
  29. {
  30. get { return _pathIsCorrect; }
  31. set { if (_pathIsCorrect != value) { _pathIsCorrect = value; RaisePropertyChanged("PathIsCorrect"); } }
  32. }
  33. private string _filePath;
  34. public string FilePath
  35. {
  36. get { return _filePath; }
  37. set { if (_filePath != value) { _filePath = value; RaisePropertyChanged("FilePath"); } }
  38. }
  39. public SaveFilePopupViewModel()
  40. {
  41. CloseButtonCommand = new RelayCommand(CloseWindow);
  42. DragMoveCommand = new RelayCommand(MoveWindow);
  43. ChoosePathCommand = new RelayCommand(ChoosePath);
  44. OkCommand = new RelayCommand(OkButton, CanClickOk);
  45. }
  46. /// <summary>
  47. /// Command that handles Path choosing to save file
  48. /// </summary>
  49. /// <param name="parameter"></param>
  50. private void ChoosePath(object parameter)
  51. {
  52. SaveFileDialog path = new SaveFileDialog()
  53. {
  54. Title = "Export path",
  55. CheckPathExists = true,
  56. DefaultExt = "PNG Image (.png)|*.png",
  57. Filter = "PNG Image (.png)|*.png"
  58. };
  59. if(path.ShowDialog() == true)
  60. {
  61. if (string.IsNullOrEmpty(path.FileName) == false)
  62. {
  63. PathButtonBorder = "#b8f080";
  64. PathIsCorrect = true;
  65. FilePath = path.FileName;
  66. }
  67. else
  68. {
  69. PathButtonBorder = "#f08080";
  70. PathIsCorrect = false;
  71. }
  72. }
  73. }
  74. private void CloseWindow(object parameter)
  75. {
  76. ((Window)parameter).DialogResult = false;
  77. base.CloseButton(parameter);
  78. }
  79. private void MoveWindow(object parameter)
  80. {
  81. base.DragMove(parameter);
  82. }
  83. private void OkButton(object parameter)
  84. {
  85. ((Window)parameter).DialogResult = true;
  86. base.CloseButton(parameter);
  87. }
  88. private bool CanClickOk(object property)
  89. {
  90. return PathIsCorrect == true;
  91. }
  92. }
  93. }