Dynamically add sub menu items to tray icon context menu - electron

I have a tray icon with a context menu, it has several predefined items (js array of objects)
One of the options is defined as follows
{
id: "MyItem",
label: "MyItem Label,
submenu: []
}
For some reason, when I populate the submenu with menu items, they don't appear in the tray icon context menu >>MyItem>>submenu (it remains empty), I do see the JS object being updated properly with the right values (
submenu>>items are populated with MenuItems)
I try to append them like this (but they are not reflected in the tray icon):
let MyItemElm = contextMenu.getMenuItemById("MyItem");
MyItemElm.submenu.items.push(new MenuItem(item1));
MyItemElm.submenu.items.push(new MenuItem(item2));
When I try to push the same item1/2 to the ROOT of the context menu it does work, like this:
contextMenu.insert(8, new MenuItem(item1))
contextMenu.insert(8, new MenuItem(item2))
Any ideas on what am I missing here?

solved it by using the following:
let MyItemElm = contextMenu.getMenuItemById("MyItem");
MyItemElm.submenu.insert(0, new MenuItem(item));

Related

How to get left click to work on column visibility example using the Vaadin Flow Grid example

On the Column Visibility example on https://vaadin.com/docs/latest/ds/components/grid/#column-visibility the code shows a class ColumnToggleContextMenu which isn't part of the Vaadin API however it seems to somehow adjust how the button is hooked so that it can be left clicked rather than the default right click for a context menu. With that in mind the code below will only show the context menu on a right click, I cannot get it to work like the example code. My code is:
Button showHideColumnsButton = new Button("Show/Hide Columns");
showHideColumnsButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
ContextMenu contextMenu = new ContextMenu(showHideColumnsButton);
for(Grid.Column column : grid.getColumns()) {
contextMenu.addItem(getColumnName(column), e -> showHideColumn(column));
}
I'm considering using a MenuBar instead to see if that will work but I'd prefer to figure out how to use a Button if possible as that seems more appropriate (mainly because it allows the checkbox to show if a column is visible or hidden).
In order to make the context menu to open on left click use setOpenOnClick(true):
Button showHideColumnsButton = new Button("Show/Hide Columns");
showHideColumnsButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
ContextMenu contextMenu = new ContextMenu(showHideColumnsButton);
contextMenu.setOpenOnClick(true)
for(Grid.Column column : grid.getColumns()) {
contextMenu.addItem(getColumnName(column), e -> showHideColumn(column));
}

Find the grid on which the context menu item is clicked on

I have a grid panel and i have a item context menu on it, which have sub items as well. When a user clicks on the sub menu item or context menu item, i want to know on which grid panel this context menu is on. Can i do this?
Use the add method to add the menu to the corresponding grid, and then later, you can get the grid using the up method.

mediaelement.js context menu

Could anyone point me to the code snippet where I can find the usage of context menu for mediaelement.js?
I am looking to disable the context menu that pops up when I do right click on the video and also to add/delete context menu elements.
You can edit the items which are displayed in the context menu by editing the method renderContextMenu in the file mediaelementplayer.js
Setting as follows will prevent any menu items from appearing:
var t = this,
html = '',
items=''; --> no menu items

Cannot detect Frontpage properly in Joomla 2.5 templates

I've seen in Joomla documentation the way to detect if you are in Frontpage while creating a template in Joomla 2.5. This is the code:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
}
?>
This works when you are at home page (or clicking on Home menu), but I have an slider in home page, and I link in the slider to an article which is not in any menu item in the application. When I load this article the code above returns as I were at frontpage. I guess that if I doesn't click on any menu item, $menu->getActive() doesn't change.
Any suggestion?
Thanks in advance.
You can do one thing to solve this problem. Create a hidden menu of all the article links which are linked in the sliders.By creating hidden menu the link will be initialized and $menu->getActive() will work for all the links..Hopefully it will works for you .
I wish to add to the present answer and provide some clarifications.
In order for the menu selection to be detected the page requires to be assigned to a menu item. If this is a hidden menu than the link to such a page called My Page would be:
/index.php/my-page - “my-page” is the menu title alias for this item
However, if one wants to show the correct hierarchy in the breadcrumbs for the same page, then the menu hierarchy would have to be replicated in the hidden menu.
For example if My Page is under My Articles main menu item, then in the hidden menu you should add “My Articles” item, of the type: Menu Item Alias, which is in the Systems submenu of the menu type field. The My Page item should be a sub-menu item of My Articles.
The “My Articles” menu item in the hidden menu must have a different menu alias than the same one in the main menu hence the new link to My Page would look like:
/index.php/my-articles2/my-page
To create a hidden menu, one simply creates another menu. It does not matter whether one creates a module for it or not, but if one does then one just should not assign any position to that module.

Remove menu item on Blackberry

In my Blackberry application, I have screen with few menu items (created by myself in makeMenu()).
On this screen, sometimes I should remove two of this menu items.
But menu.deleteItem() method does not work.
How i can remove menu item in application menu, without recreate new instance of screen? Is it real for already constructed menu? Or mb I should refresh menu/screen someway?
Thanx.
The menu is drawn at the point it's selected so all I do is set conditions on anything that's not static, example below:
protected void makeMenu( Menu menu, int instance ) {
menu.add(staticMenuItem);
if (condition) menu.add(dynamicMenuItem);
}

Resources