SaveFilePopupViewModel.cs 2.9 KB

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