Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rhino panels should be treated as if they might have been used before… #467

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ public SpeckleRhinoPanelHost(uint docSn)
Panels.Closed += PanelsOnClosed;
}

/// <summary>
/// This is a lot like PanelsOnClosed but called when trying to show the panel to clear out a lingering parent as PanelsOnClosed isn't called
/// </summary>
/// <param name="webView"></param>
public static void Reinitialize(DUI3ControlWebView? webView)
{
if (webView == null)
{
return;
}
// This check comes from behavioral difference on closing Rhino Panels.
// IsPanelVisible returns;
// - True, when docked Panel closed from the list on right click on panel tab,
// whenever it is closed with this way, Rhino.Panels tries to reinit this object and expect the different UIElement, that's why we disconnect Child.
// - False, when detached Panel is closed by 'X' close button.
// whenever it is closed with this way, Rhino.Panels don't create this object, that's why we do not disconnect Child UIElement.
if (Panels.IsPanelVisible(typeof(SpeckleRhinoPanelHost).GUID))
{
return;
}
// Disconnect UIElement from WpfElementHost. Otherwise, we can't reinit panel with same DUI3ControlWebView
if (LogicalTreeHelper.GetParent(webView) is Border border)
{
border.Child = null;
}
}

private void PanelsOnClosed(object? sender, PanelEventArgs e)
{
if (e.PanelId == typeof(SpeckleRhinoPanelHost).GUID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.IO;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Rhino;
using Rhino.Commands;
using Rhino.Input.Custom;
using Rhino.UI;
using Speckle.Connectors.DUI.WebView;
using Speckle.Connectors.Rhino.HostApp;

// using Speckle.Connectorss.Rhino.Properties;
Expand Down Expand Up @@ -65,6 +67,9 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)

if (mode == RunMode.Interactive)
{
SpeckleRhinoPanelHost.Reinitialize(
SpeckleConnectorsRhinoPlugin.Instance.Container?.GetRequiredService<DUI3ControlWebView>()
);
Panels.OpenPanel(panelId);
return Result.Success;
}
Expand Down
Loading