I am trying to get the Menu's submenu ContextMenu instance. Is there a way to get that? I actually want to add some event filters on the submenu ContextMenu.
I tried getting the ContextMenu as below.
Menu menu = new Menu("Menu");
menu.getItems().addAll(...); // Will be added dynamically
menu.setOnShown(e->{
ContextMenu contextMenu = menu.getItems().get(0).getParentPopup();
contextMenu.addEventFilter(..., ...);
});
How can I ensure that I set the event filter only once to the context menu?
Please note that the menu can be an item in MenuBar or as an item in Menu itself.
You mentioned that menu can be a MenuBar or Menu. So it depends on how deeply the menus are nested and whether getItems().get(0) could also return a MenuItem.
So the following code might be a solution to your first question:
menu.getItems().get(0).getParentMenu().getParentMenu().getParentPopup();
// or
menu.getItems().get(0).getParentMenu().getParentPopup();
// or...
Related to your second question: You have to memorise which EventHandlers have already been added, for example in a collection. Or use one of the so called convenience methods which you are already using with menu.setOnShown.
Related
Although the docs are pointing out:
The maximum number of items that can be added to the top-level browser action context menu is menus.ACTION_MENU_TOP_LEVEL_LIMIT, but you can add any number of items to submenus.
I am only able to add 1000 submenu items to the Chrome Extension context menu.
I don't want to create a UI additionally, because the context menu is really handy for my use case. The user is working in a code editor and can look up code syntax string values via the context menu and can add the value at the position of the cursor where the user right-clicked.
Do you know of such limitations or a workaround besides using an additional UI element?
Is it possible to change the context menu dynamically, once the tabulator table is already built?
I need to change the context menu according to the cell value under the mouse cursor, so if I could somehow change the context menu inside the cellMouseOver callback, that would be great.
Thanks,
Matic
Instead of specifying a menu object, what you want is a Menu Items Generator Function. The example on that page shows returning one menu if approved is false and a different menu if approved is true.
I am developing a WebExtension and as you know it is impossible to inject content script on chrome://* pages and https://chrome.google.com/webstore/*. I have a buttons in a context menu and for correct UX I would like to drop my item from context menu on such protected page.
According to the documentation I can handle click on my context menu item, but looks like no way to check the url of the page on the moment of right mouse click without trying to inject content script into every page?
As a workaround I have a code that checks url after click to the menu item.
I am new to TestComplete. I have a question and it may be something impossible or too simple. I have a toolbar containg File, Edit, View, etc. I want to get one item (eg. Edit) to mapped objects. I can get the whole toolbar only. I want to simulate a click event on Edit. How can I do this?
As a rule, TestComplete does not work with menu items as with separate objects. It works with a menu object or even only with a menu's parent object and you can specify which item to select by passing the caption of this item to the corresponding method of a menu object. For example:
objMenu.Click("Edit|Paste");
// or
parent.MainMenu("Edit|Paste");
Please find more details on how TestComplete interacts with menus in the Working With Menus help topic.
How can I hide a menu item under certain conditions in MFC?
I'm not interested in just graying it out.
Add an Update Handler for your menu item (using ON_UPDATE_COMMAND_UI).
This line should appear in your message map:
ON_UPDATE_COMMAND_UI(ID_MYMENUITEM, OnUpdateMyMenuItem)
In the handler, use this code:
void CMainFrame::OnUpdateMyMenuItem(CCmdUI *pCmdUI)
{
if (pCmdUI->m_pMenu!=NULL)
pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID, MF_BYCOMMAND);
}
Or if you are removing a single menu item use CMenu::RemoveMenu