Skip to content

Commit

Permalink
Rhino panels should be treated as if they might have been used before…
Browse files Browse the repository at this point in the history
… as Panels.Closed isn't called
  • Loading branch information
adamhathcock committed Jan 6, 2025
1 parent 95b3731 commit df89266
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,33 @@ public SpeckleRhinoPanelHost(uint docSn)
_webView = SpeckleConnectorsRhinoPlugin.Instance.Container?.GetRequiredService<DUI3ControlWebView>();
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,7 @@ 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

0 comments on commit df89266

Please sign in to comment.