picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.57k stars 325 forks source link

Menu bar in Dialog is always disabled on Mac OS #2330

Open UCIS opened 1 year ago

UCIS commented 1 year ago

Expected Behavior

Menu bar items and associated hotkeys work the same in Dialog windows and regular Form windows.

Actual Behavior

Menu bar items work correctly in Form windows, but are always disabled in Dialog windows. In addition it appears that (copy/paste/cut) menu bar hotkeys from the main window propagate to a Dialog window, until the menu bar is clicked once after which the hotkeys are no longer available.

This problem might be related to https://github.com/picoe/Eto/issues/936, however the menu items work correctly in the main form after closing the dialog window.

Steps to Reproduce the Problem

  1. Run test program, focus text box, press Cmd+a, Cmd+x, Cmd+v, this all works. Same for the Edit menu.
  2. Click Open dialog
  3. Focus text box, press Cmd+a, Cmd+x, Cmd+v, this all works.
  4. Click the Edit menu, items are disabled. Focus the text box again, press Cmd+a, this no longer works.
  5. Click the application menu, the "Test" item is disabled.

Code that Demonstrates the Problem

using System;
using System.IO;
using Eto.Forms;
using Foundation;

namespace TestApp.XamMac {
    class Program {
        static void Main(string[] args) {
            var app = new Application(Eto.Platforms.XamMac2);
            ((Eto.Mac.Forms.ApplicationHandler)app.Handler).AllowClosingMainForm = true;
            app.Run(new TestForm());
        }
    }

    class TestForm : Form {
        public TestForm() : base() {
            Menu = new MenuBar() { IncludeSystemItems = MenuBarSystemItems.All };
            Content = new StackLayout(
                new TextArea() { Text = "Text" },
                new Button((s, e) => (new TestForm() { Owner = this }).Show()) { Text = "Open form" },
                new Button((s, e) => (new ModalForm()).ShowModal(this)) {  Text = "Open dialog" }
            );
        }
    }

    class ModalForm : Dialog {
        public ModalForm() : base() {
            Menu = new MenuBar() { IncludeSystemItems = MenuBarSystemItems.All };
            Menu.ApplicationItems.Add(new ButtonMenuItem() { Text = "Test" });
            Content = new StackLayout(
                new TextArea() { Text = "Text" }
            );
        }
    }
}

Specifications

somelinguist commented 1 year ago

I just came across this bug as well, with the same steps to reproduce.