Add tree view to main window.

This commit is contained in:
2020-04-11 04:35:38 +01:00
parent f8f334737b
commit 95f30ce5a5
8 changed files with 115 additions and 13 deletions

View File

@@ -1240,11 +1240,16 @@
</e> </e>
<e p="Models" t="Include"> <e p="Models" t="Include">
<e p="AssemblyModel.cs" t="Include" /> <e p="AssemblyModel.cs" t="Include" />
<e p="DeviceModel.cs" t="Include" />
<e p="DevicesRootModel.cs" t="Include" />
<e p="DeviceStatsModel.cs" t="Include" /> <e p="DeviceStatsModel.cs" t="Include" />
<e p="EncodingModel.cs" t="Include" /> <e p="EncodingModel.cs" t="Include" />
<e p="ImageModel.cs" t="Include" />
<e p="ImagesRootModel.cs" t="Include" />
<e p="MediaStatsModel.cs" t="Include" /> <e p="MediaStatsModel.cs" t="Include" />
<e p="NameCountModel.cs" t="Include" /> <e p="NameCountModel.cs" t="Include" />
<e p="PluginModel.cs" t="Include" /> <e p="PluginModel.cs" t="Include" />
<e p="RootModel.cs" t="Include" />
</e> </e>
<e p="obj" t="ExcludeRecursive"> <e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include"> <e p="Debug" t="Include">

View File

@@ -0,0 +1,4 @@
namespace Aaru.Gui.Models
{
public class DeviceModel {}
}

View File

@@ -0,0 +1,11 @@
using System.Collections.ObjectModel;
namespace Aaru.Gui.Models
{
public class DevicesRootModel : RootModel
{
public DevicesRootModel() => Devices = new ObservableCollection<DeviceModel>();
public ObservableCollection<DeviceModel> Devices { get; }
}
}

View File

@@ -0,0 +1,4 @@
namespace Aaru.Gui.Models
{
public class ImageModel {}
}

View File

@@ -0,0 +1,11 @@
using System.Collections.ObjectModel;
namespace Aaru.Gui.Models
{
public class ImagesRootModel : RootModel
{
public ImagesRootModel() => Images = new ObservableCollection<ImageModel>();
public ObservableCollection<ImageModel> Images { get; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Aaru.Gui.Models
{
public class RootModel
{
public string Name { get; set; }
}
}

View File

@@ -1,6 +1,9 @@
using System.Linq; using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive; using System.Reactive;
using Aaru.CommonTypes.Interop;
using Aaru.Database; using Aaru.Database;
using Aaru.Gui.Models;
using Aaru.Gui.Views; using Aaru.Gui.Views;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
@@ -12,8 +15,11 @@ namespace Aaru.Gui.ViewModels
{ {
public class MainWindowViewModel : ViewModelBase public class MainWindowViewModel : ViewModelBase
{ {
readonly MainWindow _view; readonly DevicesRootModel _devicesRoot;
ConsoleWindow _consoleWindow; readonly ImagesRootModel _imagesRoot;
readonly MainWindow _view;
ConsoleWindow _consoleWindow;
bool _devicesSupported;
public MainWindowViewModel(MainWindow view) public MainWindowViewModel(MainWindow view)
{ {
@@ -25,21 +31,51 @@ namespace Aaru.Gui.ViewModels
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand); SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
ConsoleCommand = ReactiveCommand.Create(ExecuteConsoleCommand); ConsoleCommand = ReactiveCommand.Create(ExecuteConsoleCommand);
_view = view; _view = view;
TreeRoot = new ObservableCollection<RootModel>();
_imagesRoot = new ImagesRootModel
{
Name = "Images"
};
TreeRoot.Add(_imagesRoot);
switch(DetectOS.GetRealPlatformID())
{
case PlatformID.Win32NT:
case PlatformID.Linux:
case PlatformID.FreeBSD:
_devicesRoot = new DevicesRootModel
{
Name = "Devices"
};
TreeRoot.Add(_devicesRoot);
DevicesSupported = true;
break;
}
} }
public string Greeting => "Welcome to Aaru!"; public bool DevicesSupported
{
get => _devicesSupported;
set => this.RaiseAndSetIfChanged(ref _devicesSupported, value);
}
public bool NativeMenuSupported => public bool NativeMenuSupported =>
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
IClassicDesktopStyleApplicationLifetime)?.MainWindow); IClassicDesktopStyleApplicationLifetime)?.MainWindow);
public ReactiveCommand<Unit, Unit> AboutCommand { get; } public string Greeting => "Welcome to Aaru!";
public ReactiveCommand<Unit, Unit> ConsoleCommand { get; } public ObservableCollection<RootModel> TreeRoot { get; }
public ReactiveCommand<Unit, Unit> EncodingsCommand { get; } public ReactiveCommand<Unit, Unit> AboutCommand { get; }
public ReactiveCommand<Unit, Unit> PluginsCommand { get; } public ReactiveCommand<Unit, Unit> ConsoleCommand { get; }
public ReactiveCommand<Unit, Unit> StatisticsCommand { get; } public ReactiveCommand<Unit, Unit> EncodingsCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; } public ReactiveCommand<Unit, Unit> PluginsCommand { get; }
public ReactiveCommand<Unit, Unit> SettingsCommand { get; } public ReactiveCommand<Unit, Unit> StatisticsCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
public ReactiveCommand<Unit, Unit> SettingsCommand { get; }
internal void ExecuteAboutCommand() internal void ExecuteAboutCommand()
{ {

View File

@@ -1,4 +1,5 @@
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:models="clr-namespace:Aaru.Gui.Models;assembly=Aaru.Gui"
xmlns:vm="clr-namespace:Aaru.Gui.ViewModels;assembly=Aaru.Gui" xmlns:vm="clr-namespace:Aaru.Gui.ViewModels;assembly=Aaru.Gui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800"
@@ -15,7 +16,7 @@
<Separator /> <Separator />
<MenuItem Header="E_xit" IsVisible="{Binding !NativeMenuSupported}" Command="{Binding ExitCommand}" /> <MenuItem Header="E_xit" IsVisible="{Binding !NativeMenuSupported}" Command="{Binding ExitCommand}" />
</MenuItem> </MenuItem>
<MenuItem Header="_Devices"> <MenuItem Header="_Devices" IsVisible="{Binding DevicesSupported}">
<MenuItem Header="_Refresh" /> <MenuItem Header="_Refresh" />
</MenuItem> </MenuItem>
<MenuItem Header="_Window"> <MenuItem Header="_Window">
@@ -30,6 +31,29 @@
Command="{Binding AboutCommand}" /> Command="{Binding AboutCommand}" />
</MenuItem> </MenuItem>
</Menu> </Menu>
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center" /> <Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /><ColumnDefinition Width="5" /><ColumnDefinition Width="6*" />
</Grid.ColumnDefinitions>
<TreeView Items="{Binding TreeRoot}">
<TreeView.DataTemplates>
<TreeDataTemplate DataType="models:DevicesRootModel" ItemsSource="{Binding Devices}">
<StackPanel Orientation="Horizontal">
<Image Width="24" Height="24" Source="/Assets/Icons/oxygen/32x32/computer.png" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</TreeDataTemplate>
<TreeDataTemplate DataType="models:ImagesRootModel" ItemsSource="{Binding Images}">
<StackPanel Orientation="Horizontal">
<Image Width="24" Height="24" Source="/Assets/Icons/oxygen/32x32/inode-directory.png" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</TreeDataTemplate>
</TreeView.DataTemplates>
</TreeView>
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" />
<TextBlock Grid.Column="2" Text="{Binding Greeting}" HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</DockPanel> </DockPanel>
</Window> </Window>