123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using PlasticGui;
- using System;
- using System.Reflection;
- using UnityEditor;
- using UnityEngine;
-
- namespace Unity.PlasticSCM.Editor.UI
- {
- internal static class HandleMenuItem
- {
- internal static void AddMenuItem(
- string name,
- int priority,
- Action execute,
- Func<bool> validate)
- {
- AddMenuItem(name, string.Empty, priority, execute, validate);
- }
-
- internal static void AddMenuItem(
- string name,
- string shortcut,
- int priority,
- Action execute,
- Func<bool> validate)
- {
- MethodInfo InternalAddMenuItem = MenuType.GetMethod(
- "AddMenuItem",
- BindingFlags.Static | BindingFlags.NonPublic);
-
- if (InternalAddMenuItem == null)
- {
- Debug.LogWarningFormat(
- PlasticLocalization.GetString(
- PlasticLocalization.Name.ErrorAddPlasticSCMMenuItem),
- name);
- return;
- }
-
- InternalAddMenuItem.Invoke(
- null, new object[] {
- name, shortcut, false,
- priority, execute, validate });
- }
-
- internal static void RemoveMenuItem(string name)
- {
- MethodInfo InternalRemoveMenuItem = MenuType.GetMethod(
- "RemoveMenuItem",
- BindingFlags.Static | BindingFlags.NonPublic);
-
- if (InternalRemoveMenuItem == null)
- {
- Debug.LogWarningFormat(
- PlasticLocalization.GetString(
- PlasticLocalization.Name.ErrorRemovePlasticSCMMenuItem),
- name);
- return;
- }
-
- InternalRemoveMenuItem.Invoke(
- null, new object[] { name });
- }
-
- internal static void UpdateAllMenus()
- {
- MethodInfo InternalUpdateAllMenus = EditorUtilityType.GetMethod(
- "Internal_UpdateAllMenus",
- BindingFlags.Static | BindingFlags.NonPublic);
-
- if (InternalUpdateAllMenus == null)
- {
- Debug.LogWarning(
- PlasticLocalization.GetString(
- PlasticLocalization.Name.ErrorUpdatePlasticSCMMenus));
- return;
- }
-
- InternalUpdateAllMenus.Invoke(null, null);
- }
-
- internal static bool GetEnabled(string menuPath)
- {
- return Menu.GetEnabled(menuPath);
- }
-
- static readonly Type MenuType = typeof(UnityEditor.Menu);
- static readonly Type EditorUtilityType = typeof(UnityEditor.EditorUtility);
- }
- }
|