api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

UI.menu(): non persistent menu object (Windows only)

Open Fredosixx opened this issue 4 years ago • 4 comments
trafficstars

By chance, I notice a strange behavior with menus on Windows (all SU versions).

In short Sketchup::Menu objects returned by UI.menu() or by creating a submenu via add_submenu have a limited scope and cannot be reused later on.

Consider the following code

module TestMenu
  @menu = UI.menu("Plugins").add_submenu('My Submenu')
  @menu.add_menu('Menu item at load') {}
	
  def self.create_menu
    @menu.add_item("MyMenu 2") {}
  end	
end

When loaded, the menu entry Menu item at load will be created. HOWEVER, calling TestMenu.create_menu will not create a menu entry.

You can also test this issue in the Ruby Console, even with the main menu.

  1. UI.menu("Plugins").add_item('menu 1') {} will create a menu item
  2. m = UI.menu("Plugins") ; m.add_item('menu 1') {} will create a menu item
  3. m = UI.menu("Plugins"), and then m.add_item('menu 1') {} will NOT create a menu item

Note that this works fine on Mac.

Fredosixx avatar Jun 12 '21 14:06 Fredosixx

By chance, I notice a strange behavior with menus on Windows (all SU versions).

In short Sketchup::Menu objects returned by UI.menu() or by creating a submenu via add_submenu have a limited scope and cannot be reused later on.

We (MS Windows coders) have always known about this, ... and have often complained about it.

You can later on call UI::menu and receive a new reference to a "top level" menu.

But calling Menu#add_submenu with an existing submenu name just creates another same-named submenu instead of returning the a reference to the existing submenu.

This has been a great frustration over the years !

@thomthom, has this already been logged as a FR and how long ago ?

Note that this works fine on Mac.

This I did not know ! This fact would make this a platform parity issue.

DanRathbun avatar Jun 12 '21 16:06 DanRathbun

In short Sketchup::Menu objects returned by UI.menu() or by creating a submenu via add_submenu have a limited scope and cannot be reused later on.

Yes. It's bug in the SketchUp menu handling code on Windows. We were looking into this last week.

thomthom avatar Jun 14 '21 08:06 thomthom

Logged as: SKEXT-3109

sketchupbot avatar Jun 17 '21 11:06 sketchupbot

Has a workaround for this ever been created?

The examples tutorials mention putting all the functions into 1 submenu, but doesn't actually explain how to do so!

Best method I found was to create a $submenu global variable submenu in load_tutorials.rb, then replace the menu.add_item with submenu.add_item in every example file.

Ben-Garcia-DB-Solutions avatar Oct 23 '23 09:10 Ben-Garcia-DB-Solutions