mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Add file information.
This commit is contained in:
@@ -8,4 +8,5 @@ public class FileModel
|
||||
public string Filename { get; set; }
|
||||
public IBrush ForegroundBrush { get; set; }
|
||||
public bool IsDirectory { get; set; }
|
||||
public FileInfo? FileInfo { get; set; }
|
||||
}
|
||||
@@ -15,15 +15,14 @@ namespace Aaru.Tui.ViewModels.Windows;
|
||||
public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
public string _copyright;
|
||||
string _copyright;
|
||||
[ObservableProperty]
|
||||
public string _currentPath;
|
||||
string _currentPath;
|
||||
[ObservableProperty]
|
||||
ObservableCollection<FileModel> _files = [];
|
||||
[ObservableProperty]
|
||||
public string _informationalVersion;
|
||||
[ObservableProperty]
|
||||
public FileModel _selectedFile;
|
||||
string _informationalVersion;
|
||||
FileModel? _selectedFile;
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
@@ -39,9 +38,31 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
Copyright = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright ?? "";
|
||||
}
|
||||
|
||||
public ICommand OpenSelectedFileCommand { get; }
|
||||
public FileModel? SelectedFile
|
||||
{
|
||||
get => _selectedFile;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedFile, value);
|
||||
OnPropertyChanged(nameof(IsFileInfoAvailable));
|
||||
OnPropertyChanged(nameof(SelectedFileIsNotDirectory));
|
||||
OnPropertyChanged(nameof(SelectedFileLength));
|
||||
OnPropertyChanged(nameof(SelectedFileCreationTime));
|
||||
OnPropertyChanged(nameof(SelectedFileLastWriteTime));
|
||||
OnPropertyChanged(nameof(SelectedFileAttributes));
|
||||
OnPropertyChanged(nameof(SelectedFileUnixMode));
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand OpenSelectedFileCommand { get; }
|
||||
public ICommand ExitCommand { get; }
|
||||
public bool IsFileInfoAvailable => SelectedFile?.FileInfo != null;
|
||||
public bool SelectedFileIsNotDirectory => SelectedFile?.IsDirectory == false;
|
||||
public long? SelectedFileLength => SelectedFile?.IsDirectory == false ? SelectedFile?.FileInfo?.Length : 0;
|
||||
public DateTime? SelectedFileCreationTime => SelectedFile?.FileInfo?.CreationTime;
|
||||
public DateTime? SelectedFileLastWriteTime => SelectedFile?.FileInfo?.LastWriteTime;
|
||||
public string? SelectedFileAttributes => SelectedFile?.FileInfo?.Attributes.ToString();
|
||||
public string? SelectedFileUnixMode => SelectedFile?.FileInfo?.UnixFileMode.ToString();
|
||||
|
||||
void Exit()
|
||||
{
|
||||
@@ -102,11 +123,18 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
|
||||
Files.Add(model);
|
||||
}
|
||||
|
||||
_ = Task.Run(Worker);
|
||||
}
|
||||
|
||||
void Worker()
|
||||
{
|
||||
foreach(FileModel file in Files) file.FileInfo = new FileInfo(file.Path);
|
||||
}
|
||||
|
||||
void OpenSelectedFile()
|
||||
{
|
||||
if(!SelectedFile.IsDirectory) return;
|
||||
if(SelectedFile?.IsDirectory != true) return;
|
||||
|
||||
CurrentPath = SelectedFile.Path;
|
||||
Environment.CurrentDirectory = CurrentPath;
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<Grid RowDefinitions="*,Auto"
|
||||
<Grid RowDefinitions="*,Auto,Auto"
|
||||
VerticalAlignment="Top">
|
||||
<Border Grid.Row="0"
|
||||
BorderThickness="1">
|
||||
@@ -81,6 +81,61 @@
|
||||
Foreground="Green" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<Border Grid.Row="2"
|
||||
BorderThickness="1"
|
||||
IsVisible="{Binding IsFileInfoAvailable, Mode=OneWay}">
|
||||
<Border.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<Grid RowDefinitions="Auto, *, *, *, *, *">
|
||||
<TextBlock Text="File information"
|
||||
Grid.Row="0"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="SlateBlue" />
|
||||
<Grid ColumnDefinitions="Auto, *"
|
||||
Grid.Row="1"
|
||||
IsVisible="{Binding SelectedFileIsNotDirectory, Mode=OneWay}">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="Length: " />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding SelectedFileLength, Mode=OneWay}"
|
||||
Foreground="Aqua" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="Auto, *"
|
||||
Grid.Row="2">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="Creation time: " />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding SelectedFileCreationTime, Mode=OneWay}"
|
||||
Foreground="Aqua" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="Auto, *"
|
||||
Grid.Row="3">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="Last write time: " />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding SelectedFileLastWriteTime, Mode=OneWay}"
|
||||
Foreground="Aqua" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="Auto, *"
|
||||
Grid.Row="4">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="Attributes: " />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding SelectedFileAttributes, Mode=OneWay}"
|
||||
Foreground="Aqua" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="Auto, *"
|
||||
Grid.Row="5">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="Mode: " />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding SelectedFileUnixMode, Mode=OneWay}"
|
||||
Foreground="Aqua" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user