mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Show ROM sets in main window.
This commit is contained in:
@@ -24,10 +24,12 @@
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using RomRepoMgr.Models;
|
||||
using RomRepoMgr.ViewModels;
|
||||
using RomRepoMgr.Views;
|
||||
|
||||
@@ -35,6 +37,8 @@ namespace RomRepoMgr
|
||||
{
|
||||
public class App : Application
|
||||
{
|
||||
List<RomSetModel> _romSets;
|
||||
|
||||
public override void Initialize() => AvaloniaXamlLoader.Load(this);
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
@@ -44,6 +48,7 @@ namespace RomRepoMgr
|
||||
var splashWindow = new SplashWindow();
|
||||
var swvm = new SplashWindowViewModel();
|
||||
swvm.WorkFinished += OnSplashFinished;
|
||||
swvm.GotRomSets += OnGotRomSets;
|
||||
splashWindow.DataContext = swvm;
|
||||
desktop.MainWindow = splashWindow;
|
||||
}
|
||||
@@ -51,6 +56,8 @@ namespace RomRepoMgr
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
void OnGotRomSets(object sender, SplashWindowViewModel.RomSetEventArgs e) => _romSets = e.RomSets;
|
||||
|
||||
void OnSplashFinished(object sender, EventArgs e)
|
||||
{
|
||||
if(!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop))
|
||||
@@ -64,7 +71,7 @@ namespace RomRepoMgr
|
||||
|
||||
// Create and show main window
|
||||
desktop.MainWindow = new MainWindow();
|
||||
desktop.MainWindow.DataContext = new MainWindowViewModel(desktop.MainWindow as MainWindow);
|
||||
desktop.MainWindow.DataContext = new MainWindowViewModel(desktop.MainWindow as MainWindow, _romSets);
|
||||
desktop.MainWindow.Show();
|
||||
|
||||
// Now can close when all windows are closed
|
||||
|
||||
@@ -25,9 +25,16 @@
|
||||
|
||||
namespace RomRepoMgr.Models
|
||||
{
|
||||
public sealed class RomSetModel
|
||||
public class RomSetModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string Comment { get; set; }
|
||||
public string Date { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Homepage { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Filename { get; set; }
|
||||
public string Sha384 { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
<PackageReference Include="Avalonia" Version="0.10.0-preview3" />
|
||||
<PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.0-preview3" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="0.10.0-preview3" />
|
||||
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0-preview3" />
|
||||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0-preview3" />
|
||||
<PackageReference Include="Svg.Skia.Avalonia" Version="0.10.0-preview3" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -39,20 +39,25 @@ namespace RomRepoMgr.ViewModels
|
||||
{
|
||||
readonly MainWindow _view;
|
||||
|
||||
public MainWindowViewModel(MainWindow view)
|
||||
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
|
||||
{
|
||||
_view = view;
|
||||
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
|
||||
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
|
||||
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
|
||||
ImportDatCommand = ReactiveCommand.Create(ExecuteImportDatCommand);
|
||||
RomSets = new ObservableCollection<RomSetModel>();
|
||||
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
||||
}
|
||||
|
||||
public ObservableCollection<RomSetModel> RomSets { get; }
|
||||
public string RomSetLabel => "ROM sets";
|
||||
public string RomSetNameLabel => "Name";
|
||||
public string RomSetVersionLabel => "Version";
|
||||
public ObservableCollection<RomSetModel> RomSets { get; }
|
||||
public string RomSetLabel => "ROM sets";
|
||||
public string RomSetNameLabel => "Name";
|
||||
public string RomSetVersionLabel => "Version";
|
||||
public string RomSetAuthorLabel => "Author";
|
||||
public string RomSetDateLabel => "Date";
|
||||
public string RomSetDescriptionLabel => "Description";
|
||||
public string RomSetCommentLabel => "Comment";
|
||||
public string RomSetHomepageLabel => "Homepage";
|
||||
|
||||
public string Greeting => "Hello World!";
|
||||
public bool NativeMenuSupported =>
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
@@ -33,6 +35,7 @@ using Avalonia.Threading;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReactiveUI;
|
||||
using RomRepoMgr.Database;
|
||||
using RomRepoMgr.Models;
|
||||
|
||||
namespace RomRepoMgr.ViewModels
|
||||
{
|
||||
@@ -44,6 +47,11 @@ namespace RomRepoMgr.ViewModels
|
||||
bool _loadingDatabaseOk;
|
||||
string _loadingDatabaseText;
|
||||
bool _loadingDatabaseUnknown;
|
||||
bool _loadingRomSetsError;
|
||||
|
||||
bool _loadingRomSetsOk;
|
||||
string _loadingRomSetsText;
|
||||
bool _loadingRomSetsUnknown;
|
||||
bool _loadingSettingsError;
|
||||
bool _loadingSettingsOk;
|
||||
string _loadingSettingsText;
|
||||
@@ -69,6 +77,9 @@ namespace RomRepoMgr.ViewModels
|
||||
MigratingDatabaseOk = false;
|
||||
MigratingDatabaseError = false;
|
||||
MigratingDatabaseUnknown = true;
|
||||
LoadingRomSetsOk = false;
|
||||
LoadingRomSetsError = false;
|
||||
LoadingRomSetsUnknown = true;
|
||||
ExitVisible = false;
|
||||
}
|
||||
|
||||
@@ -164,6 +175,30 @@ namespace RomRepoMgr.ViewModels
|
||||
set => this.RaiseAndSetIfChanged(ref _exitButtonText, value);
|
||||
}
|
||||
|
||||
public bool LoadingRomSetsOk
|
||||
{
|
||||
get => _loadingRomSetsOk;
|
||||
set => this.RaiseAndSetIfChanged(ref _loadingRomSetsOk, value);
|
||||
}
|
||||
|
||||
public bool LoadingRomSetsError
|
||||
{
|
||||
get => _loadingRomSetsError;
|
||||
set => this.RaiseAndSetIfChanged(ref _loadingRomSetsError, value);
|
||||
}
|
||||
|
||||
public bool LoadingRomSetsUnknown
|
||||
{
|
||||
get => _loadingRomSetsUnknown;
|
||||
set => this.RaiseAndSetIfChanged(ref _loadingRomSetsUnknown, value);
|
||||
}
|
||||
|
||||
public string LoadingRomSetsText
|
||||
{
|
||||
get => _loadingRomSetsText;
|
||||
set => this.RaiseAndSetIfChanged(ref _loadingRomSetsText, value);
|
||||
}
|
||||
|
||||
internal void ExecuteExitCommand() =>
|
||||
(Application.Current.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown();
|
||||
|
||||
@@ -173,6 +208,7 @@ namespace RomRepoMgr.ViewModels
|
||||
LoadingSettingsText = "Loading settings...";
|
||||
LoadingDatabaseText = "Loading database...";
|
||||
MigratingDatabaseText = "Migrating database...";
|
||||
LoadingRomSetsText = "Loading ROM sets...";
|
||||
ExitButtonText = "Exit";
|
||||
}
|
||||
|
||||
@@ -183,14 +219,14 @@ namespace RomRepoMgr.ViewModels
|
||||
try
|
||||
{
|
||||
Settings.Settings.LoadSettings();
|
||||
|
||||
Dispatcher.UIThread.Post(LoadDatabase);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// TODO: Log error
|
||||
Dispatcher.UIThread.Post(FailedLoadingSettings);
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Post(LoadDatabase);
|
||||
});
|
||||
|
||||
void FailedLoadingSettings()
|
||||
@@ -215,14 +251,14 @@ namespace RomRepoMgr.ViewModels
|
||||
Directory.CreateDirectory(dbPathFolder);
|
||||
|
||||
_ = Context.Singleton;
|
||||
|
||||
Dispatcher.UIThread.Post(MigrateDatabase);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// TODO: Log error
|
||||
Dispatcher.UIThread.Post(FailedLoadingDatabase);
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Post(MigrateDatabase);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -243,14 +279,14 @@ namespace RomRepoMgr.ViewModels
|
||||
try
|
||||
{
|
||||
Context.Singleton.Database.Migrate();
|
||||
|
||||
Dispatcher.UIThread.Post(LoadRomSets);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// TODO: Log error
|
||||
Dispatcher.UIThread.Post(FailedMigratingDatabase);
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Post(LoadMainWindow);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -261,14 +297,65 @@ namespace RomRepoMgr.ViewModels
|
||||
ExitVisible = true;
|
||||
}
|
||||
|
||||
void LoadMainWindow()
|
||||
void LoadRomSets()
|
||||
{
|
||||
MigratingDatabaseUnknown = false;
|
||||
MigratingDatabaseOk = true;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
GotRomSets?.Invoke(this, new RomSetEventArgs
|
||||
{
|
||||
RomSets = Context.Singleton.RomSets.OrderBy(r => r.Name).ThenBy(r => r.Version).
|
||||
ThenBy(r => r.Date).ThenBy(r => r.Description).ThenBy(r => r.Comment).
|
||||
ThenBy(r => r.Filename).Select(r => new RomSetModel
|
||||
{
|
||||
Author = r.Author,
|
||||
Comment = r.Comment,
|
||||
Date = r.Date,
|
||||
Description = r.Description,
|
||||
Filename = r.Filename,
|
||||
Homepage = r.Homepage,
|
||||
Name = r.Name,
|
||||
Sha384 = r.Sha384,
|
||||
Version = r.Version
|
||||
}).ToList()
|
||||
});
|
||||
|
||||
Dispatcher.UIThread.Post(LoadMainWindow);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// TODO: Log error
|
||||
Dispatcher.UIThread.Post(FailedLoadingRomSets);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void FailedLoadingRomSets()
|
||||
{
|
||||
LoadingRomSetsUnknown = false;
|
||||
LoadingRomSetsError = true;
|
||||
ExitVisible = true;
|
||||
}
|
||||
|
||||
void LoadMainWindow()
|
||||
{
|
||||
LoadingRomSetsUnknown = false;
|
||||
LoadingRomSetsOk = true;
|
||||
|
||||
WorkFinished?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal event EventHandler WorkFinished;
|
||||
|
||||
internal event EventHandler<RomSetEventArgs> GotRomSets;
|
||||
|
||||
public sealed class RomSetEventArgs : EventArgs
|
||||
{
|
||||
public List<RomSetModel> RomSets { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,41 @@
|
||||
</TabItem.Header>
|
||||
<DataGrid Items="{Binding RomSets}" HorizontalScrollBarVisibility="Visible">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="{Binding RomSetNameLabel}" Binding="{Binding Name}" Width="Auto"
|
||||
IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="{Binding RomSetVersionLabel}" Binding="{Binding Version}"
|
||||
Width="Auto" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Name}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding RomSetNameLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Version}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding RomSetVersionLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Author}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding RomSetAuthorLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Date}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding RomSetDateLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Description}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding RomSetDescriptionLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Comment}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding RomSetCommentLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTextColumn Binding="{Binding Homepage}" Width="Auto" IsReadOnly="True">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{Binding RomSetHomepageLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</TabItem>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
// Copyright © 2020 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
@@ -30,7 +31,13 @@ namespace RomRepoMgr.Views
|
||||
{
|
||||
public class MainWindow : Window
|
||||
{
|
||||
public MainWindow() => InitializeComponent();
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
xmlns:svg="clr-namespace:Svg.Skia.Avalonia;assembly=Svg.Skia.Avalonia" mc:Ignorable="d" d:DesignWidth="450"
|
||||
d:DesignHeight="250" x:Class="RomRepoMgr.Views.SplashWindow" Icon="/Assets/avalonia-logo.ico"
|
||||
Title="ROM Repository Manager" SystemDecorations="BorderOnly" WindowStartupLocation="CenterScreen" Width="250"
|
||||
Height="120">
|
||||
Height="140">
|
||||
<Design.DataContext>
|
||||
<vm:SplashWindowViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -66,6 +66,24 @@
|
||||
</Image>
|
||||
<TextBlock Text="{Binding MigratingDatabaseText}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
|
||||
<Image MaxWidth="24" MaxHeight="24" IsVisible="{Binding LoadingRomSetsOk}">
|
||||
<Image.Source>
|
||||
<svg:SvgImage Source="/Assets/emblem-checked.svg" />
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<Image MaxWidth="24" MaxHeight="24" IsVisible="{Binding LoadingRomSetsError}">
|
||||
<Image.Source>
|
||||
<svg:SvgImage Source="/Assets/emblem-error.svg" />
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<Image MaxWidth="24" MaxHeight="24" IsVisible="{Binding LoadingRomSetsUnknown}">
|
||||
<Image.Source>
|
||||
<svg:SvgImage Source="/Assets/emblem-question.svg" />
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<TextBlock Text="{Binding LoadingRomSetsText}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<Button Command="{Binding ExitCommand}" IsVisible="{Binding ExitVisible}" HorizontalAlignment="Right">
|
||||
<TextBlock Text="{Binding ExitButtonText}" />
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user