123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.IO;
- using System.Windows.Input;
- namespace WatchDog.WPF
- {
- public class FileSelectedVM : INotifyPropertyChanged
- {
- private string selectedItem;
- public string SelectedItem
- {
- get { return selectedItem; }
- set
- {
- selectedItem = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedItem)));
- if (!string.IsNullOrEmpty(selectedItem))
- {
- CurrentDir = selectedItem;
- }
- }
- }
- private string currentDir = @"C:\Users\77411\Desktop";
- public string CurrentDir
- {
- get { return currentDir; }
- set
- {
- currentDir = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentDir)));
- }
- }
- public ICommand ExpandDirectory { get; }
- public ICommand ExpandCurrentDirectory { get; }
- public ICommand PreDirectory { get; }
- public ICommand RootDirectory { get; }
- public ICommand SelectedDirectory { get; }
- public ObservableCollection<string> FilesPath { get; set; } = new ObservableCollection<string>();
- public FileSelectedVM()
- {
- SelectedDirectory = new AnotherCommandImplementation(_ =>
- {
- if (!string.IsNullOrEmpty(selectedItem))
- {
- //dataBus.SetDirPath(SelectedItem);
- }
- else
- {
- //dataBus.SetDirPath(CurrentDir);
- }
- });
- ExpandDirectory = new AnotherCommandImplementation(_ =>
- {
- if (string.IsNullOrWhiteSpace(SelectedItem))
- {
- return;
- }
- var dirs = Directory.GetDirectories(SelectedItem);
- FilesPath.Clear();
- foreach (var item in dirs)
- {
- FilesPath.Add(item);
- }
- });
- PreDirectory = new AnotherCommandImplementation(_ =>
- {
- if (string.IsNullOrWhiteSpace(CurrentDir))
- {
- RootDirectory.Execute(_);
- return;
- }
- var root = Directory.GetDirectoryRoot(CurrentDir);
- if (root == CurrentDir)
- {
- RootDirectory.Execute(_);
- return;
- }
- FilesPath.Clear();
- var dir = Directory.GetParent(CurrentDir);
- CurrentDir = dir.FullName;
- var dirInfos = dir.GetDirectories();
- foreach (var item in dirInfos)
- {
- FilesPath.Add(item.FullName);
- }
- });
- ExpandCurrentDirectory = new AnotherCommandImplementation(_ => {
- var dirs = Directory.GetDirectories(CurrentDir);
- FilesPath.Clear();
- foreach (var item in dirs)
- {
- FilesPath.Add(item);
- }
- });
- RootDirectory =
- new AnotherCommandImplementation(_ =>
- {
- FilesPath.Clear();
- DriveInfo[] allDirves = DriveInfo.GetDrives();
- foreach (var item in allDirves)
- {
- FilesPath.Add(@item.Name);
- }
- });
- }
- public event PropertyChangedEventHandler PropertyChanged;
- }
- }
|