mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Laf & HelpViewer: usability tweaks and EA-57465 NPE on double updateUI()
This commit is contained in:
@@ -31,9 +31,10 @@ import javax.swing.*;
|
||||
* @author max
|
||||
*/
|
||||
public abstract class QuickSwitchSchemeAction extends AnAction implements DumbAware {
|
||||
|
||||
protected static final Icon ourCurrentAction = AllIcons.Diff.CurrentLine;
|
||||
protected static final Icon ourNotCurrentAction = new EmptyIcon(ourCurrentAction.getIconWidth(), ourCurrentAction.getIconHeight());
|
||||
@NotNull
|
||||
protected static final Icon ourNotCurrentAction = EmptyIcon.create(ourCurrentAction.getIconWidth(), ourCurrentAction.getIconHeight());
|
||||
|
||||
protected String myActionPlace = ActionPlaces.UNKNOWN;
|
||||
|
||||
private final boolean myShowPopupWithNoActions;
|
||||
@@ -58,11 +59,12 @@ public abstract class QuickSwitchSchemeAction extends AnAction implements DumbAw
|
||||
|
||||
private void showPopup(AnActionEvent e, DefaultActionGroup group) {
|
||||
if (!myShowPopupWithNoActions && group.getChildrenCount() == 0) return;
|
||||
final ListPopup popup = JBPopupFactory.getInstance()
|
||||
.createActionGroupPopup(getPopupTitle(e),
|
||||
group,
|
||||
e.getDataContext(), getAidMethod(),
|
||||
true, myActionPlace);
|
||||
JBPopupFactory.ActionSelectionAid aid = getAidMethod();
|
||||
|
||||
ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
|
||||
getPopupTitle(e), group, e.getDataContext(),
|
||||
aid == JBPopupFactory.ActionSelectionAid.NUMBERING || aid == JBPopupFactory.ActionSelectionAid.ALPHA_NUMBERING,
|
||||
true, aid == JBPopupFactory.ActionSelectionAid.MNEMONICS, null, -1, (a) -> a.getTemplatePresentation().getIcon() != ourCurrentAction);
|
||||
|
||||
showPopup(e, popup);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.ide.ui.LafManagerListener;
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaInstaller;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
@@ -26,27 +27,41 @@ import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class QuickChangeLookAndFeel extends QuickSwitchSchemeAction {
|
||||
|
||||
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
|
||||
final LafManager manager = LafManager.getInstance();
|
||||
final UIManager.LookAndFeelInfo[] lfs = manager.getInstalledLookAndFeels();
|
||||
final UIManager.LookAndFeelInfo current = manager.getCurrentLookAndFeel();
|
||||
final LafManager lafMan = LafManager.getInstance();
|
||||
final UIManager.LookAndFeelInfo[] lfs = lafMan.getInstalledLookAndFeels();
|
||||
final UIManager.LookAndFeelInfo current = lafMan.getCurrentLookAndFeel();
|
||||
for (final UIManager.LookAndFeelInfo lf : lfs) {
|
||||
group.add(new DumbAwareAction(lf.getName(), "", lf == current ? ourCurrentAction : ourNotCurrentAction) {
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final UIManager.LookAndFeelInfo cur = manager.getCurrentLookAndFeel();
|
||||
UIManager.LookAndFeelInfo cur = lafMan.getCurrentLookAndFeel();
|
||||
if (cur == lf) return;
|
||||
boolean needUninstall = UIUtil.isUnderDarcula();
|
||||
manager.setCurrentLookAndFeel(lf);
|
||||
manager.updateUI();
|
||||
if (UIUtil.isUnderDarcula()) {
|
||||
DarculaInstaller.install();
|
||||
} else if (needUninstall) {
|
||||
DarculaInstaller.uninstall();
|
||||
boolean wasDarcula = UIUtil.isUnderDarcula();
|
||||
lafMan.setCurrentLookAndFeel(lf);
|
||||
// hack not to updateUI twice: here and in DarculaInstaller
|
||||
final AtomicBoolean updated = new AtomicBoolean(false);
|
||||
LafManagerListener listener = (s) -> updated.set(true);
|
||||
lafMan.addLafManagerListener(listener);
|
||||
try {
|
||||
if (UIUtil.isUnderDarcula()) {
|
||||
DarculaInstaller.install();
|
||||
}
|
||||
else if (wasDarcula) {
|
||||
DarculaInstaller.uninstall();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
lafMan.removeLafManagerListener(listener);
|
||||
if (!updated.get()) {
|
||||
lafMan.updateUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -760,13 +760,10 @@ public final class LafManagerImpl extends LafManager implements ApplicationCompo
|
||||
}
|
||||
|
||||
private static void updateUI(Window window) {
|
||||
if (!window.isDisplayable()) {
|
||||
return;
|
||||
}
|
||||
IJSwingUtilities.updateComponentTreeUI(window);
|
||||
Window[] children = window.getOwnedWindows();
|
||||
for (Window aChildren : children) {
|
||||
updateUI(aChildren);
|
||||
for (Window w : children) {
|
||||
IJSwingUtilities.updateComponentTreeUI(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
|
||||
/**
|
||||
@@ -28,24 +29,23 @@ import com.intellij.ui.JBColor;
|
||||
public class DarculaInstaller {
|
||||
|
||||
public static void uninstall() {
|
||||
JBColor.setDark(false);
|
||||
IconLoader.setUseDarkIcons(false);
|
||||
if (DarculaLaf.NAME.equals(EditorColorsManager.getInstance().getGlobalScheme().getName())) {
|
||||
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME);
|
||||
if (scheme != null) {
|
||||
EditorColorsManager.getInstance().setGlobalScheme(scheme);
|
||||
}
|
||||
}
|
||||
update();
|
||||
performImpl(false);
|
||||
}
|
||||
|
||||
public static void install() {
|
||||
JBColor.setDark(true);
|
||||
IconLoader.setUseDarkIcons(true);
|
||||
if (!DarculaLaf.NAME.equals(EditorColorsManager.getInstance().getGlobalScheme().getName())) {
|
||||
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getScheme(DarculaLaf.NAME);
|
||||
performImpl(true);
|
||||
}
|
||||
|
||||
private static void performImpl(boolean b) {
|
||||
JBColor.setDark(b);
|
||||
IconLoader.setUseDarkIcons(b);
|
||||
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
|
||||
EditorColorsScheme current = colorsManager.getGlobalScheme();
|
||||
if (b != ColorUtil.isDark(current.getDefaultBackground())) {
|
||||
String targetScheme = b ? DarculaLaf.NAME : EditorColorsScheme.DEFAULT_SCHEME_NAME;
|
||||
EditorColorsScheme scheme = colorsManager.getScheme(targetScheme);
|
||||
if (scheme != null) {
|
||||
EditorColorsManager.getInstance().setGlobalScheme(scheme);
|
||||
colorsManager.setGlobalScheme(scheme);
|
||||
}
|
||||
}
|
||||
update();
|
||||
|
||||
Reference in New Issue
Block a user