mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (unified code for setting app icon in debug mode)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,8 +34,8 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.ui.AppIcon.MacAppIcon;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.ImageUtil;
|
||||
@@ -65,56 +65,44 @@ import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
|
||||
*/
|
||||
public class AppUIUtil {
|
||||
private static final String VENDOR_PREFIX = "jetbrains-";
|
||||
private static final boolean DEBUG_MODE = SystemProperties.getBooleanProperty("idea.debug.mode", false);
|
||||
|
||||
public static void updateWindowIcon(@NotNull Window window) {
|
||||
window.setIconImages(getAppIconImages());
|
||||
}
|
||||
|
||||
static {
|
||||
// Forcedly set app-icon for the debug IDE on macOS.
|
||||
ApplicationInfoEx appInfo = ApplicationInfoImpl.getShadowInstance();
|
||||
if (SystemInfo.isMac && appInfo.getBuild().isSnapshot()) {
|
||||
Image bigIcon = getBigAppIcon();
|
||||
if (bigIcon != null) {
|
||||
MacAppIcon.setDockIcon(ImageUtil.toBufferedImage(bigIcon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnnecessaryFullyQualifiedName", "deprecation"})
|
||||
private static List<Image> getAppIconImages() {
|
||||
ApplicationInfoEx appInfo = ApplicationInfoImpl.getShadowInstance();
|
||||
List<Image> images = ContainerUtil.newArrayListWithCapacity(3);
|
||||
|
||||
if (SystemInfo.isUnix) {//MacOS is Unix too
|
||||
Image bigIcon = getBigAppIcon();
|
||||
if (bigIcon != null) {
|
||||
images.add(bigIcon);
|
||||
if (SystemInfo.isUnix) {
|
||||
String bigIconUrl = appInfo.getBigIconUrl();
|
||||
if (bigIconUrl != null) {
|
||||
Image bigIcon = ImageLoader.loadFromResource(bigIconUrl);
|
||||
if (bigIcon != null) {
|
||||
images.add(bigIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
images.add(com.intellij.util.ImageLoader.loadFromResource(appInfo.getIconUrl()));
|
||||
images.add(com.intellij.util.ImageLoader.loadFromResource(appInfo.getSmallIconUrl()));
|
||||
images.add(ImageLoader.loadFromResource(appInfo.getIconUrl()));
|
||||
images.add(ImageLoader.loadFromResource(appInfo.getSmallIconUrl()));
|
||||
|
||||
for (int i = 0; i < images.size(); i++) {
|
||||
Image image = images.get(i);
|
||||
if (image instanceof JBHiDPIScaledImage) {
|
||||
images.set(i, ((JBHiDPIScaledImage)image).getDelegate());
|
||||
}
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
private static Image getBigAppIcon() {
|
||||
ApplicationInfoEx appInfo = ApplicationInfoImpl.getShadowInstance();
|
||||
String bigIconUrl = appInfo.getBigIconUrl();
|
||||
if (bigIconUrl != null) {
|
||||
return ImageLoader.loadFromResource(bigIconUrl);
|
||||
if (!images.isEmpty()) {
|
||||
if (!SystemInfo.isMac) {
|
||||
window.setIconImages(images);
|
||||
}
|
||||
else if (DEBUG_MODE) {
|
||||
MacAppIcon.setDockIcon(ImageUtil.toBufferedImage(images.get(0)));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void invokeLaterIfProjectAlive(@NotNull Project project, @NotNull Runnable runnable) {
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
Application application = ApplicationManager.getApplication();
|
||||
if (application.isDispatchThread()) {
|
||||
runnable.run();
|
||||
}
|
||||
@@ -145,8 +133,8 @@ public class AppUIUtil {
|
||||
|
||||
public static void updateFrameClass() {
|
||||
try {
|
||||
final Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
final Class<? extends Toolkit> aClass = toolkit.getClass();
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
Class<? extends Toolkit> aClass = toolkit.getClass();
|
||||
if ("sun.awt.X11.XToolkit".equals(aClass.getName())) {
|
||||
ReflectionUtil.setField(aClass, toolkit, null, "awtAppClassName", getFrameClass());
|
||||
}
|
||||
@@ -157,10 +145,9 @@ public class AppUIUtil {
|
||||
public static String getFrameClass() {
|
||||
String name = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(Locale.US);
|
||||
String wmClass = VENDOR_PREFIX + name.replace(' ', '-');
|
||||
if ("true".equals(System.getProperty("idea.debug.mode"))) {
|
||||
wmClass += "-debug";
|
||||
}
|
||||
return PlatformUtils.isCommunityEdition() ? wmClass + "-ce" : wmClass;
|
||||
if (PlatformUtils.isCommunityEdition()) wmClass += "-ce";
|
||||
if (DEBUG_MODE) wmClass += "-debug";
|
||||
return wmClass;
|
||||
}
|
||||
|
||||
public static void registerBundledFonts() {
|
||||
@@ -261,7 +248,6 @@ public class AppUIUtil {
|
||||
*/
|
||||
public static void showPrivacyPolicyAgreement(@NotNull String htmlText) {
|
||||
DialogWrapper dialog = new DialogWrapper(true) {
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
JPanel centerPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
|
||||
|
||||
Reference in New Issue
Block a user