Hearthstone-Deck-Tracker icon indicating copy to clipboard operation
Hearthstone-Deck-Tracker copied to clipboard

Nested MenuItem of plugin disappears

Open sgkoishi opened this issue 1 year ago • 2 comments

Bug report

Expected & Actual Behavior

Mouse:

  • Click PLUGINS, TopLevel shows up.
  • Mouse over TopLevel, Second shows up.
  • Mouse over Second
    • Expected: Third shows up somewhere near Second.
    • Actual: Third shows up in the top left corner of the screen, and disappear instantly. Second also disappears, only TopLevel remains.

Keyboard:

  • Press Right Arrow Key when selecting TopLevel, Second shows up and being selected.
  • Press Right Arrow Key when selecting Second,
    • Expected: Third shows up somewhere near Second.
    • Actual: Third shows up in the top left corner of the screen, and disappear instantly. Second and TopLevel also disappears.

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.

sgkoishi avatar Aug 05 '22 21:08 sgkoishi

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?

batstyx avatar Aug 07 '22 09:08 batstyx

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; }
}

sgkoishi avatar Aug 07 '22 17:08 sgkoishi