diff --git a/RuntimeUnityEditor.Bepin5/PatchInspector/PatchInspector.cs b/RuntimeUnityEditor.Bepin5/PatchInspector/PatchInspector.cs
index 4afbf50..661a050 100644
--- a/RuntimeUnityEditor.Bepin5/PatchInspector/PatchInspector.cs
+++ b/RuntimeUnityEditor.Bepin5/PatchInspector/PatchInspector.cs
@@ -40,6 +40,11 @@ protected override void Initialize(InitSettings initSettings)
DefaultScreenPosition = ScreenPartition.LeftUpper;
DisplayName = "Patch Inspector";
Title = "Harmony Patch Inspector";
+
+ ContextMenu.MenuContents.Add(new ContextMenuEntry((GUIContent)null, (o, info) => info != null, null));
+ ContextMenu.MenuContents.Add(new ContextMenuEntry("Manage harmony patches", (o, info) => info is MethodBase, (o, info, name) => OpenILViewer((MethodBase)info)));
+ ContextMenu.MenuContents.Add(new ContextMenuEntry("Manage harmony patches (get)", (o, info) => info is PropertyInfo p && p.CanRead, (o, info, name) => OpenILViewer(((PropertyInfo)info).GetGetMethod(true))));
+ ContextMenu.MenuContents.Add(new ContextMenuEntry("Manage harmony patches (set)", (o, info) => info is PropertyInfo p && p.CanWrite, (o, info, name) => OpenILViewer(((PropertyInfo)info).GetSetMethod(true))));
}
///
diff --git a/RuntimeUnityEditor.Core/Features/ContextMenu.cs b/RuntimeUnityEditor.Core/Features/ContextMenu.cs
index dd588dc..a54b8a1 100644
--- a/RuntimeUnityEditor.Core/Features/ContextMenu.cs
+++ b/RuntimeUnityEditor.Core/Features/ContextMenu.cs
@@ -5,13 +5,10 @@
using HarmonyLib;
using RuntimeUnityEditor.Core.ChangeHistory;
using RuntimeUnityEditor.Core.Inspector.Entries;
-using RuntimeUnityEditor.Core.ObjectTree;
-using RuntimeUnityEditor.Core.ObjectView;
using RuntimeUnityEditor.Core.Utils;
using RuntimeUnityEditor.Core.Utils.Abstractions;
using RuntimeUnityEditor.Core.Utils.ObjectDumper;
using UnityEngine;
-using UnityEngine.Events;
using UnityEngine.UI;
namespace RuntimeUnityEditor.Core
@@ -47,58 +44,26 @@ public override bool Enabled
///
/// Contents of the context menu.
///
- public List MenuContents { get; } = new List();
- private List _currentContents;
+ public static List MenuContents { get; } = new List();
+ private List _currentContents;
///
protected override void Initialize(InitSettings initSettings)
{
- // TODO This mess needs a rewrite with a sane API
- MenuContents.AddRange(new[]
- {
- new MenuEntry("! Destroyed unity Object !", obj => obj is UnityEngine.Object uobj && !uobj, null),
-
- new MenuEntry("Preview", o => o != null && ObjectViewWindow.Initialized && ObjectViewWindow.Instance.CanPreview(o), o => ObjectViewWindow.Instance.SetShownObject(o, _objName)),
-
- new MenuEntry("Show event details", o => o is UnityEventBase && ObjectViewWindow.Initialized,
- o => ObjectViewWindow.Instance.SetShownObject(ReflectionUtils.GetEventDetails((UnityEventBase)o), o + " - Event details")),
-
- new MenuEntry("Find in object tree", o => o is GameObject || o is Component, o => ObjectTreeViewer.Instance.SelectAndShowObject((o as GameObject)?.transform ?? ((Component)o).transform)),
-
- new MenuEntry(),
-
- new MenuEntry("Send to inspector", o => o != null && Inspector.Inspector.Initialized, o =>
- {
- if (o is Type t)
- Inspector.Inspector.Instance.Push(new StaticStackEntry(t, _objName), true);
- else
- Inspector.Inspector.Instance.Push(new InstanceStackEntry(o, _objName), true);
- }),
-
- new MenuEntry("Send to REPL", o => o != null && REPL.ReplWindow.Initialized, o => REPL.ReplWindow.Instance.IngestObject(o)),
-
- new MenuEntry(),
- });
-
- AddBreakpointControls(MenuContents);
+ MenuContents.Insert(0, ContextMenuEntry.Create("! Destroyed unity Object !", (o, info) => !o, null));
MenuContents.AddRange(new[]
{
- new MenuEntry("Copy to clipboard", o => o != null && Clipboard.ClipboardWindow.Initialized, o =>
- {
- if (Clipboard.ClipboardWindow.Contents.LastOrDefault() != o)
- Clipboard.ClipboardWindow.Contents.Add(o);
- }),
- //todo Paste from clipboard, kind of difficult
+ ContextMenuEntry.Separator,
- new MenuEntry("Export texture...",
- o => o is Texture ||
+ new ContextMenuEntry("Export texture...",
+ (o, info) => o is Texture ||
o is Sprite ||
(o is Material m && m.mainTexture != null) ||
(o is Image i && i.mainTexture != null) ||
(o is RawImage ri && ri.mainTexture != null) ||
(o is Renderer r && (r.sharedMaterial ?? r.material) != null && (r.sharedMaterial ?? r.material).mainTexture != null),
- o =>
+ (o, info, name) =>
{
if (o is Texture t)
t.SaveTextureToFileWithDialog();
@@ -114,13 +79,13 @@ o is Sprite ||
(r.sharedMaterial ?? r.material).mainTexture.SaveTextureToFileWithDialog();
}),
- new MenuEntry("Replace texture...",
- o => o is Texture2D ||
+ new ContextMenuEntry("Replace texture...",
+ (o, info) => o is Texture2D ||
o is Texture && _setValue != null ||
o is Material ||
o is RawImage ||
(o is Renderer r && (r.sharedMaterial != null || r.material != null)),
- o =>
+ (o, info, name) =>
{
string filename = "null";
var newTex = TextureUtils.LoadTextureFromFileWithDialog(ref filename);
@@ -187,20 +152,13 @@ o is RawImage ||
}
}),
- new MenuEntry("Export mesh to .obj", o => o is Renderer r && MeshExport.CanExport(r), o => MeshExport.ExportObj((Renderer)o, false, false)),
- new MenuEntry("Export mesh to .obj (Baked)", o => o is Renderer r && MeshExport.CanExport(r), o => MeshExport.ExportObj((Renderer)o, true, false)),
- new MenuEntry("Export mesh to .obj (World)", o => o is Renderer r && MeshExport.CanExport(r), o => MeshExport.ExportObj((Renderer)o, true, true)),
+ ContextMenuEntry.Create("Export mesh to .obj", (o, info) => MeshExport.CanExport(o), (o, info, name) => MeshExport.ExportObj(o, false, false)),
+ ContextMenuEntry.Create("Export mesh to .obj (Baked)", (o, info) => MeshExport.CanExport(o), (o, info, name) => MeshExport.ExportObj(o, true, false)),
+ ContextMenuEntry.Create("Export mesh to .obj (World)", (o, info) => MeshExport.CanExport(o), (o, info, name) => MeshExport.ExportObj(o, true, true)),
- new MenuEntry("Dump object to file...", o => o != null, o => Dumper.DumpToTempFile(o, _objName)),
+ new ContextMenuEntry("Dump object to file...", (o, _) => o != null, (o, info, name) => Dumper.DumpToTempFile(o, name)),
- new MenuEntry("Destroy", o => o is UnityEngine.Object uo && uo, o => Change.Action("(ContextMenu)::UnityEngine.Object.Destroy({0})", o is Transform t ? t.gameObject : (UnityEngine.Object)o, UnityEngine.Object.Destroy)),
-
- new MenuEntry(),
-
- new MenuEntry("Find references in scene", o => o != null && ObjectViewWindow.Initialized && o.GetType().IsClass, o => ObjectTreeViewer.Instance.FindReferencesInScene(o)),
-
- new MenuEntry("Find member in dnSpy", o => DnSpyHelper.IsAvailable && _objMemberInfo != null, o => DnSpyHelper.OpenInDnSpy(_objMemberInfo)),
- new MenuEntry("Find member type in dnSpy", o => o != null && DnSpyHelper.IsAvailable, o => DnSpyHelper.OpenInDnSpy(o.GetType()))
+ ContextMenuEntry.Create("Destroy", (o, info) => o, (o, info, name) => Change.Action("(ContextMenu)::UnityEngine.Object.Destroy({0})", o is Transform t ? t.gameObject : o, UnityEngine.Object.Destroy)),
});
_windowId = base.GetHashCode();
@@ -208,42 +166,6 @@ o is RawImage ||
DisplayType = FeatureDisplayType.Hidden;
}
- private void AddBreakpointControls(List menuContents)
- {
- menuContents.AddRange(AddGroup("call", (o, info) => info as MethodBase));
- menuContents.AddRange(AddGroup("getter", (o, info) => info is PropertyInfo pi ? pi.GetGetMethod(true) : null));
- menuContents.AddRange(AddGroup("setter", (o, info) => info is PropertyInfo pi ? pi.GetSetMethod(true) : null));
- menuContents.Add(new MenuEntry());
- return;
-
- IEnumerable AddGroup(string name, Func