light edit: simplify main menu action group customization (IDEA-231946)

This partially reverts e7372e579072a725a47a432a86f303fba5a470d1. Now, when LightEditMenuBar (extending IdeMenuBar) is dropped, IdeMenuBar should be inherited by an implementation with OS-specific customization.

GitOrigin-RevId: 043486e8edc9d0ec204047c0641b853b5e595ebe
This commit is contained in:
Sergey Simonchik
2020-08-18 10:41:39 +00:00
committed by intellij-monorepo-bot
parent 3bfc5734e1
commit 8c32ff37e4
7 changed files with 23 additions and 25 deletions
@@ -2,12 +2,13 @@
package com.intellij.ide.lightEdit;
import com.intellij.diagnostic.IdeMessagePanel;
import com.intellij.ide.lightEdit.menuBar.LightEditMenuBar;
import com.intellij.ide.lightEdit.menuBar.LightEditMainMenuHelper;
import com.intellij.ide.lightEdit.statusBar.LightEditAutosaveWidget;
import com.intellij.ide.lightEdit.statusBar.LightEditEncodingWidgetWrapper;
import com.intellij.ide.lightEdit.statusBar.LightEditLineSeparatorWidgetWrapper;
import com.intellij.ide.lightEdit.statusBar.LightEditPositionWidget;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
@@ -111,8 +112,8 @@ final class LightEditFrameWrapper extends ProjectFrameHelper implements Disposab
}
@Override
protected @NotNull IdeMenuBar createMenuBar() {
return new LightEditMenuBar();
protected @Nullable ActionGroup getMainMenuActionGroup() {
return new LightEditMainMenuHelper().getMainMenuActionGroup();
}
@NotNull
@@ -11,8 +11,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
public final class LightEditMenuBar extends IdeMenuBar {
@Override
public final class LightEditMainMenuHelper {
public @NotNull ActionGroup getMainMenuActionGroup() {
DefaultActionGroup topGroup = new DefaultActionGroup();
topGroup.add(
@@ -23,6 +23,7 @@ import com.intellij.ui.ColorUtil;
import com.intellij.ui.Gray;
import com.intellij.ui.ScreenUtil;
import com.intellij.ui.mac.foundation.NSDefaults;
import com.intellij.util.ObjectUtils;
import com.intellij.util.concurrency.NonUrgentExecutor;
import com.intellij.util.ui.*;
import org.jetbrains.annotations.NotNull;
@@ -447,8 +448,12 @@ public class IdeMenuBar extends JMenuBar implements IdeEventQueue.EventDispatche
}
}
@Nullable
public ActionGroup getMainMenuActionGroup() {
public @Nullable ActionGroup getMainMenuActionGroup() {
IdeRootPane rootPane = ObjectUtils.tryCast(getRootPane(), IdeRootPane.class);
ActionGroup group = rootPane != null ? rootPane.getMainMenuActionGroup() : null;
if (group != null) {
return group;
}
return (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_MENU);
}
@@ -77,7 +77,7 @@ public class IdeRootPane extends JRootPane implements UISettingsListener {
myContentPane.addMouseMotionListener(new MouseMotionAdapter() {
});
IdeMenuBar menu = createMenuBar();
IdeMenuBar menu = IdeMenuBar.createMenuBar();
myDecoratedMenu = IdeFrameDecorator.isCustomDecorationActive();
if (!isDecoratedMenu() && !FrameInfoHelper.isFloatingMenuBarSupported()) {
@@ -87,7 +87,7 @@ public class IdeRootPane extends JRootPane implements UISettingsListener {
if (isDecoratedMenu()) {
JdkEx.setHasCustomDecoration(frame);
myCustomFrameTitlePane = CustomHeader.createMainFrameHeader(frame, menu);
myCustomFrameTitlePane = CustomHeader.createMainFrameHeader(frame);
getLayeredPane().add(myCustomFrameTitlePane, JLayeredPane.DEFAULT_LAYER - 2);
menu.setVisible(false);
}
@@ -117,10 +117,6 @@ public class IdeRootPane extends JRootPane implements UISettingsListener {
myContentPane.add(getCenterComponent(frame, parentDisposable), BorderLayout.CENTER);
}
protected @NotNull IdeMenuBar createMenuBar() {
return IdeMenuBar.createMenuBar();
}
protected @NotNull Component getCenterComponent(@NotNull JFrame frame, @NotNull Disposable parentDisposable) {
myToolWindowsPane = new ToolWindowsPane(frame, parentDisposable);
return myToolWindowsPane;
@@ -233,6 +229,10 @@ public class IdeRootPane extends JRootPane implements UISettingsListener {
}
}
protected @Nullable ActionGroup getMainMenuActionGroup() {
return null;
}
private static @NotNull JComponent createToolbar() {
ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
@@ -72,7 +72,7 @@ abstract class CustomHeader(private val window: Window) : JPanel(), Disposable {
fun create(window: Window): CustomHeader {
return if (window is JFrame) {
if(window.rootPane is IdeRootPane) {
createMainFrameHeader(window, null)
createMainFrameHeader(window)
} else {
createFrameHeader(window)
}
@@ -87,7 +87,7 @@ abstract class CustomHeader(private val window: Window) : JPanel(), Disposable {
} ?: DefaultFrameHeader(frame)
}
@JvmStatic
fun createMainFrameHeader(frame: JFrame, delegatingMenuBar: IdeMenuBar?): MainFrameHeader = MainFrameHeader(frame, delegatingMenuBar)
fun createMainFrameHeader(frame: JFrame): MainFrameHeader = MainFrameHeader(frame)
private val windowBorderThicknessInPhysicalPx: Int = run {
// Windows 10 (tested on 1809) determines the window border size by the main display scaling, rounded down. This value is
@@ -8,7 +8,7 @@ import com.intellij.util.ui.JBUI
import java.awt.Graphics
import javax.swing.border.Border
class CustomHeaderMenuBar(private val delegatingMenuBar: IdeMenuBar?) : IdeMenuBar() {
class CustomHeaderMenuBar : IdeMenuBar() {
init {
isOpaque = false
}
@@ -27,11 +27,4 @@ class CustomHeaderMenuBar(private val delegatingMenuBar: IdeMenuBar?) : IdeMenuB
return actionMenu
}
override fun getMainMenuActionGroup(): ActionGroup? {
if (delegatingMenuBar != null) {
return delegatingMenuBar.mainMenuActionGroup
}
return super.getMainMenuActionGroup()
}
}
@@ -18,7 +18,7 @@ import java.util.*
import javax.swing.*
import javax.swing.event.ChangeListener
class MainFrameHeader(frame: JFrame, menuBar: IdeMenuBar?) : FrameHeader(frame){
class MainFrameHeader(frame: JFrame) : FrameHeader(frame){
private val mySelectedEditorFilePath: CustomDecorationPath
private val myIdeMenu: IdeMenuBar
private val menuHolder: JComponent
@@ -35,7 +35,7 @@ class MainFrameHeader(frame: JFrame, menuBar: IdeMenuBar?) : FrameHeader(frame){
productIcon.border = empty
add(productIcon)
myIdeMenu = CustomHeaderMenuBar(menuBar)
myIdeMenu = CustomHeaderMenuBar()
changeListener = ChangeListener {
updateCustomDecorationHitTestSpots()