Skip to content

Commit

Permalink
Custom decorations setting actually sets decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Aug 1, 2024
1 parent ca6ced3 commit 354f110
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
23 changes: 22 additions & 1 deletion SightKeeper.Avalonia/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Avalonia;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using CommunityToolkit.Diagnostics;

namespace SightKeeper.Avalonia.Extensions;
Expand All @@ -9,4 +11,23 @@ public static class ControlExtensions
public static TopLevel GetTopLevel(this Visual visual) =>
TopLevel.GetTopLevel(visual) ??
ThrowHelper.ThrowArgumentException<TopLevel>(nameof(visual), "Could`t find TopLevel of the visual");

public static void ReopenWindow<TWindow>() where TWindow : Window, new()
{
var application = global::Avalonia.Application.Current;
Guard.IsNotNull(application);
Guard.IsNotNull(application.ApplicationLifetime);
var lifetime = (IClassicDesktopStyleApplicationLifetime)application.ApplicationLifetime;
var window = lifetime.Windows.OfType<TWindow>().Single();
TWindow replacement = new()
{
Position = window.Position,
DataContext = window.DataContext,
WindowState = window.WindowState,
Width = window.Width,
Height = window.Height
};
replacement.Show();
window.Close();
}
}
8 changes: 7 additions & 1 deletion SightKeeper.Avalonia/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Material.Icons;
using SightKeeper.Avalonia.Dialogs;
using SightKeeper.Avalonia.Settings.Appearance;
using SightKeeper.Avalonia.ViewModels;
using SightKeeper.Avalonia.ViewModels.Elements;
using SettingsViewModel = SightKeeper.Avalonia.Settings.SettingsViewModel;
Expand All @@ -13,11 +14,16 @@ namespace SightKeeper.Avalonia;
internal sealed partial class MainViewModel : ViewModel, DialogHost
{
public DialogManager DialogManager { get; }
public AppearanceSettingsViewModel AppearanceSettings { get; }
public IReadOnlyCollection<TabItem> Tabs { get; }

public MainViewModel(IComponentContext context, DialogManager dialogManager)
public MainViewModel(
IComponentContext context,
DialogManager dialogManager,
AppearanceSettingsViewModel appearanceSettings)
{
DialogManager = dialogManager;
AppearanceSettings = appearanceSettings;
Tabs =
[
CreateTab<SettingsViewModel>(context, MaterialIconKind.Cog, "Settings"),
Expand Down
3 changes: 2 additions & 1 deletion SightKeeper.Avalonia/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
Title="Sight Keeper"
MinWidth="480"
MinHeight="320"
x:DataType="local:MainViewModel">
x:DataType="local:MainViewModel"
ExtendClientAreaToDecorationsHint="{Binding AppearanceSettings.CustomDecorations}">
<assists:WindowAssist.OverlayContent>
<dialogs:DialogHostPresenter/>
</assists:WindowAssist.OverlayContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using SightKeeper.Avalonia.Extensions;
using SightKeeper.Avalonia.ViewModels;

namespace SightKeeper.Avalonia.Settings.Appearance;
Expand All @@ -18,7 +19,8 @@ public bool CustomDecorations
return;
_customDecorations = value;
OnPropertyChanged();

// ISSUE Should not directly reference window
ControlExtensions.ReopenWindow<MainWindow>();
}
}

Expand Down
2 changes: 1 addition & 1 deletion SightKeeper.Avalonia/Setup/ViewModelsBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void Setup(ContainerBuilder builder)
{
builder.RegisterType<MainViewModel>();
builder.RegisterType<SettingsViewModel>();
builder.RegisterType<AppearanceSettingsViewModel>().As<SettingsSection>();
builder.RegisterType<AppearanceSettingsViewModel>().AsSelf().As<SettingsSection>().SingleInstance();
builder.RegisterType<GamesSettingsViewModel>().As<SettingsSection>();
builder.RegisterType<GamesRepositoryViewModel>();
builder.RegisterType<AddGameViewModel>();
Expand Down

0 comments on commit 354f110

Please sign in to comment.