Files
sbox-public/engine/Sandbox.Tools/Editor/DockAttribute.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

69 lines
1.4 KiB
C#

using Sandbox;
using System;
namespace Editor
{
[AttributeUsage( AttributeTargets.Class )]
public class DockAttribute : Attribute, ITypeAttribute
{
static Dictionary<string, DockWindow> Targets = new();
static List<DockAttribute> All = new();
Type ITypeAttribute.TargetType { get; set; }
public static void RegisterWindow( string name, DockWindow b )
{
Targets[name] = b;
foreach ( var m in All.Where( x => x.Target == name ) )
{
m.Register();
}
}
void ITypeAttribute.TypeRegister()
{
All.Add( this );
Register();
}
void Register()
{
if ( !Targets.TryGetValue( Target, out var window ) )
return;
var createAction = () =>
{
var widget = EditorTypeLibrary.Create<Widget>( (this as ITypeAttribute).TargetType, new object[] { window } );
widget.WindowTitle = Name;
widget.SetWindowIcon( Icon );
widget.Name = Name;
return widget;
};
window.DockManager.RegisterDockType( Name, Icon, createAction );
}
void ITypeAttribute.TypeUnregister()
{
All.Remove( this );
if ( !Targets.TryGetValue( Target, out var window ) )
return;
window.DockManager.UnregisterDockType( Name );
}
public string Target { get; set; }
public string Name { get; set; }
public string Icon { get; set; }
public DockAttribute( string target, string name, string icon = null )
{
Target = target;
Name = name;
Icon = icon;
}
}
}