aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/Dialogs/SaveFileDialogViewVM.cs
blob: 18b5c080c44e8cd0b10af3f011fa1870868db72d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.FSE.Common;
using Tango.FSE.Common.Storage;

namespace Tango.FSE.Procedures.Dialogs
{
    public class SaveFileDialogViewVM : FSEDialogViewVM
    {
        [TangoInject]
        protected IStorageProvider StorageProvider { get; set; }

        private String _selectedFile;
        public String SelectedFile
        {
            get { return _selectedFile; }
            set { _selectedFile = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }

        public String Extension { get; set; }
        public String Message { get; set; }
        public String DefaultFileName { get; set; }

        public RelayCommand BrowseCommand { get; set; }

        public SaveFileDialogViewVM(String message, String extension, String defaultFileName)
        {
            TangoIOC.Default.Inject(this);

            AutoMode = true;
            Message = message;
            Extension = extension;
            DefaultFileName = defaultFileName;

            BrowseCommand = new RelayCommand(BrowseForFile);
        }

        private async void BrowseForFile()
        {
            var result = await StorageProvider.SaveFile("Select File Location", $"Files|{Extension}", DefaultFileName);

            if (result.Confirmed)
            {
                SelectedFile = result.SelectedItem;
            }
        }

        protected override bool CanOK()
        {
            return base.CanOK() && SelectedFile != null;
        }

        protected override void Cancel()
        {
            SelectedFile = null;
            base.Cancel();
        }
    }
}