diff --git a/Bonsai.Editor/EditorForm.cs b/Bonsai.Editor/EditorForm.cs index 202be6a9..d7a1df4c 100644 --- a/Bonsai.Editor/EditorForm.cs +++ b/Bonsai.Editor/EditorForm.cs @@ -1531,55 +1531,6 @@ private void toolboxTreeView_ItemDrag(object sender, ItemDragEventArgs e) } } - static string GetElementName(object component) - { - var name = ExpressionBuilder.GetElementDisplayName(component); - if (component is ExternalizedProperty workflowProperty && - !string.IsNullOrWhiteSpace(workflowProperty.Name) && - workflowProperty.Name != workflowProperty.MemberName) - { - return name + " (" + workflowProperty.MemberName + ")"; - } - - var componentType = component.GetType(); - if (component is BinaryOperatorBuilder binaryOperator && binaryOperator.Operand != null) - { - var operandType = binaryOperator.Operand.GetType(); - if (operandType.IsGenericType) operandType = operandType.GetGenericArguments()[0]; - return name + " (" + ExpressionBuilder.GetElementDisplayName(operandType) + ")"; - } - else if (component is SubscribeSubject subscribeSubject && componentType.IsGenericType) - { - componentType = componentType.GetGenericArguments()[0]; - if (string.IsNullOrWhiteSpace(subscribeSubject.Name)) - { - name = name.Substring(0, name.IndexOf("`")); - } - return name + " (" + ExpressionBuilder.GetElementDisplayName(componentType) + ")"; - } - else - { - if (component is INamedElement namedExpressionBuilder && !string.IsNullOrWhiteSpace(namedExpressionBuilder.Name)) - { - name += " (" + ExpressionBuilder.GetElementDisplayName(componentType) + ")"; - } - - return name; - } - } - - static string GetElementDescription(object component) - { - if (component is WorkflowExpressionBuilder workflowExpressionBuilder) - { - var description = workflowExpressionBuilder.Description; - if (!string.IsNullOrEmpty(description)) return description; - } - - var descriptionAttribute = (DescriptionAttribute)TypeDescriptor.GetAttributes(component)[typeof(DescriptionAttribute)]; - return descriptionAttribute.Description; - } - void editorControl_Enter(object sender, EventArgs e) { var selectedView = selectionModel.SelectedView; @@ -1602,9 +1553,9 @@ private void selectionModel_SelectionChanged(object sender, EventArgs e) private void GetSelectionDescription(object[] selectedObjects, out string displayName, out string description) { - var displayNames = selectedObjects.Select(GetElementName).Distinct().Reverse().ToArray(); + var displayNames = selectedObjects.Select(ElementHelper.GetElementName).Distinct().Reverse().ToArray(); displayName = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " ", displayNames); - var objectDescriptions = selectedObjects.Select(GetElementDescription).Distinct().Reverse().ToArray(); + var objectDescriptions = selectedObjects.Select(ElementHelper.GetElementDescription).Distinct().Reverse().ToArray(); description = objectDescriptions.Length == 1 ? objectDescriptions[0] : string.Empty; } @@ -1645,8 +1596,8 @@ private void UpdatePropertyGrid() var launcher = selectedView.Launcher; if (launcher != null) { - displayName = GetElementName(launcher.Builder); - description = GetElementDescription(launcher.Builder); + displayName = ElementHelper.GetElementName(launcher.Builder); + description = ElementHelper.GetElementDescription(launcher.Builder); } else { @@ -2365,7 +2316,14 @@ private async Task OpenDocumentationAsync(string assemblyName, string uid) if (!ModifierKeys.HasFlag(Keys.Control) && editorControl.WebViewInitialized) { editorControl.WebView.CoreWebView2.Navigate(url.AbsoluteUri); - editorControl.ExpandWebView(); + var nameSeparator = uid.LastIndexOf(ExpressionHelper.MemberSeparator); + if (nameSeparator >= 0) + { + var name = uid.Substring(nameSeparator + 1); + var categoryName = GetPackageDisplayName(uid.Substring(0, nameSeparator)); + editorControl.ExpandWebView(label: $"{name} ({categoryName})"); + } + else editorControl.ExpandWebView(label: uid); } else EditorDialog.OpenUrl(url); } diff --git a/Bonsai.Editor/GraphModel/ElementHelper.cs b/Bonsai.Editor/GraphModel/ElementHelper.cs new file mode 100644 index 00000000..862e0828 --- /dev/null +++ b/Bonsai.Editor/GraphModel/ElementHelper.cs @@ -0,0 +1,57 @@ +using System.ComponentModel; +using Bonsai.Expressions; + +namespace Bonsai.Editor.GraphModel +{ + static class ElementHelper + { + public static string GetElementName(object component) + { + var name = ExpressionBuilder.GetElementDisplayName(component); + if (component is ExternalizedProperty workflowProperty && + !string.IsNullOrWhiteSpace(workflowProperty.Name) && + workflowProperty.Name != workflowProperty.MemberName) + { + return name + " (" + workflowProperty.MemberName + ")"; + } + + var componentType = component.GetType(); + if (component is BinaryOperatorBuilder binaryOperator && binaryOperator.Operand != null) + { + var operandType = binaryOperator.Operand.GetType(); + if (operandType.IsGenericType) operandType = operandType.GetGenericArguments()[0]; + return name + " (" + ExpressionBuilder.GetElementDisplayName(operandType) + ")"; + } + else if (component is SubscribeSubject subscribeSubject && componentType.IsGenericType) + { + componentType = componentType.GetGenericArguments()[0]; + if (string.IsNullOrWhiteSpace(subscribeSubject.Name)) + { + name = name.Substring(0, name.IndexOf("`")); + } + return name + " (" + ExpressionBuilder.GetElementDisplayName(componentType) + ")"; + } + else + { + if (component is INamedElement namedExpressionBuilder && !string.IsNullOrWhiteSpace(namedExpressionBuilder.Name)) + { + name += " (" + ExpressionBuilder.GetElementDisplayName(componentType) + ")"; + } + + return name; + } + } + + public static string GetElementDescription(object component) + { + if (component is WorkflowExpressionBuilder workflowExpressionBuilder) + { + var description = workflowExpressionBuilder.Description; + if (!string.IsNullOrEmpty(description)) return description; + } + + var descriptionAttribute = (DescriptionAttribute)TypeDescriptor.GetAttributes(component)[typeof(DescriptionAttribute)]; + return descriptionAttribute.Description; + } + } +} diff --git a/Bonsai.Editor/GraphView/WorkflowEditorControl.cs b/Bonsai.Editor/GraphView/WorkflowEditorControl.cs index 478b8438..f156e54e 100644 --- a/Bonsai.Editor/GraphView/WorkflowEditorControl.cs +++ b/Bonsai.Editor/GraphView/WorkflowEditorControl.cs @@ -7,6 +7,7 @@ using Bonsai.Editor.Themes; using Microsoft.Web.WebView2.WinForms; using Microsoft.Web.WebView2.Core; +using Bonsai.Editor.GraphModel; namespace Bonsai.Editor.GraphView { @@ -76,16 +77,16 @@ public ExpressionBuilderGraph Workflow set { WorkflowGraphView.Workflow = value; } } - public void ExpandWebView() + public void ExpandWebView(ExpressionBuilder builder) { - splitContainer.Panel1Collapsed = false; + webView.Tag = builder; + ExpandWebView(ElementHelper.GetElementName(builder)); } - public void ExpandWebView(ExpressionBuilder builder) + public void ExpandWebView(string label) { - webView.Tag = builder; - browserLabel.Text = $"Browser ({ExpressionBuilder.GetElementDisplayName(builder)})"; - ExpandWebView(); + browserLabel.Text = label; + splitContainer.Panel1Collapsed = false; } public void CollapseWebView()