Skip to content

Commit

Permalink
Allow asynchronous creation of menus in ActionContributionItem
Browse files Browse the repository at this point in the history
Add a listener that copies and shows the resulting menu once it has been
completely populated.
  • Loading branch information
fedejeanne committed Dec 21, 2023
1 parent 11e281c commit 771d0b4
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*******************************************************************************/
package org.eclipse.jface.action;

import java.util.Arrays;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.jface.action.ExternalActionManager.IBindingManagerCallback;
Expand Down Expand Up @@ -1168,7 +1170,22 @@ private void handleShowProxy(Menu proxy) {
if (holdMenu == null) {
return;
}

// for backwards compatibility (in case the menu is NOT calculated asynchronously)
copyMenu(holdMenu, proxy);

// in case the menu is populated asynchronously by the menu creator, this listener will update it once it's complete
holdMenu.addListener(SWT.Show, evt -> {
// This one is (currently) being triggered from ContextuaLaunchAction
if (evt.data == null || evt.data != holdMenu)
return;

// remove all items in the proxy...
Arrays.stream(proxy.getItems()).forEach(Widget::dispose);

// ... and replace them with the new content
copyMenu(holdMenu, proxy);
});
}

/**
Expand Down

0 comments on commit 771d0b4

Please sign in to comment.