SOMS/test/YoloV5ImageLableWpfApp/FileSelectedVM.cs
2024-07-15 10:31:26 +08:00

120 lines
3.7 KiB
C#

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;
}
}