1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Added validation support for Context Menu items

This commit is contained in:
wuhao 2019-06-21 11:03:30 +08:00
parent 11365b16b9
commit 483eafdd2a

View File

@ -86,9 +86,24 @@ namespace XNodeEditor {
KeyValuePair<ContextMenu, System.Reflection.MethodInfo>[] items = GetContextMenuMethods(obj);
if (items.Length != 0) {
contextMenu.AddSeparator("");
List<ContextMenu> invalidatedEntries = new List<ContextMenu>();
foreach (var checkValidate in items) {
if (checkValidate.Key.validate && !(bool) checkValidate.Value.Invoke(obj, null))
{
invalidatedEntries.Add(checkValidate.Key);
}
}
for (int i = 0; i < items.Length; i++) {
KeyValuePair<ContextMenu, System.Reflection.MethodInfo> kvp = items[i];
contextMenu.AddItem(new GUIContent(kvp.Key.menuItem), false, () => kvp.Value.Invoke(obj, null));
if (invalidatedEntries.Contains(kvp.Key))
{
contextMenu.AddDisabledItem(new GUIContent(kvp.Key.menuItem));
}
else
{
contextMenu.AddItem(new GUIContent(kvp.Key.menuItem), false, () => kvp.Value.Invoke(obj, null));
}
}
}
}