mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-03 03:52:28 +08:00
Rewrite EvaluateWidget, add BaseArgumentHandler, use autocomplete for InteractiveEnum
This commit is contained in:
61
src/UI/Widgets/EvaluateWidget/GenericArgumentHandler.cs
Normal file
61
src/UI/Widgets/EvaluateWidget/GenericArgumentHandler.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UniverseLib;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets
|
||||
{
|
||||
public class GenericArgumentHandler : BaseArgumentHandler
|
||||
{
|
||||
private Type genericType;
|
||||
|
||||
public void OnBorrowed(EvaluateWidget evaluator, Type genericConstraint)
|
||||
{
|
||||
this.evaluator = evaluator;
|
||||
this.genericType = genericConstraint;
|
||||
|
||||
typeCompleter.Enabled = true;
|
||||
typeCompleter.BaseType = genericType;
|
||||
typeCompleter.CacheTypes();
|
||||
|
||||
var constraints = genericType.GetGenericParameterConstraints();
|
||||
typeCompleter.GenericConstraints = constraints;
|
||||
|
||||
var sb = new StringBuilder($"<color={SignatureHighlighter.CONST}>{genericType.Name}</color>");
|
||||
|
||||
for (int j = 0; j < constraints.Length; j++)
|
||||
{
|
||||
if (j == 0) sb.Append(' ').Append('(');
|
||||
else sb.Append(',').Append(' ');
|
||||
|
||||
sb.Append(SignatureHighlighter.Parse(constraints[j], false));
|
||||
|
||||
if (j + 1 == constraints.Length)
|
||||
sb.Append(')');
|
||||
}
|
||||
|
||||
argNameLabel.text = sb.ToString();
|
||||
}
|
||||
|
||||
public void OnReturned()
|
||||
{
|
||||
this.evaluator = null;
|
||||
this.genericType = null;
|
||||
|
||||
this.typeCompleter.Enabled = false;
|
||||
|
||||
this.inputField.Text = "";
|
||||
}
|
||||
|
||||
public Type Evaluate()
|
||||
{
|
||||
return ReflectionUtility.GetTypeByName(this.inputField.Text)
|
||||
?? throw new Exception($"Could not find any type by name '{this.inputField.Text}'!");
|
||||
}
|
||||
|
||||
public override void CreateSpecialContent()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user