IDEA-319117 call menuNeedsUpdate from menuWillOpen if necessary

and also remove unnecessary fillMenu() from menuWillOpen

GitOrigin-RevId: f7bf20c03fb629c08f66da2d21eb200cfdf728ad
This commit is contained in:
Artem Bochkarev
2023-05-01 18:41:10 +07:00
committed by intellij-monorepo-bot
parent ed9122224d
commit 1d4e3aa898
5 changed files with 32 additions and 1 deletions

Binary file not shown.

View File

@@ -73,6 +73,19 @@ static bool sUpdateInProgress = false; // used only in AppKit
JNI_COCOA_EXIT();
}
- (void)menuWillOpen:(NSMenu *)menu {
if (javaPeer == nil)
return;
JNIEnv *env = getAppKitEnv();
JNI_COCOA_ENTER();
GET_MENU_CLASS();
DECLARE_METHOD(jm_Menu_menuWillOpen, sjc_Menu, "menuWillOpen", "()V");
(*env)->CallVoidMethod(env, javaPeer, jm_Menu_menuWillOpen);
CHECK_EXCEPTION(env);
JNI_COCOA_EXIT();
}
- (void)menuDidClose:(NSMenu *)menu {
if (javaPeer == nil)
return;

View File

@@ -95,6 +95,9 @@ public class Menu extends MenuItem {
public void setTitle(String label) {
ensureNativePeer();
if (label == null)
label = "";
myTitle = label;
nativeSetTitle(nativePeer, label, isInHierarchy);
}
@@ -243,6 +246,18 @@ public class Menu extends MenuItem {
}
}
public void menuWillOpen() {
// Called on AppKit when menu opening
if (!myIsOpened) {
// When user opens some menu at second time (without focus lost) apple doesn't call menuNeedsUpdate for
// this menu (but always calls menuWillOpen) and for all submenus. It causes problems like IDEA-319117.
// So detect this case and call menuNeedsUpdate() "manually".
// NOTE: unfortunately modifying menu here can cause unstable behaviour, see IDEA-315910.
Logger.getInstance(Menu.class).debug("menuNeedsUpdate wasn't called for '" + myTitle + "', will do it now");
menuNeedsUpdate();
}
}
public void invokeMenuClosing() {
// Called on AppKit when menu closed
myIsOpened = false;

View File

@@ -23,6 +23,7 @@ public class MenuItem implements Disposable, PropertyChangeListener {
Runnable actionDelegate;
boolean isInHierarchy = false;
Presentation presentation;
String myTitle; // used for logging and debug
public MenuItem() {}
@@ -80,12 +81,14 @@ public class MenuItem implements Disposable, PropertyChangeListener {
keyChar = 0;
}
myTitle = label;
nativeSetTitleAndAccelerator(nativePeer, label, keyChar, keyCode, modifiers, isInHierarchy);
}
public void setLabel(String label) {
ensureNativePeer();
if (label == null) label = "";
myTitle = label;
nativeSetTitle(nativePeer, label, isInHierarchy);
}

View File

@@ -105,8 +105,8 @@ public final class ActionMenu extends JBMenu {
if (Menu.isJbScreenMenuEnabled() && ActionPlaces.MAIN_MENU.equals(myPlace)) {
myScreenMenuPeer = new Menu(myPresentation.getText(enableMnemonics));
myScreenMenuPeer.setOnOpen(() -> {
// NOTE: setSelected(true) calls fillMenu internally
setSelected(true);
fillMenu();
}, this);
myScreenMenuPeer.setOnClose(() -> setSelected(false), this);
myScreenMenuPeer.listenPresentationChanges(myPresentation);