api-issue-tracker
api-issue-tracker copied to clipboard
UI.menu(): non persistent menu object (Windows only)
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.
UI.menu("Plugins").add_item('menu 1') {}will create a menu itemm = UI.menu("Plugins") ; m.add_item('menu 1') {}will create a menu itemm = UI.menu("Plugins"), and thenm.add_item('menu 1') {}will NOT create a menu item
Note that this works fine on Mac.
By chance, I notice a strange behavior with menus on Windows (all SU versions).
In short
Sketchup::Menuobjects returned byUI.menu()or by creating a submenu viaadd_submenuhave 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.
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.
Logged as: SKEXT-3109
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.