Browse Source

Fix event attachment

pull/165/head
Ionite 1 year ago
parent
commit
e4203ec750
No known key found for this signature in database
  1. 56
      StabilityMatrix.Avalonia/Controls/Dock/DockUserControlBase.cs
  2. 1
      StabilityMatrix.Avalonia/Views/InferencePage.axaml

56
StabilityMatrix.Avalonia/Controls/Dock/DockUserControlBase.cs

@ -48,26 +48,42 @@ public abstract class DockUserControlBase : DropTargetUserControlBase
// Attach handlers for view state saving and loading
if (DataContext is InferenceTabViewModelBase vm)
{
vm.SaveViewStateRequested += (_, args) =>
{
var saveTcs = new TaskCompletionSource<ViewState>();
Dispatcher.UIThread.Post(() =>
{
var state = new ViewState { DockLayout = SaveDockLayout() };
saveTcs.SetResult(state);
});
args.StateTask ??= saveTcs.Task;
};
vm.LoadViewStateRequested += (_, args) =>
{
if (args.State.DockLayout is { } layout)
{
LoadDockLayout(layout);
}
};
vm.SaveViewStateRequested += DataContext_OnSaveViewStateRequested;
vm.LoadViewStateRequested += DataContext_OnLoadViewStateRequested;
}
}
/// <inheritdoc />
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
// Detach handlers for view state saving and loading
if (DataContext is InferenceTabViewModelBase vm)
{
vm.SaveViewStateRequested -= DataContext_OnSaveViewStateRequested;
vm.LoadViewStateRequested -= DataContext_OnLoadViewStateRequested;
}
}
private void DataContext_OnSaveViewStateRequested(object? sender, SaveViewStateEventArgs args)
{
var saveTcs = new TaskCompletionSource<ViewState>();
Dispatcher.UIThread.Post(() =>
{
var state = new ViewState { DockLayout = SaveDockLayout() };
saveTcs.SetResult(state);
});
args.StateTask ??= saveTcs.Task;
}
private void DataContext_OnLoadViewStateRequested(object? sender, LoadViewStateEventArgs args)
{
if (args.State.DockLayout is { } layout)
{
LoadDockLayout(layout);
}
}

1
StabilityMatrix.Avalonia/Views/InferencePage.axaml

@ -217,6 +217,7 @@
<ui:MenuFlyoutSeparator IsVisible="{Binding SharedState.IsDebugMode}" />
<ui:MenuFlyoutItem
IsVisible="{Binding SharedState.IsDebugMode}"
Command="{Binding SelectedTab.DebugSaveViewStateCommand}"
Text="Show Dock State" />

Loading…
Cancel
Save