-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add descriptive title to docs and annotation panel
- Loading branch information
Showing
3 changed files
with
76 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters