Skip to content

Commit

Permalink
Merge pull request #76 from ZehMatt/fix-pluginmenu
Browse files Browse the repository at this point in the history
Fix Plugin menu being destroyed
  • Loading branch information
ZehMatt authored Jan 15, 2023
2 parents 216bbff + d38ea41 commit 5796a49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/Dotx64Managed/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ internal class MenuEntry
internal static UI.Menu.Id NextInternalId = 0;
internal static UI.Menu.Id MainMenu;

// Reserved menu paths that can not belong to a plugin.
private static readonly string[] PreservedMenus =
{
"Main",
"Main/Plugins",
};

internal static void Initialize()
{
Registered = new();
Expand Down Expand Up @@ -146,6 +153,10 @@ internal static void AddMenu(Plugin plugin, string path, System.Drawing.Image im
id = Native.UI.Menu.Add(parentId, entryName),
subEntry = false,
};
if (PreservedMenus.Contains(currentPath))
{
nextEntry.plugin = null;
}
Registered.Add(currentPath, nextEntry);

entry = nextEntry;
Expand All @@ -167,7 +178,10 @@ internal static void AddMenu(Plugin plugin, string path, System.Drawing.Image im
id = NextInternalId,
subEntry = true,
};

if (PreservedMenus.Contains(path))
{
nextEntry.plugin = null;
}
Registered.Add(path, nextEntry);

Handlers.Add(nextEntry.id, func);
Expand Down Expand Up @@ -216,7 +230,6 @@ internal static bool Remove(string name)
Native.UI.Menu.Remove(entry.id);

Handlers.Remove(entry.id);

Registered.Remove(name);

return true;
Expand Down
5 changes: 4 additions & 1 deletion src/Dotx64Managed/Plugins.Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ void OnPluginCreate(object sender, FileSystemEventArgs e)

if (info.PluginRootFolder)
{
RegisterPlugin(e.FullPath);
if (Directory.Exists(e.FullPath))
{
RegisterPlugin(e.FullPath);
}
}
else
{
Expand Down

0 comments on commit 5796a49

Please sign in to comment.