Add Code Docs module for Editor tooltips

This commit is contained in:
Wojciech Figat
2021-12-22 10:55:42 +01:00
parent 6b9a3c58d0
commit 73c22b75ea
10 changed files with 81 additions and 68 deletions

View File

@@ -625,11 +625,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
group.Panel.Open(false);
// Customize
var typeAttributes = scriptType.GetAttributes(false);
group.Panel.TooltipText = scriptType.TypeName;
var tooltip = (TooltipAttribute)typeAttributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltip != null)
group.Panel.TooltipText += '\n' + tooltip.Text;
group.Panel.TooltipText = Editor.Instance.CodeDocs.GetTooltip(scriptType);
if (script.HasPrefabLink)
group.Panel.HeaderTextColor = FlaxEngine.GUI.Style.Current.ProgressNormal;

View File

@@ -142,10 +142,15 @@ namespace FlaxEditor
public readonly ContentFindingModule ContentFinding;
/// <summary>
/// The content editing
/// The scripts editing
/// </summary>
public readonly CodeEditingModule CodeEditing;
/// <summary>
/// The scripts documentation
/// </summary>
public readonly CodeDocsModule CodeDocs;
/// <summary>
/// The editor state machine.
/// </summary>
@@ -237,6 +242,7 @@ namespace FlaxEditor
RegisterModule(ContentDatabase = new ContentDatabaseModule(this));
RegisterModule(ContentImporting = new ContentImportingModule(this));
RegisterModule(CodeEditing = new CodeEditingModule(this));
RegisterModule(CodeDocs = new CodeDocsModule(this));
RegisterModule(ProgressReporting = new ProgressReportingModule(this));
RegisterModule(ContentFinding = new ContentFindingModule(this));

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using FlaxEditor.CustomEditors;
using FlaxEditor.CustomEditors.Elements;
using FlaxEditor.Scripting;
using FlaxEngine;
namespace FlaxEditor.GUI
@@ -245,7 +246,7 @@ namespace FlaxEditor.GUI
if (field.Name.Equals("value__", StringComparison.Ordinal))
continue;
var attributes = (Attribute[])field.GetCustomAttributes();
var attributes = field.GetCustomAttributes(false);
if (attributes.Any(x => x is HideInEditorAttribute))
continue;
@@ -269,12 +270,7 @@ namespace FlaxEditor.GUI
}
}
string tooltip = null;
var tooltipAttr = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttr != null)
{
tooltip = tooltipAttr.Text;
}
string tooltip = Editor.Instance.CodeDocs.GetTooltip(new ScriptMemberInfo(field), attributes);
entries.Add(new Entry(name, Convert.ToInt64(field.GetRawConstantValue()), tooltip));
}

View File

@@ -46,14 +46,8 @@ namespace FlaxEditor.GUI
_type = type;
Name = type.Name;
TooltipText = type.TypeName;
TooltipText = Editor.Instance.CodeDocs.GetTooltip(type, attributes);
Tag = type;
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
{
TooltipText += '\n';
TooltipText += tooltipAttribute.Text;
}
var categoryAttribute = (CategoryAttribute)attributes.FirstOrDefault(x => x is CategoryAttribute);
if (categoryAttribute != null)
{

View File

@@ -0,0 +1,54 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System.Linq;
using FlaxEditor.Scripting;
using FlaxEngine;
namespace FlaxEditor.Modules.SourceCodeEditing
{
/// <summary>
/// Source code documentation module.
/// </summary>
/// <seealso cref="FlaxEditor.Modules.EditorModule" />
public sealed class CodeDocsModule : EditorModule
{
internal CodeDocsModule(Editor editor)
: base(editor)
{
}
/// <summary>
/// Gets the tooltip text for the type.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="attributes">The type attributes. Optional, if null type attributes will be used.</param>
/// <returns>The documentation tooltip.</returns>
public string GetTooltip(ScriptType type, object[] attributes = null)
{
if (attributes == null)
attributes = type.GetAttributes(false);
var text = type.TypeName;
var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltip != null)
text += '\n' + tooltip.Text;
return text;
}
/// <summary>
/// Gets the tooltip text for the type.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="attributes">The type attributes. Optional, if null type attributes will be used.</param>
/// <returns>The documentation tooltip.</returns>
public string GetTooltip(ScriptMemberInfo type, object[] attributes = null)
{
if (attributes == null)
attributes = type.GetAttributes(true);
string text = null;
var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltip != null)
text = tooltip.Text;
return text;
}
}
}

View File

@@ -164,11 +164,7 @@ namespace FlaxEditor.Surface
node.DefaultValues[0] = Activator.CreateInstance(scriptType.Type);
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
node.Title = scriptTypeName;
node.Description = scriptTypeTypeName;
var attributes = scriptType.GetAttributes(false);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
node.Description += "\n" + tooltipAttribute.Text;
node.Description = Editor.Instance.CodeDocs.GetTooltip(scriptType);
// Create group archetype
var groupKey = new KeyValuePair<string, ushort>(scriptTypeName, 2);
@@ -211,17 +207,14 @@ namespace FlaxEditor.Surface
_cache.Add(groupKey, group);
}
var attributes = scriptType.GetAttributes(false);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
var tooltip = Editor.Instance.CodeDocs.GetTooltip(scriptType);
// Create Pack node archetype
var node = (NodeArchetype)Archetypes.Packing.Nodes[6].Clone();
node.DefaultValues[0] = scriptTypeTypeName;
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
node.Title = "Pack " + scriptTypeName;
node.Description = scriptTypeTypeName;
if (tooltipAttribute != null)
node.Description += "\n" + tooltipAttribute.Text;
node.Description = tooltip;
((IList<NodeArchetype>)group.Archetypes).Add(node);
// Create Unpack node archetype
@@ -229,9 +222,7 @@ namespace FlaxEditor.Surface
node.DefaultValues[0] = scriptTypeTypeName;
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
node.Title = "Unpack " + scriptTypeName;
node.Description = scriptTypeTypeName;
if (tooltipAttribute != null)
node.Description += "\n" + tooltipAttribute.Text;
node.Description = tooltip;
((IList<NodeArchetype>)group.Archetypes).Add(node);
}
}

View File

@@ -537,10 +537,7 @@ namespace FlaxEditor.Surface.Archetypes
if (methodInfo)
{
// Update tooltip
var attributes = methodInfo.GetAttributes(true);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
TooltipText = tooltipAttribute.Text;
TooltipText = Editor.Instance.CodeDocs.GetTooltip(methodInfo);
// Generate signature from the method info
MakeBox(0, string.Empty, typeof(void), true);

View File

@@ -437,12 +437,7 @@ namespace FlaxEditor.Surface
sb.Append("static ");
else if (type.IsAbstract)
sb.Append("abstract ");
sb.Append(type.TypeName);
var attributes = type.GetAttributes(false);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
sb.Append("\n").Append(tooltipAttribute.Text);
sb.Append(Editor.Instance.CodeDocs.GetTooltip(type));
return sb.ToString();
}
@@ -502,10 +497,9 @@ namespace FlaxEditor.Surface
}
// Tooltip
var attributes = member.GetAttributes();
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
sb.Append("\n").Append(tooltipAttribute.Text);
var tooltip = Editor.Instance.CodeDocs.GetTooltip(member);
if (!string.IsNullOrEmpty(tooltip))
sb.Append("\n").Append(tooltip);
return sb.ToString();
}

View File

@@ -132,11 +132,7 @@ namespace FlaxEditor.Surface
node.DefaultValues[0] = Activator.CreateInstance(scriptType.Type);
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
node.Title = scriptTypeName;
node.Description = scriptTypeTypeName;
var attributes = scriptType.GetAttributes(false);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
node.Description += "\n" + tooltipAttribute.Text;
node.Description = Editor.Instance.CodeDocs.GetTooltip(scriptType);
// Create group archetype
var groupKey = new KeyValuePair<string, ushort>(scriptTypeName, 2);
@@ -179,17 +175,14 @@ namespace FlaxEditor.Surface
_cache.Add(groupKey, group);
}
var attributes = scriptType.GetAttributes(false);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
var tooltip = Editor.Instance.CodeDocs.GetTooltip(scriptType);
// Create Pack node archetype
var node = (NodeArchetype)Archetypes.Packing.Nodes[6].Clone();
node.DefaultValues[0] = scriptTypeTypeName;
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
node.Title = "Pack " + scriptTypeName;
node.Description = scriptTypeTypeName;
if (tooltipAttribute != null)
node.Description += "\n" + tooltipAttribute.Text;
node.Description = tooltip;
((IList<NodeArchetype>)group.Archetypes).Add(node);
// Create Unpack node archetype
@@ -197,9 +190,7 @@ namespace FlaxEditor.Surface
node.DefaultValues[0] = scriptTypeTypeName;
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
node.Title = "Unpack " + scriptTypeName;
node.Description = scriptTypeTypeName;
if (tooltipAttribute != null)
node.Description += "\n" + tooltipAttribute.Text;
node.Description = tooltip;
((IList<NodeArchetype>)group.Archetypes).Add(node);
}
@@ -580,10 +571,7 @@ namespace FlaxEditor.Surface
var node = (NodeArchetype)Archetypes.Function.Nodes[2].Clone();
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
var attributes = member.GetAttributes(true);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
node.Description = tooltipAttribute.Text;
node.Description = Editor.Instance.CodeDocs.GetTooltip(member);
node.DefaultValues[0] = name;
node.DefaultValues[1] = parameters.Length;
node.Title = "Override " + name;

View File

@@ -447,10 +447,7 @@ namespace FlaxEditor.Windows.Assets
continue;
var cmButton = cm.AddButton($"{name} (in {member.DeclaringType.Name})");
var attributes = member.GetAttributes(true);
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
if (tooltipAttribute != null)
cmButton.TooltipText = tooltipAttribute.Text;
cmButton.TooltipText = Editor.Instance.CodeDocs.GetTooltip(member);
cmButton.Clicked += () =>
{
var surface = ((VisualScriptWindow)Values[0]).Surface;