picoe / Eto

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

[Gtk] Enabled=false on ButtonMenuItem not working when item is not a menu #1135

Open kaesaecracker opened 6 years ago

kaesaecracker commented 6 years ago

Expected Behavior

When setting Enabled=false, I expect a ButtonMenuItem not to be clickable, especially when it is not a menu.

Actual Behavior

It is still clickable!

Steps to Reproduce the Problem

  1. Add a new ButtonMenuItem to the menu that does not have child elements
  2. set Enabled=false for that item
  3. Run that code. The item is clickable.

Code that Demonstrates the Problem

            Menu = new MenuBar
            {
                Items =
                {
                    new ButtonMenuItem
                    {
                        Text = "Disabled",
                        Enabled = false,
                        Items =
                        {
                            new ButtonMenuItem
                            {
                                Text = "Cannot see this"
                            }
                        }
                    },
                    new ButtonMenuItem
                    {
                        Text = "Disabled but clickable",
                        Enabled = false,
                        Command = new Command((s, a) => MessageBox.Show("Disabled but clickable clicked"))
                    }
                }
            };

Specifications

NETStandard.Library 2.0 Eto.Forms 2.4.1 Eto.Platform.Gtk 2.4.1 On Ubuntu 18.04

kaesaecracker commented 6 years ago

Complete runnable source: https://gist.github.com/kaesaecracker/6263ea05b71210cc4f86c77d67987eb6

cwensley commented 6 years ago

Hey @kaesaecracker, thanks for posting the issue and the repro! It is very helpful.

I'll take a look but be aware that some platforms (macOS I believe) don't let you make the top level menu items be clickable anyway, and must have a submenu.

kaesaecracker commented 6 years ago

The same problem exists with ButtonToolItems too.

Also I googled a little bit and did not find anything about not being able to do that in Gtk.

As far as I can tell, there is no logic that forces Enabled=true. The ButtonMenuItemHandler just references Control.Sensitive which in turn just runs the GtkSharp methods.

kaesaecracker commented 6 years ago

I created a small test app using GtkSharp. Sensitive=false disables the menu item properly.

kaesaecracker commented 5 years ago

Did anything change on this yet?

cwensley commented 5 years ago

Hey @kaesaecracker, no. I think your problem is that you're trying to set the Enabled property and the Command property at the same time. The Command provides the enabled state, so if you set its Enabled property instead, it should work.

cwensley commented 5 years ago

Also, if you use the ButtonMenuItem's Click event instead of a Command, that would be another option.