Statistics
| Branch: | Revision:

root / trunk / Pithos.OFM / LocalFilesViewModel.cs @ 71374945

History | View | Annotate | Download (3.6 kB)

1
´╗┐using System;
2
using System.Collections.Generic;
3
using System.ComponentModel.Composition;
4
using System.IO;
5
using System.Linq;
6
using System.Text;
7
using System.Windows;
8
using Caliburn.Micro;
9
using Pithos.Interfaces;
10

    
11
namespace Pithos.OFM
12
{
13
    [Export]
14
    public class LocalFilesViewModel:Screen
15
    {
16
        private IEnumerable<DirectoryRecord> _localFiles;
17

    
18
        private FileSystemInfo _currentLocalItem;
19

    
20

    
21

    
22
        public IEnumerable<DirectoryRecord> LocalFiles
23
        {
24
            get { return _localFiles; }
25
            set
26
            {
27
                if (Equals(value, _localFiles)) return;
28
                _localFiles = value;
29
                NotifyOfPropertyChange(() => LocalFiles);
30
            }
31
        }
32

    
33
        private IInfoRecord _selectedLocalFile;
34

    
35
        public IInfoRecord SelectedLocalFile
36
        {
37
            get { return _selectedLocalFile; }
38
            set
39
            {
40
                if (Equals(value, _selectedLocalFile)) return;
41
                _selectedLocalFile = value;
42
                NotifyOfPropertyChange(() => SelectedLocalFile);
43
                NotifyOfPropertyChange(() => CanUpload);
44
                IsLocalSelected = true;
45
            }
46
        }
47

    
48
        public bool CanUpload { get { return SelectedLocalFile != null; } }
49

    
50

    
51

    
52

    
53
        private bool _isLocalBusy;
54
        private string _localBusyMessage;
55
        private bool _isLocalSelected;
56

    
57
        public void SelectLocalFile(RoutedPropertyChangedEventArgs<object> file)
58
        {
59
            SelectedLocalFile = (IInfoRecord)file.NewValue;
60
        }
61

    
62

    
63
        public bool IsLocalBusy
64
        {
65
            get { return _isLocalBusy; }
66
            set
67
            {
68
                if (value.Equals(_isLocalBusy)) return;
69
                _isLocalBusy = value;
70
                NotifyOfPropertyChange(() => IsLocalBusy);
71
            }
72
        }
73

    
74
        public string LocalBusyMessage
75
        {
76
            get { return _localBusyMessage; }
77
            set
78
            {
79
                if (value == _localBusyMessage) return;
80
                _localBusyMessage = value;
81
                NotifyOfPropertyChange(() => LocalBusyMessage);
82
            }
83
        }
84

    
85
        public void LoadLocalFiles(string path)
86
        {
87
            IsLocalBusy = true;
88
            LocalBusyMessage = "Reading local files ...";
89
            if (_watcher.Path != path)
90
            {
91
                _watcher.Path = path;
92
                _watcher.EnableRaisingEvents = true;
93
            }
94

    
95
            var folder = new DirectoryInfo(Path.Combine(path, "pithos"));
96
            LocalFiles = new List<DirectoryRecord>
97
                {
98
                    new DirectoryRecord{DirInfo=folder}
99
                };
100
            IsLocalBusy = false;
101

    
102
        }
103

    
104
        readonly FileSystemWatcher _watcher;
105

    
106

    
107

    
108
        public bool IsLocalSelected
109
        {
110
            get { return _isLocalSelected; }
111
            set
112
            {
113
                if (value.Equals(_isLocalSelected)) return;
114
                _isLocalSelected = value;
115
                NotifyOfPropertyChange(() => IsLocalSelected);
116
            }
117
        }
118

    
119
        public FileSystemInfo CurrentLocalItem
120
        {
121
            get { return _currentLocalItem; }
122
            set
123
            {
124
                if (Equals(value, _currentLocalItem)) return;
125
                _currentLocalItem = value;
126
                NotifyOfPropertyChange(() => CurrentLocalItem);
127

    
128
            }
129
        }
130

    
131
        public LocalFilesViewModel()
132
        {
133
            _watcher = new FileSystemWatcher();            
134

    
135
        }
136

    
137
    }
138
}