using System;
using UnityEngine;
namespace UnityEditor.Timeline.Actions
{
///
/// Use this attribute to add a menu item to a context menu.
/// Used to indicate path and priority that are auto added to the menu
/// (examples can be found on ).
///
///
///
///
///
/// Unlike Menu item, MenuEntryAttribute doesn't handle shortcuts in the menu name. See .
///
[AttributeUsage(AttributeTargets.Class)]
public class MenuEntryAttribute : Attribute
{
internal readonly int priority;
internal readonly string name;
internal readonly string subMenuPath;
///
/// Constructor for Menu Entry Attribute to define information about the menu item for an action.
///
/// Path to the menu. If there is a "/" in the path, it will create one (or multiple) submenu items.
/// Priority to decide where the menu will be positioned in the menu.
/// The lower the priority, the higher the menu item will be in the context menu.
///
///
public MenuEntryAttribute(string path = default, int priority = MenuPriority.defaultPriority)
{
path = path ?? string.Empty;
path = L10n.Tr(path);
this.priority = priority;
var index = path.LastIndexOf('/');
if (index >= 0)
{
name = (index == path.Length - 1) ? string.Empty : path.Substring(index + 1);
subMenuPath = path.Substring(0, index + 1);
}
else
{
name = path;
subMenuPath = string.Empty;
}
}
}
}