mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Implement changing path.
This commit is contained in:
@@ -6,5 +6,6 @@ public class FileModel
|
|||||||
{
|
{
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
public string Filename { get; set; }
|
public string Filename { get; set; }
|
||||||
public IBrush ForegroundBrush { get; set; } // Add this property for ListBox Foreground binding
|
public IBrush ForegroundBrush { get; set; }
|
||||||
|
public bool IsDirectory { get; set; }
|
||||||
}
|
}
|
||||||
@@ -22,10 +22,13 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
ObservableCollection<FileModel> _files = [];
|
ObservableCollection<FileModel> _files = [];
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public string _informationalVersion;
|
public string _informationalVersion;
|
||||||
|
[ObservableProperty]
|
||||||
|
public FileModel _selectedFile;
|
||||||
|
|
||||||
public MainWindowViewModel()
|
public MainWindowViewModel()
|
||||||
{
|
{
|
||||||
ExitCommand = new RelayCommand(Exit);
|
ExitCommand = new RelayCommand(Exit);
|
||||||
|
OpenSelectedFileCommand = new RelayCommand(OpenSelectedFile, CanOpenSelectedFile);
|
||||||
|
|
||||||
InformationalVersion =
|
InformationalVersion =
|
||||||
Assembly.GetExecutingAssembly()
|
Assembly.GetExecutingAssembly()
|
||||||
@@ -36,6 +39,8 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
Copyright = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright ?? "";
|
Copyright = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommand OpenSelectedFileCommand { get; }
|
||||||
|
|
||||||
public ICommand ExitCommand { get; }
|
public ICommand ExitCommand { get; }
|
||||||
|
|
||||||
void Exit()
|
void Exit()
|
||||||
@@ -45,33 +50,41 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void LoadComplete()
|
public void LoadComplete()
|
||||||
|
{
|
||||||
|
LoadFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadFiles()
|
||||||
{
|
{
|
||||||
CurrentPath = Directory.GetCurrentDirectory();
|
CurrentPath = Directory.GetCurrentDirectory();
|
||||||
|
Files.Clear();
|
||||||
|
|
||||||
var parentDirectory = new FileModel
|
var parentDirectory = new FileModel
|
||||||
{
|
{
|
||||||
Filename = "..",
|
Filename = "..",
|
||||||
Path = Path.GetRelativePath(Directory.GetCurrentDirectory(), ".."),
|
Path = Path.GetRelativePath(CurrentPath, ".."),
|
||||||
ForegroundBrush =
|
ForegroundBrush =
|
||||||
new SolidColorBrush(Color.Parse(DirColorsParser.Instance.DirectoryColor ??
|
new SolidColorBrush(Color.Parse(DirColorsParser.Instance.DirectoryColor ??
|
||||||
DirColorsParser.Instance.NormalColor))
|
DirColorsParser.Instance.NormalColor)),
|
||||||
|
IsDirectory = true
|
||||||
};
|
};
|
||||||
|
|
||||||
Files.Add(parentDirectory);
|
Files.Add(parentDirectory);
|
||||||
|
|
||||||
foreach(FileModel model in Directory
|
foreach(FileModel model in Directory.GetDirectories(CurrentPath, "*", SearchOption.TopDirectoryOnly)
|
||||||
.GetDirectories(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly)
|
.Select(directory => new FileModel
|
||||||
.Select(directory => new FileModel
|
{
|
||||||
{
|
Path = directory,
|
||||||
Path = directory,
|
Filename = Path.GetFileName(directory),
|
||||||
Filename = Path.GetFileName(directory),
|
ForegroundBrush =
|
||||||
ForegroundBrush =
|
new SolidColorBrush(Color.Parse(DirColorsParser.Instance
|
||||||
new SolidColorBrush(Color.Parse(DirColorsParser.Instance.DirectoryColor ??
|
.DirectoryColor ??
|
||||||
DirColorsParser.Instance.NormalColor))
|
DirColorsParser.Instance.NormalColor)),
|
||||||
}))
|
IsDirectory = true
|
||||||
|
}))
|
||||||
Files.Add(model);
|
Files.Add(model);
|
||||||
|
|
||||||
foreach(string file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.TopDirectoryOnly))
|
foreach(string file in Directory.GetFiles(CurrentPath, "*", SearchOption.TopDirectoryOnly))
|
||||||
{
|
{
|
||||||
var model = new FileModel
|
var model = new FileModel
|
||||||
{
|
{
|
||||||
@@ -90,4 +103,15 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
Files.Add(model);
|
Files.Add(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenSelectedFile()
|
||||||
|
{
|
||||||
|
if(!SelectedFile.IsDirectory) return;
|
||||||
|
|
||||||
|
CurrentPath = SelectedFile.Path;
|
||||||
|
Environment.CurrentDirectory = CurrentPath;
|
||||||
|
LoadFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CanOpenSelectedFile() => SelectedFile != null;
|
||||||
}
|
}
|
||||||
@@ -24,10 +24,12 @@
|
|||||||
<ListBox Grid.Column="0"
|
<ListBox Grid.Column="0"
|
||||||
ItemsSource="{Binding Files, Mode=OneWay}"
|
ItemsSource="{Binding Files, Mode=OneWay}"
|
||||||
BorderThickness="1"
|
BorderThickness="1"
|
||||||
Background="Transparent">
|
Background="Transparent"
|
||||||
|
SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
|
||||||
|
KeyDown="ListBox_OnKeyDown">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="models:FileModel">
|
<DataTemplate DataType="models:FileModel">
|
||||||
<TextBox Text="{Binding Filename}"
|
<TextBox Text="{Binding Filename, Mode=OneWay}"
|
||||||
Foreground="{Binding ForegroundBrush, Mode=OneWay}"
|
Foreground="{Binding ForegroundBrush, Mode=OneWay}"
|
||||||
Background="Transparent" />
|
Background="Transparent" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
@@ -56,10 +58,10 @@
|
|||||||
<TextBlock Text="Aaru Data Preservation Suite"
|
<TextBlock Text="Aaru Data Preservation Suite"
|
||||||
Foreground="Red"
|
Foreground="Red"
|
||||||
FontWeight="Bold" />
|
FontWeight="Bold" />
|
||||||
<TextBlock Text="{Binding InformationalVersion}"
|
<TextBlock Text="{Binding InformationalVersion, Mode=OneWay}"
|
||||||
Foreground="Green"
|
Foreground="Green"
|
||||||
FontWeight="Bold" />
|
FontWeight="Bold" />
|
||||||
<TextBlock Text="{Binding Copyright}"
|
<TextBlock Text="{Binding Copyright, Mode=OneWay}"
|
||||||
Foreground="Blue"
|
Foreground="Blue"
|
||||||
FontWeight="Bold" />
|
FontWeight="Bold" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
@@ -75,7 +77,7 @@
|
|||||||
Text="Path: "
|
Text="Path: "
|
||||||
Foreground="SlateBlue" />
|
Foreground="SlateBlue" />
|
||||||
<TextBlock Grid.Column="1"
|
<TextBlock Grid.Column="1"
|
||||||
Text="{Binding CurrentPath}"
|
Text="{Binding CurrentPath, Mode=OneWay}"
|
||||||
Foreground="Green" />
|
Foreground="Green" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Aaru.Tui.ViewModels.Windows;
|
using Aaru.Tui.ViewModels.Windows;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
namespace Aaru.Tui.Views.Windows;
|
namespace Aaru.Tui.Views.Windows;
|
||||||
@@ -11,6 +12,18 @@ public partial class MainWindow : Window
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ListBox_OnKeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if(e.Key == Key.Enter)
|
||||||
|
{
|
||||||
|
if(DataContext is MainWindowViewModel vm && vm.OpenSelectedFileCommand.CanExecute(null))
|
||||||
|
{
|
||||||
|
vm.OpenSelectedFileCommand.Execute(null);
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnLoaded(RoutedEventArgs e)
|
protected override void OnLoaded(RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user