diff --git a/UI/TagHierarchyManager.UI.csproj b/UI/TagHierarchyManager.UI.csproj
index cfeb77c..b3ab760 100644
--- a/UI/TagHierarchyManager.UI.csproj
+++ b/UI/TagHierarchyManager.UI.csproj
@@ -8,21 +8,22 @@
-
-
+
+
-
-
-
-
+
+
+
+
None
All
-
+
+
@@ -55,4 +56,8 @@
Code
+
+
+
+
diff --git a/UI/ViewModels/MainWindowViewModel.cs b/UI/ViewModels/MainWindowViewModel.cs
index f649fbb..4c52165 100644
--- a/UI/ViewModels/MainWindowViewModel.cs
+++ b/UI/ViewModels/MainWindowViewModel.cs
@@ -1,6 +1,41 @@
-namespace TagHierarchyManager.UI.ViewModels;
+using System;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Threading.Tasks;
+using CommunityToolkit.Mvvm.ComponentModel;
+using TagHierarchyManager.Models;
+
+namespace TagHierarchyManager.UI.ViewModels;
public partial class MainWindowViewModel : ViewModelBase
{
- public string Greeting { get; } = "Welcome to Avalonia!";
+ private TagDatabase _database;
+
+ public ObservableCollection Tags;
+
+ [ObservableProperty]
+ private bool _isDbLoaded;
+
+ // TODO searchViewModel
+ // TODO hierarchyViewModel
+
+ public MainWindowViewModel()
+ {
+
+ }
+
+ public async Task LoadDatabase(string filePath)
+ {
+ TagDatabase db = new();
+ db.InitialisationComplete += (s, e) =>
+ {
+ Avalonia.Threading.Dispatcher.UIThread.Post(() =>
+ {
+ this._database = db;
+ this.IsDbLoaded = true;
+ });
+ Debug.WriteLine($"Database loaded on UI - name: {db.Name}, version: {db.Version}");
+ };
+ await db.LoadAsync(filePath);
+ }
}
\ No newline at end of file
diff --git a/UI/Views/MainWindow.axaml b/UI/Views/MainWindow.axaml
index d55da83..7731f7e 100644
--- a/UI/Views/MainWindow.axaml
+++ b/UI/Views/MainWindow.axaml
@@ -3,8 +3,10 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:assets="clr-namespace:TagHierarchyManager.UI.Assets"
+ xmlns:vm="clr-namespace:TagHierarchyManager.UI.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="TagHierarchyManager.UI.Views.MainWindow"
+ x:DataType="vm:MainWindowViewModel"
Title="{x:Static assets:Resources.Title}">
+
diff --git a/UI/Views/MainWindow.axaml.cs b/UI/Views/MainWindow.axaml.cs
index 3bc4fbb..a37c7f7 100644
--- a/UI/Views/MainWindow.axaml.cs
+++ b/UI/Views/MainWindow.axaml.cs
@@ -1,15 +1,48 @@
+using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
+using Avalonia.Platform.Storage;
+using TagHierarchyManager.UI.ViewModels;
namespace TagHierarchyManager.UI.Views;
public partial class MainWindow : Window
{
+ public MainWindowViewModel? ViewModel => DataContext as MainWindowViewModel;
+
public MainWindow()
{
InitializeComponent();
}
+ // TODO resx
+ private static FilePickerFileType TagDatabaseFileType { get; } = new("Tag Hierarchy Manager database")
+ {
+ Patterns = ["*.thdb"]
+ };
+
public void OpenAboutWindow(object? sender, RoutedEventArgs e) => new AboutWindow().ShowDialog(this);
public void Quit(object? sender, RoutedEventArgs e) => this.Close();
+
+ public async void MenuItemOpen_Click(object? sender, RoutedEventArgs e)
+ {
+ try
+ {
+ var files = await this.StorageProvider.OpenFilePickerAsync(
+ new FilePickerOpenOptions
+ {
+ AllowMultiple = false,
+ Title = "Open a tag database...",
+ FileTypeFilter = [TagDatabaseFileType]
+ });
+ if (files.Count == 0) return;
+ var path = files[0].TryGetLocalPath();
+ if (path == null) return;
+ await this.ViewModel.LoadDatabase(path);
+ }
+ catch (Exception ex)
+ {
+ throw; // TODO handle exception
+ }
+ }
}
\ No newline at end of file