mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Add main window.
This commit is contained in:
@@ -11,4 +11,11 @@
|
||||
<PackageReference Include="Consolonia"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Views\Windows\MainWindow.axaml.cs">
|
||||
<DependentUpon>MainWindow.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using Aaru.Tui.ViewModels.Windows;
|
||||
using Aaru.Tui.Views.Windows;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Aaru.Tui;
|
||||
|
||||
public partial class App : Application
|
||||
public class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -14,9 +16,10 @@ public partial class App : Application
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
|
||||
desktopLifetime.MainWindow = new MainWindow
|
||||
{
|
||||
desktopLifetime.MainWindow = new MainWindow();
|
||||
}
|
||||
DataContext = new MainWindowViewModel()
|
||||
};
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<Window 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:console="https://github.com/jinek/consolonia"
|
||||
xmlns:local="clr-namespace:Aaru.Tui"
|
||||
x:Class="Aaru.Tui.MainWindow"
|
||||
RequestedThemeVariant="Dark"
|
||||
Title="Consolonia">
|
||||
<StackPanel
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center">
|
||||
<TextBlock Text="Welcome to Consolonia!" />
|
||||
<Button Content="_Exit"
|
||||
Click="OnExit" />
|
||||
</StackPanel>
|
||||
</Window>
|
||||
@@ -1,21 +0,0 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Aaru.Tui
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnExit(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var lifetime = Application.Current!.ApplicationLifetime as IControlledApplicationLifetime;
|
||||
lifetime!.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Aaru.Tui/ViewModels/ViewModelBase.cs
Normal file
37
Aaru.Tui/ViewModels/ViewModelBase.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : ViewModelBase.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : GUI view models.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Inheritable view model.
|
||||
//
|
||||
// --[ 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 CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Aaru.Tui.ViewModels;
|
||||
|
||||
public class ViewModelBase : ObservableObject;
|
||||
45
Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs
Normal file
45
Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using System.Windows.Input;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Aaru.Tui.ViewModels.Windows;
|
||||
|
||||
public sealed class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty]
|
||||
ObservableCollection<string> _files = [];
|
||||
[ObservableProperty]
|
||||
public string _informationalVersion;
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
ExitCommand = new RelayCommand(Exit);
|
||||
|
||||
InformationalVersion =
|
||||
Assembly.GetExecutingAssembly()
|
||||
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
|
||||
?.InformationalVersion ??
|
||||
"?.?.?";
|
||||
}
|
||||
|
||||
public ICommand ExitCommand { get; }
|
||||
|
||||
void Exit()
|
||||
{
|
||||
var lifetime = Application.Current!.ApplicationLifetime as IControlledApplicationLifetime;
|
||||
lifetime!.Shutdown();
|
||||
}
|
||||
|
||||
public void LoadComplete()
|
||||
{
|
||||
Files.Add("..");
|
||||
|
||||
foreach(string file in
|
||||
Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*", SearchOption.TopDirectoryOnly))
|
||||
Files.Add(Path.GetFileName(file));
|
||||
}
|
||||
}
|
||||
50
Aaru.Tui/Views/Windows/MainWindow.axaml
Normal file
50
Aaru.Tui/Views/Windows/MainWindow.axaml
Normal file
@@ -0,0 +1,50 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:console="https://github.com/jinek/consolonia"
|
||||
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
||||
x:Class="Aaru.Tui.Views.Windows.MainWindow"
|
||||
RequestedThemeVariant="Dark"
|
||||
Title="Aaru">
|
||||
<Design.DataContext>
|
||||
<windows:MainWindowViewModel />
|
||||
</Design.DataContext>
|
||||
<DockPanel>
|
||||
<Menu DockPanel.Dock="Bottom">
|
||||
<MenuItem Header="F10 Exit"
|
||||
Command="{Binding ExitCommand, Mode=OneWay}"
|
||||
HotKey="F10" />
|
||||
</Menu>
|
||||
<Border BorderThickness="1">
|
||||
<Border.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
<ListBox Grid.Column="0"
|
||||
ItemsSource="{Binding Files, Mode=OneWay}"
|
||||
BorderThickness="1">
|
||||
<ListBox.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</ListBox.BorderBrush>
|
||||
</ListBox>
|
||||
<Border Grid.Column="1"
|
||||
BorderThickness="1">
|
||||
<Border.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<Grid RowDefinitions="*"
|
||||
VerticalAlignment="Top">
|
||||
<StackPanel Grid.Row="0"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Center">
|
||||
<TextBlock Text="Aaru Data Preservation Suite" />
|
||||
<TextBlock Text="{Binding InformationalVersion}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
</Window>
|
||||
21
Aaru.Tui/Views/Windows/MainWindow.axaml.cs
Normal file
21
Aaru.Tui/Views/Windows/MainWindow.axaml.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Aaru.Tui.ViewModels.Windows;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Aaru.Tui.Views.Windows;
|
||||
|
||||
public class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
(DataContext as MainWindowViewModel)?.LoadComplete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user