Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 15, 2023
1 parent b93d09e commit 6c73ea3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
23 changes: 17 additions & 6 deletions src/OneWare.Core/Views/Windows/MainView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Interactivity;
using DynamicData.Binding;
using OneWare.Shared.Controls;
using OneWare.Shared.ViewModels;

namespace OneWare.Core.Views.Windows;

Expand Down Expand Up @@ -38,11 +40,16 @@ public async Task ShowVirtualDialogAsync(FlexibleWindow window)
private void SetVirtualDialog(FlexibleWindow window)
{
DialogControlPanel.IsVisible = true;
DialogControl.Height = double.NaN;
DialogControl.Width = double.NaN;
DialogControl.Content = window;
DialogControl.Width = window.PrefWidth < this.Bounds.Width ? window.PrefWidth : this.Bounds.Width;
DialogControl.Height = window.PrefHeight + 40 < this.Bounds.Height ? window.PrefHeight : this.Bounds.Height - 40;
DialogControl.Background = window.WindowBackground;
DialogTitle.Text = window.Title;

if(!double.IsNaN(window.PrefWidth)) DialogControl.Width = window.PrefWidth < this.Bounds.Width ? window.PrefWidth : this.Bounds.Width;
if(!double.IsNaN(window.PrefHeight)) DialogControl.Height = window.PrefHeight + 40 < this.Bounds.Height ? window.PrefHeight : this.Bounds.Height - 40;

window.WhenValueChanged(x => x.Title).Subscribe(x => DialogTitle.Text = x);
window.WhenValueChanged(x => x.Background).Subscribe(x => DialogControl.Background = x);

if (window.CustomIcon != null)
{
DialogIcon.Source = window.CustomIcon;
Expand All @@ -56,7 +63,11 @@ private void SetVirtualDialog(FlexibleWindow window)

private void DialogCloseButton_OnClick(object? sender, RoutedEventArgs e)
{
if(_windowStack.Any())
_windowStack.Peek().Close();
if (_windowStack.Any())
{
if(_windowStack.Peek() is {DataContext: FlexibleWindowViewModelBase vm} window)
vm.Close(window);
else _windowStack.Peek().Close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,14 @@ private async Task SafeQuitAsync(FlexibleWindow window)
{
case MessageBoxStatus.Yes:
SaveAndClose(window);
break;
return;
case MessageBoxStatus.No:
IsDirty = false;
break;
window.Close();
return;
case MessageBoxStatus.Canceled:
return;
}

IsDirty = false;
window.Close();
}

public void SaveAndClose(FlexibleWindow window)
Expand Down

0 comments on commit 6c73ea3

Please sign in to comment.