Skip to content

Commit

Permalink
better virtual dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 15, 2023
1 parent 6c73ea3 commit 4e526b1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 30 deletions.
21 changes: 21 additions & 0 deletions src/OneWare.Core/Models/VirtualDialogModel.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion src/OneWare.Core/ViewModels/Windows/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +44,6 @@ public IEditor? CurrentEditor
public ObservableCollection<Control> BottomRightExtension { get; }
public ObservableCollection<IMenuItem> MainMenu { get; }


public MainWindowViewModel(IPaths paths, IActive active, IWindowService windowService, IDockService dockService,
ISettingsService settingsService)
{
Expand Down
44 changes: 31 additions & 13 deletions src/OneWare.Core/Views/Windows/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -156,19 +157,36 @@
</Border>
</Grid>

<Panel Name="DialogControlPanel" IsVisible="False">
<Border BoxShadow="0 6 8 0 #4F000000" Background="{DynamicResource ThemeBackgroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" CornerRadius="8" BorderThickness="1" BorderBrush="{DynamicResource ThemeBorderLowBrush}">
<Grid RowDefinitions="30, *">
<StackPanel Margin="8 0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
<Image Height="16" Width="16" VerticalAlignment="Center" Name="DialogIcon"/>
<TextBlock Margin="8 0" Height="16" Name="DialogTitle"/>
</StackPanel>
<Button Grid.Row="0" HorizontalAlignment="Right" Margin="3" Name="DialogCloseButton" Click="DialogCloseButton_OnClick">
<Image Height="12" Source="{DynamicResource MaterialDesign.Close}"/>
</Button>
<ContentControl Grid.Row="1" Name="DialogControl" />
</Grid>
</Border>
<Panel Name="DialogControlPanel" IsVisible="{Binding #VirtualDialogItemsControl.ItemCount}">
<ItemsControl Name="VirtualDialogItemsControl" ItemsSource="{Binding #MainViewView.VirtualDialogModels}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Panel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Panel Background="#01000000">
<Border BoxShadow="0 6 8 0 #4F000000" Background="{DynamicResource ThemeBackgroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" CornerRadius="8" BorderThickness="1" BorderBrush="{DynamicResource ThemeBorderLowBrush}">
<Grid RowDefinitions="30, *">
<StackPanel Margin="8 0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
<Image Height="16" Width="16" VerticalAlignment="Center" Source="{Binding Dialog.CustomIcon}"/>
<TextBlock Margin="8 0" Height="16" Text="{Binding Dialog.Title}"/>
</StackPanel>
<Button Grid.Row="0" HorizontalAlignment="Right" Margin="3" Command="{Binding Close}">
<Image Height="12" Source="{DynamicResource MaterialDesign.Close}"/>
</Button>
<ContentControl MaxHeight="{Binding #DialogControlPanel.Bounds.Height, Converter={x:Static converters:SharedConverters.AddConverter}, ConverterParameter=-35}"
MaxWidth="{Binding #DialogControlPanel.Bounds.Width}"
Width="{Binding Dialog.PrefWidth}"
Height="{Binding Dialog.PrefHeight}" Grid.Row="1"
Content="{Binding Dialog}" />
</Grid>
</Border>
</Panel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Panel>

</Panel>
Expand Down
27 changes: 11 additions & 16 deletions src/OneWare.Core/Views/Windows/MainView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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;

namespace OneWare.Core.Views.Windows;

public partial class MainView : UserControl
{
private readonly Stack<FlexibleWindow> _windowStack = new();
public ObservableCollection<VirtualDialogModel> VirtualDialogModels { get; } = new();

public MainView()
{
Expand All @@ -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;
Expand Down Expand Up @@ -70,4 +64,5 @@ private void DialogCloseButton_OnClick(object? sender, RoutedEventArgs e)
else _windowStack.Peek().Close();
}
}
*/
}
21 changes: 21 additions & 0 deletions src/OneWare.Shared/Converters/AddConverter.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
1 change: 1 addition & 0 deletions src/OneWare.Shared/Converters/SharedConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4e526b1

Please sign in to comment.