HearthSim / Hearthstone-Deck-Tracker

A deck tracker and deck manager for Hearthstone on Windows
https://hsreplay.net/downloads/
4.65k stars 1.11k forks source link

Nested MenuItem of plugin disappears #4425

Open sgkoishi opened 2 years ago

sgkoishi commented 2 years ago

Bug report

Expected & Actual Behavior

Mouse:

Keyboard:

Corresponding plugin source:

using System;
using System.Windows.Controls;
using Hearthstone_Deck_Tracker.Plugins;

public class Plugin : IPlugin
{
    public void OnLoad() { }
    public void OnUnload() { }
    public void OnButtonPress() { }
    public void OnUpdate() { }
    public string Name => "Test Nested MenuItem";
    public string Description => "test";
    public string ButtonText => "test";
    public string Author => "test";
    public Version Version => new Version(1, 0, 0, 0);
    public MenuItem MenuItem
    {
        get
        {
            var m1 = new MenuItem { Header = "TopLevel" };
            var m2 = new MenuItem { Header = "Second" };
            m1.Items.Add(m2);
            var m3 = new MenuItem { Header = "Third" };
            m2.Items.Add(m3);
            return m1;
        }
    }
}

Log/Screenshots

No exception thrown.

batstyx commented 2 years ago

Do you get the same behaviour if you initialise the menu structure once (i.e. in the Plugin constructor or IPlugin.OnLoad) rather than rebuilding a new menu tree every time MenuItem get is called?

sgkoishi commented 2 years ago

Do you get the same behaviour if you initialise the menu structure once (i.e. in the Plugin constructor or IPlugin.OnLoad) rather than rebuilding a new menu tree every time MenuItem get is called?

Likely it's not related: The IPlugin::get_MenuItem is not called multiple times, but only once inside Hearthstone_Deck_Tracker.Plugins.PluginWrapper::Load() : bool right after the IPlugin::OnLoad. So, it only returns one instance by only being called once (unless the plugin OnLoad is called multiple times, which I guess it should expect different MenuItems in that case).


Confirmed nothing changed, the MenuItem still disappears.

using Hearthstone_Deck_Tracker.Plugins;
using System;
using System.Windows.Controls;

public class Plugin : IPlugin
{
    public void OnLoad()
    {
        this.MenuItem = new MenuItem { Header = "TopLevel" };
        var m2 = new MenuItem { Header = "Second" };
        this.MenuItem.Items.Add(m2);
        var m3 = new MenuItem { Header = "Third" };
        m2.Items.Add(m3);
    }
    public void OnUnload() { }
    public void OnButtonPress() { }
    public void OnUpdate() { }
    public string Name => "Test Nested MenuItem";
    public string Description => "test";
    public string ButtonText => "test";
    public string Author => "test";
    public Version Version => new Version(1, 0, 0, 0);
    public MenuItem MenuItem { get; private set; }
}