mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Implement GoToPath dialog for navigating to specified directory
This commit is contained in:
80
Aaru.Tui/ViewModels/Dialogs/GoToPathDialogViewModel.cs
Normal file
80
Aaru.Tui/ViewModels/Dialogs/GoToPathDialogViewModel.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Text User Interface.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2025 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Iciclecreek.Avalonia.WindowManager;
|
||||
|
||||
namespace Aaru.Tui.ViewModels.Dialogs;
|
||||
|
||||
public sealed partial class GoToPathDialogViewModel : ViewModelBase
|
||||
{
|
||||
internal ManagedWindow _dialog = null!;
|
||||
[ObservableProperty]
|
||||
string _errorMessage = string.Empty;
|
||||
[ObservableProperty]
|
||||
bool _hasError;
|
||||
[ObservableProperty]
|
||||
string? _path = string.Empty;
|
||||
|
||||
public GoToPathDialogViewModel(ManagedWindow dialog)
|
||||
{
|
||||
_dialog = dialog;
|
||||
OkCommand = new RelayCommand(Ok);
|
||||
CancelCommand = new RelayCommand(Cancel);
|
||||
}
|
||||
|
||||
public ICommand OkCommand { get; }
|
||||
public ICommand CancelCommand { get; }
|
||||
|
||||
void Ok()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Path))
|
||||
{
|
||||
HasError = true;
|
||||
ErrorMessage = "Path cannot be empty";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Directory.Exists(Path))
|
||||
{
|
||||
HasError = true;
|
||||
ErrorMessage = "Path does not exist";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_dialog.Close(true);
|
||||
}
|
||||
|
||||
void Cancel()
|
||||
{
|
||||
_dialog.Close(false);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,8 @@ using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Core;
|
||||
using Aaru.Helpers;
|
||||
using Aaru.Tui.Models;
|
||||
using Aaru.Tui.ViewModels.Dialogs;
|
||||
using Aaru.Tui.Views.Dialogs;
|
||||
using Aaru.Tui.Views.Windows;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@@ -70,6 +72,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
_view = view;
|
||||
ExitCommand = new RelayCommand(Exit);
|
||||
SectorViewCommand = new RelayCommand(SectorView);
|
||||
GoToPathCommand = new AsyncRelayCommand(GoToPathAsync);
|
||||
OpenSelectedFileCommand = new RelayCommand(OpenSelectedFile, CanOpenSelectedFile);
|
||||
|
||||
InformationalVersion =
|
||||
@@ -103,6 +106,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
public ICommand OpenSelectedFileCommand { get; }
|
||||
public ICommand ExitCommand { get; }
|
||||
public ICommand SectorViewCommand { get; }
|
||||
public ICommand GoToPathCommand { get; }
|
||||
public bool IsFileInfoAvailable => SelectedFile?.FileInfo != null;
|
||||
public bool SelectedFileIsNotDirectory => SelectedFile?.IsDirectory == false;
|
||||
public long? SelectedFileLength => SelectedFile?.IsDirectory == false ? SelectedFile?.FileInfo?.Length : 0;
|
||||
@@ -114,6 +118,30 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
||||
|
||||
public string? SelectedFileInformation => SelectedFile?.Information;
|
||||
|
||||
async Task GoToPathAsync()
|
||||
{
|
||||
var dialog = new GoToPathDialog
|
||||
{
|
||||
DataContext = new GoToPathDialogViewModel(null!)
|
||||
};
|
||||
|
||||
// Set the dialog reference after creation
|
||||
((GoToPathDialogViewModel)dialog.DataContext!)._dialog = dialog;
|
||||
|
||||
bool? result = await dialog.ShowDialog<bool?>(_view);
|
||||
|
||||
if(result == true)
|
||||
{
|
||||
var viewModel = (GoToPathDialogViewModel)dialog.DataContext;
|
||||
|
||||
if(viewModel.Path is not null && Directory.Exists(viewModel.Path))
|
||||
{
|
||||
Environment.CurrentDirectory = viewModel.Path;
|
||||
LoadFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SectorView()
|
||||
{
|
||||
if(SelectedFile?.ImageFormat is null) return;
|
||||
|
||||
40
Aaru.Tui/Views/Dialogs/GoToPathDialog.axaml
Normal file
40
Aaru.Tui/Views/Dialogs/GoToPathDialog.axaml
Normal file
@@ -0,0 +1,40 @@
|
||||
<windowManager:ManagedWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:windowManager="clr-namespace:Iciclecreek.Avalonia.WindowManager;assembly=Iciclecreek.Avalonia.WindowManager"
|
||||
xmlns:brushes="https://github.com/jinek/consolonia"
|
||||
xmlns:dialogs="clr-namespace:Aaru.Tui.ViewModels.Dialogs"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
Width="40"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
x:Class="Aaru.Tui.Views.Dialogs.GoToPathDialog"
|
||||
Title="Go to path">
|
||||
<Design.DataContext>
|
||||
<dialogs:GoToPathDialogViewModel />
|
||||
</Design.DataContext>
|
||||
<Border BorderThickness="1">
|
||||
<Border.BorderBrush>
|
||||
<brushes:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<StackPanel>
|
||||
<TextBlock Text="Enter destination path:" />
|
||||
<TextBox Text="{Binding Path, Mode=TwoWay}"
|
||||
Watermark="Destination path" />
|
||||
<TextBlock Text="{Binding ErrorMessage, Mode=OneWay}"
|
||||
Foreground="Red"
|
||||
IsVisible="{Binding HasError, Mode=OneWay}" />
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Right"
|
||||
Spacing="1">
|
||||
<Button Content="OK"
|
||||
Command="{Binding OkCommand, Mode=OneWay}" />
|
||||
<Button Content="Cancel"
|
||||
Command="{Binding CancelCommand, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</windowManager:ManagedWindow>
|
||||
11
Aaru.Tui/Views/Dialogs/GoToPathDialog.axaml.cs
Normal file
11
Aaru.Tui/Views/Dialogs/GoToPathDialog.axaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Iciclecreek.Avalonia.WindowManager;
|
||||
|
||||
namespace Aaru.Tui.Views.Dialogs;
|
||||
|
||||
public partial class GoToPathDialog : ManagedWindow
|
||||
{
|
||||
public GoToPathDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,10 @@
|
||||
<MenuItem Header="F2 ScVw"
|
||||
Command="{Binding SectorViewCommand, Mode=OneWay}"
|
||||
HotKey="F2" />
|
||||
<MenuItem Header="F3 " />
|
||||
<MenuItem Header="F4 GoTo"
|
||||
Command="{Binding GoToPathCommand, Mode=OneWay}"
|
||||
HotKey="F4" />
|
||||
<MenuItem Header="F10 Exit"
|
||||
Command="{Binding ExitCommand, Mode=OneWay}"
|
||||
HotKey="F10" />
|
||||
|
||||
Reference in New Issue
Block a user