diff --git a/src/OneWare.Core/Models/VirtualDialogModel.cs b/src/OneWare.Core/Models/VirtualDialogModel.cs new file mode 100644 index 00000000..cc30add2 --- /dev/null +++ b/src/OneWare.Core/Models/VirtualDialogModel.cs @@ -0,0 +1,21 @@ +using OneWare.Shared.Controls; +using OneWare.Shared.ViewModels; + +namespace OneWare.Core.Models; + +public class VirtualDialogModel +{ + public FlexibleWindow Dialog { get; } + + public VirtualDialogModel(FlexibleWindow dialog) + { + Dialog = dialog; + } + + public void Close() + { + if(Dialog is {DataContext: FlexibleWindowViewModelBase vm}) + vm.Close(Dialog); + else Dialog.Close(); + } +} \ No newline at end of file diff --git a/src/OneWare.Core/ViewModels/Windows/MainWindowViewModel.cs b/src/OneWare.Core/ViewModels/Windows/MainWindowViewModel.cs index 68427eba..ed026468 100644 --- a/src/OneWare.Core/ViewModels/Windows/MainWindowViewModel.cs +++ b/src/OneWare.Core/ViewModels/Windows/MainWindowViewModel.cs @@ -2,6 +2,7 @@ using Avalonia.Controls; using CommunityToolkit.Mvvm.ComponentModel; using DynamicData.Binding; +using OneWare.Core.Models; using OneWare.Core.ViewModels.DockViews; using OneWare.Settings.ViewModels; using OneWare.Settings.Views; @@ -43,7 +44,6 @@ public IEditor? CurrentEditor public ObservableCollection BottomRightExtension { get; } public ObservableCollection MainMenu { get; } - public MainWindowViewModel(IPaths paths, IActive active, IWindowService windowService, IDockService dockService, ISettingsService settingsService) { diff --git a/src/OneWare.Core/Views/Windows/MainView.axaml b/src/OneWare.Core/Views/Windows/MainView.axaml index 21c0b074..3ab22d5a 100644 --- a/src/OneWare.Core/Views/Windows/MainView.axaml +++ b/src/OneWare.Core/Views/Windows/MainView.axaml @@ -9,6 +9,7 @@ xmlns:windows1="clr-namespace:OneWare.Core.Views.Windows" xmlns:controls="clr-namespace:OneWare.Shared.Controls;assembly=OneWare.Shared" xmlns:enums="clr-namespace:OneWare.Shared.Enums;assembly=OneWare.Shared" + xmlns:models="clr-namespace:OneWare.Core.Models" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="OneWare.Core.Views.Windows.MainView" mvvm:ViewModelLocator.AutoWireViewModel="False" Name="MainViewView" @@ -156,19 +157,36 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/OneWare.Core/Views/Windows/MainView.axaml.cs b/src/OneWare.Core/Views/Windows/MainView.axaml.cs index 7e8fc955..52a82cdb 100644 --- a/src/OneWare.Core/Views/Windows/MainView.axaml.cs +++ b/src/OneWare.Core/Views/Windows/MainView.axaml.cs @@ -1,7 +1,10 @@ -using System.Reactive.Linq; +using System.Collections.ObjectModel; +using System.Reactive.Linq; using Avalonia.Controls; using Avalonia.Interactivity; +using DynamicData; using DynamicData.Binding; +using OneWare.Core.Models; using OneWare.Shared.Controls; using OneWare.Shared.ViewModels; @@ -9,7 +12,7 @@ namespace OneWare.Core.Views.Windows; public partial class MainView : UserControl { - private readonly Stack _windowStack = new(); + public ObservableCollection VirtualDialogModels { get; } = new(); public MainView() { @@ -18,25 +21,16 @@ public MainView() public async Task ShowVirtualDialogAsync(FlexibleWindow window) { - _windowStack.Push(window); + var dialog = new VirtualDialogModel(window); - SetVirtualDialog(window); + VirtualDialogModels.Add(dialog); await Observable.FromEventPattern(h => window.Closed += h, h => window.Closed -= h).Take(1).GetAwaiter(); - - _windowStack.Pop(); - - if (_windowStack.Any()) - { - await ShowVirtualDialogAsync(_windowStack.Pop()); - } - else - { - DialogControl.Content = null; - DialogControlPanel.IsVisible = false; - } + + VirtualDialogModels.Remove(dialog); } + /* private void SetVirtualDialog(FlexibleWindow window) { DialogControlPanel.IsVisible = true; @@ -70,4 +64,5 @@ private void DialogCloseButton_OnClick(object? sender, RoutedEventArgs e) else _windowStack.Peek().Close(); } } + */ } \ No newline at end of file diff --git a/src/OneWare.Shared/Converters/AddConverter.cs b/src/OneWare.Shared/Converters/AddConverter.cs new file mode 100644 index 00000000..94b2dde0 --- /dev/null +++ b/src/OneWare.Shared/Converters/AddConverter.cs @@ -0,0 +1,21 @@ +using System.Globalization; +using Avalonia.Data.Converters; + +namespace OneWare.Shared.Converters +{ + public class AddConverter : IValueConverter + { + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + if (value == null || parameter == null) return false; + if(!double.TryParse(parameter.ToString(), out var param)) return null; + if(!double.TryParse(value.ToString(), out var val)) return null; + return param + val; + } + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/OneWare.Shared/Converters/SharedConverters.cs b/src/OneWare.Shared/Converters/SharedConverters.cs index f9ee2af0..bfe9c544 100644 --- a/src/OneWare.Shared/Converters/SharedConverters.cs +++ b/src/OneWare.Shared/Converters/SharedConverters.cs @@ -19,6 +19,7 @@ public static readonly IValueConverter public static readonly IValueConverter TimeUnitConverter = new TimeUnitConverter(); public static readonly IValueConverter PathToWindowIconConverter = new PathToWindowIconConverter(); public static readonly IValueConverter ViewFoundConverter = new ViewFoundConverter(); + public static readonly IValueConverter AddConverter = new AddConverter(); public static readonly PathToBitmapConverter PathToBitmapConverter = new(); public static readonly IMultiValueConverter PathsEqualConverter = new PathsEqualConverter(); public static readonly IMultiValueConverter ObjectsEqualConverter = new ObjectsEqualConverter();