Add Code Docs module for Editor tooltips
This commit is contained in:
@@ -625,11 +625,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
group.Panel.Open(false);
|
group.Panel.Open(false);
|
||||||
|
|
||||||
// Customize
|
// Customize
|
||||||
var typeAttributes = scriptType.GetAttributes(false);
|
group.Panel.TooltipText = Editor.Instance.CodeDocs.GetTooltip(scriptType);
|
||||||
group.Panel.TooltipText = scriptType.TypeName;
|
|
||||||
var tooltip = (TooltipAttribute)typeAttributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltip != null)
|
|
||||||
group.Panel.TooltipText += '\n' + tooltip.Text;
|
|
||||||
if (script.HasPrefabLink)
|
if (script.HasPrefabLink)
|
||||||
group.Panel.HeaderTextColor = FlaxEngine.GUI.Style.Current.ProgressNormal;
|
group.Panel.HeaderTextColor = FlaxEngine.GUI.Style.Current.ProgressNormal;
|
||||||
|
|
||||||
|
|||||||
@@ -142,10 +142,15 @@ namespace FlaxEditor
|
|||||||
public readonly ContentFindingModule ContentFinding;
|
public readonly ContentFindingModule ContentFinding;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The content editing
|
/// The scripts editing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly CodeEditingModule CodeEditing;
|
public readonly CodeEditingModule CodeEditing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The scripts documentation
|
||||||
|
/// </summary>
|
||||||
|
public readonly CodeDocsModule CodeDocs;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The editor state machine.
|
/// The editor state machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -237,6 +242,7 @@ namespace FlaxEditor
|
|||||||
RegisterModule(ContentDatabase = new ContentDatabaseModule(this));
|
RegisterModule(ContentDatabase = new ContentDatabaseModule(this));
|
||||||
RegisterModule(ContentImporting = new ContentImportingModule(this));
|
RegisterModule(ContentImporting = new ContentImportingModule(this));
|
||||||
RegisterModule(CodeEditing = new CodeEditingModule(this));
|
RegisterModule(CodeEditing = new CodeEditingModule(this));
|
||||||
|
RegisterModule(CodeDocs = new CodeDocsModule(this));
|
||||||
RegisterModule(ProgressReporting = new ProgressReportingModule(this));
|
RegisterModule(ProgressReporting = new ProgressReportingModule(this));
|
||||||
RegisterModule(ContentFinding = new ContentFindingModule(this));
|
RegisterModule(ContentFinding = new ContentFindingModule(this));
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using FlaxEditor.CustomEditors;
|
using FlaxEditor.CustomEditors;
|
||||||
using FlaxEditor.CustomEditors.Elements;
|
using FlaxEditor.CustomEditors.Elements;
|
||||||
|
using FlaxEditor.Scripting;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
|
|
||||||
namespace FlaxEditor.GUI
|
namespace FlaxEditor.GUI
|
||||||
@@ -245,7 +246,7 @@ namespace FlaxEditor.GUI
|
|||||||
if (field.Name.Equals("value__", StringComparison.Ordinal))
|
if (field.Name.Equals("value__", StringComparison.Ordinal))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var attributes = (Attribute[])field.GetCustomAttributes();
|
var attributes = field.GetCustomAttributes(false);
|
||||||
if (attributes.Any(x => x is HideInEditorAttribute))
|
if (attributes.Any(x => x is HideInEditorAttribute))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -269,12 +270,7 @@ namespace FlaxEditor.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string tooltip = null;
|
string tooltip = Editor.Instance.CodeDocs.GetTooltip(new ScriptMemberInfo(field), attributes);
|
||||||
var tooltipAttr = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttr != null)
|
|
||||||
{
|
|
||||||
tooltip = tooltipAttr.Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
entries.Add(new Entry(name, Convert.ToInt64(field.GetRawConstantValue()), tooltip));
|
entries.Add(new Entry(name, Convert.ToInt64(field.GetRawConstantValue()), tooltip));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,14 +46,8 @@ namespace FlaxEditor.GUI
|
|||||||
_type = type;
|
_type = type;
|
||||||
|
|
||||||
Name = type.Name;
|
Name = type.Name;
|
||||||
TooltipText = type.TypeName;
|
TooltipText = Editor.Instance.CodeDocs.GetTooltip(type, attributes);
|
||||||
Tag = type;
|
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);
|
var categoryAttribute = (CategoryAttribute)attributes.FirstOrDefault(x => x is CategoryAttribute);
|
||||||
if (categoryAttribute != null)
|
if (categoryAttribute != null)
|
||||||
{
|
{
|
||||||
|
|||||||
54
Source/Editor/Modules/SourceCodeEditing/CodeDocsModule.cs
Normal file
54
Source/Editor/Modules/SourceCodeEditing/CodeDocsModule.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -164,11 +164,7 @@ namespace FlaxEditor.Surface
|
|||||||
node.DefaultValues[0] = Activator.CreateInstance(scriptType.Type);
|
node.DefaultValues[0] = Activator.CreateInstance(scriptType.Type);
|
||||||
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
||||||
node.Title = scriptTypeName;
|
node.Title = scriptTypeName;
|
||||||
node.Description = scriptTypeTypeName;
|
node.Description = Editor.Instance.CodeDocs.GetTooltip(scriptType);
|
||||||
var attributes = scriptType.GetAttributes(false);
|
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
node.Description += "\n" + tooltipAttribute.Text;
|
|
||||||
|
|
||||||
// Create group archetype
|
// Create group archetype
|
||||||
var groupKey = new KeyValuePair<string, ushort>(scriptTypeName, 2);
|
var groupKey = new KeyValuePair<string, ushort>(scriptTypeName, 2);
|
||||||
@@ -211,17 +207,14 @@ namespace FlaxEditor.Surface
|
|||||||
_cache.Add(groupKey, group);
|
_cache.Add(groupKey, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
var attributes = scriptType.GetAttributes(false);
|
var tooltip = Editor.Instance.CodeDocs.GetTooltip(scriptType);
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
|
|
||||||
// Create Pack node archetype
|
// Create Pack node archetype
|
||||||
var node = (NodeArchetype)Archetypes.Packing.Nodes[6].Clone();
|
var node = (NodeArchetype)Archetypes.Packing.Nodes[6].Clone();
|
||||||
node.DefaultValues[0] = scriptTypeTypeName;
|
node.DefaultValues[0] = scriptTypeTypeName;
|
||||||
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
||||||
node.Title = "Pack " + scriptTypeName;
|
node.Title = "Pack " + scriptTypeName;
|
||||||
node.Description = scriptTypeTypeName;
|
node.Description = tooltip;
|
||||||
if (tooltipAttribute != null)
|
|
||||||
node.Description += "\n" + tooltipAttribute.Text;
|
|
||||||
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
||||||
|
|
||||||
// Create Unpack node archetype
|
// Create Unpack node archetype
|
||||||
@@ -229,9 +222,7 @@ namespace FlaxEditor.Surface
|
|||||||
node.DefaultValues[0] = scriptTypeTypeName;
|
node.DefaultValues[0] = scriptTypeTypeName;
|
||||||
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
||||||
node.Title = "Unpack " + scriptTypeName;
|
node.Title = "Unpack " + scriptTypeName;
|
||||||
node.Description = scriptTypeTypeName;
|
node.Description = tooltip;
|
||||||
if (tooltipAttribute != null)
|
|
||||||
node.Description += "\n" + tooltipAttribute.Text;
|
|
||||||
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -537,10 +537,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
if (methodInfo)
|
if (methodInfo)
|
||||||
{
|
{
|
||||||
// Update tooltip
|
// Update tooltip
|
||||||
var attributes = methodInfo.GetAttributes(true);
|
TooltipText = Editor.Instance.CodeDocs.GetTooltip(methodInfo);
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
TooltipText = tooltipAttribute.Text;
|
|
||||||
|
|
||||||
// Generate signature from the method info
|
// Generate signature from the method info
|
||||||
MakeBox(0, string.Empty, typeof(void), true);
|
MakeBox(0, string.Empty, typeof(void), true);
|
||||||
|
|||||||
@@ -437,12 +437,7 @@ namespace FlaxEditor.Surface
|
|||||||
sb.Append("static ");
|
sb.Append("static ");
|
||||||
else if (type.IsAbstract)
|
else if (type.IsAbstract)
|
||||||
sb.Append("abstract ");
|
sb.Append("abstract ");
|
||||||
sb.Append(type.TypeName);
|
sb.Append(Editor.Instance.CodeDocs.GetTooltip(type));
|
||||||
|
|
||||||
var attributes = type.GetAttributes(false);
|
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
sb.Append("\n").Append(tooltipAttribute.Text);
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,10 +497,9 @@ namespace FlaxEditor.Surface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tooltip
|
// Tooltip
|
||||||
var attributes = member.GetAttributes();
|
var tooltip = Editor.Instance.CodeDocs.GetTooltip(member);
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
if (!string.IsNullOrEmpty(tooltip))
|
||||||
if (tooltipAttribute != null)
|
sb.Append("\n").Append(tooltip);
|
||||||
sb.Append("\n").Append(tooltipAttribute.Text);
|
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,11 +132,7 @@ namespace FlaxEditor.Surface
|
|||||||
node.DefaultValues[0] = Activator.CreateInstance(scriptType.Type);
|
node.DefaultValues[0] = Activator.CreateInstance(scriptType.Type);
|
||||||
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
||||||
node.Title = scriptTypeName;
|
node.Title = scriptTypeName;
|
||||||
node.Description = scriptTypeTypeName;
|
node.Description = Editor.Instance.CodeDocs.GetTooltip(scriptType);
|
||||||
var attributes = scriptType.GetAttributes(false);
|
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
node.Description += "\n" + tooltipAttribute.Text;
|
|
||||||
|
|
||||||
// Create group archetype
|
// Create group archetype
|
||||||
var groupKey = new KeyValuePair<string, ushort>(scriptTypeName, 2);
|
var groupKey = new KeyValuePair<string, ushort>(scriptTypeName, 2);
|
||||||
@@ -179,17 +175,14 @@ namespace FlaxEditor.Surface
|
|||||||
_cache.Add(groupKey, group);
|
_cache.Add(groupKey, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
var attributes = scriptType.GetAttributes(false);
|
var tooltip = Editor.Instance.CodeDocs.GetTooltip(scriptType);
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
|
|
||||||
// Create Pack node archetype
|
// Create Pack node archetype
|
||||||
var node = (NodeArchetype)Archetypes.Packing.Nodes[6].Clone();
|
var node = (NodeArchetype)Archetypes.Packing.Nodes[6].Clone();
|
||||||
node.DefaultValues[0] = scriptTypeTypeName;
|
node.DefaultValues[0] = scriptTypeTypeName;
|
||||||
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
||||||
node.Title = "Pack " + scriptTypeName;
|
node.Title = "Pack " + scriptTypeName;
|
||||||
node.Description = scriptTypeTypeName;
|
node.Description = tooltip;
|
||||||
if (tooltipAttribute != null)
|
|
||||||
node.Description += "\n" + tooltipAttribute.Text;
|
|
||||||
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
||||||
|
|
||||||
// Create Unpack node archetype
|
// Create Unpack node archetype
|
||||||
@@ -197,9 +190,7 @@ namespace FlaxEditor.Surface
|
|||||||
node.DefaultValues[0] = scriptTypeTypeName;
|
node.DefaultValues[0] = scriptTypeTypeName;
|
||||||
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
||||||
node.Title = "Unpack " + scriptTypeName;
|
node.Title = "Unpack " + scriptTypeName;
|
||||||
node.Description = scriptTypeTypeName;
|
node.Description = tooltip;
|
||||||
if (tooltipAttribute != null)
|
|
||||||
node.Description += "\n" + tooltipAttribute.Text;
|
|
||||||
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
((IList<NodeArchetype>)group.Archetypes).Add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,10 +571,7 @@ namespace FlaxEditor.Surface
|
|||||||
|
|
||||||
var node = (NodeArchetype)Archetypes.Function.Nodes[2].Clone();
|
var node = (NodeArchetype)Archetypes.Function.Nodes[2].Clone();
|
||||||
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
node.Flags &= ~NodeFlags.NoSpawnViaGUI;
|
||||||
var attributes = member.GetAttributes(true);
|
node.Description = Editor.Instance.CodeDocs.GetTooltip(member);
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
node.Description = tooltipAttribute.Text;
|
|
||||||
node.DefaultValues[0] = name;
|
node.DefaultValues[0] = name;
|
||||||
node.DefaultValues[1] = parameters.Length;
|
node.DefaultValues[1] = parameters.Length;
|
||||||
node.Title = "Override " + name;
|
node.Title = "Override " + name;
|
||||||
|
|||||||
@@ -447,10 +447,7 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var cmButton = cm.AddButton($"{name} (in {member.DeclaringType.Name})");
|
var cmButton = cm.AddButton($"{name} (in {member.DeclaringType.Name})");
|
||||||
var attributes = member.GetAttributes(true);
|
cmButton.TooltipText = Editor.Instance.CodeDocs.GetTooltip(member);
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
cmButton.TooltipText = tooltipAttribute.Text;
|
|
||||||
cmButton.Clicked += () =>
|
cmButton.Clicked += () =>
|
||||||
{
|
{
|
||||||
var surface = ((VisualScriptWindow)Values[0]).Surface;
|
var surface = ((VisualScriptWindow)Values[0]).Surface;
|
||||||
|
|||||||
Reference in New Issue
Block a user