mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-CR-32392 LafIconLookup.getIcon should be not always strict
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
package com.intellij.util.ui
|
||||
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.util.IconLoader
|
||||
import com.intellij.util.ThreeState
|
||||
import javax.swing.Icon
|
||||
|
||||
/**
|
||||
@@ -12,11 +14,11 @@ object LafIconLookup {
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun getIcon(name: String, selected: Boolean = false, focused: Boolean = false, enabled: Boolean = true, editable: Boolean = false, pressed: Boolean = false): Icon {
|
||||
return findIcon(name, selected = selected, focused = focused, enabled = enabled, editable = editable, pressed = pressed, isThrowErrorIfNotFound = true)
|
||||
return findIcon(name, selected = selected, focused = focused, enabled = enabled, editable = editable, pressed = pressed)
|
||||
?: AllIcons.Actions.Stub
|
||||
}
|
||||
|
||||
fun findIcon(name: String, selected: Boolean = false, focused: Boolean = false, enabled: Boolean = true, editable: Boolean = false, pressed: Boolean = false, isThrowErrorIfNotFound: Boolean = false): Icon? {
|
||||
fun findIcon(name: String, selected: Boolean = false, focused: Boolean = false, enabled: Boolean = true, editable: Boolean = false, pressed: Boolean = false, isThrowErrorIfNotFound: ThreeState = ThreeState.UNSURE): Icon? {
|
||||
var key = name
|
||||
if (editable) key += "Editable"
|
||||
if (selected) key += "Selected"
|
||||
@@ -37,7 +39,17 @@ object LafIconLookup {
|
||||
}
|
||||
|
||||
key = dir + key
|
||||
return IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/$key.png", LafIconLookup::class.java, true, isThrowErrorIfNotFound)
|
||||
@Suppress("DEPRECATION")
|
||||
return IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/$key.png", LafIconLookup::class.java, resolveIsThrowErrorIfNotFound(isThrowErrorIfNotFound))
|
||||
}
|
||||
|
||||
private fun resolveIsThrowErrorIfNotFound(value: ThreeState): Boolean {
|
||||
if (value != ThreeState.UNSURE) {
|
||||
return value == ThreeState.YES
|
||||
}
|
||||
|
||||
val app = ApplicationManager.getApplication()
|
||||
return app.isUnitTestMode || app.isInternal
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -362,7 +362,7 @@ public class DarculaLaf extends BasicLookAndFeel {
|
||||
}
|
||||
|
||||
if (value.endsWith(".png") || value.endsWith(".svg")) {
|
||||
Icon icon = IconLoader.findIcon(value, DarculaLaf.class, true);
|
||||
Icon icon = IconLoader.findIcon(value, DarculaLaf.class);
|
||||
if (icon != null) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
+3
-17
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.ui.laf.intellij;
|
||||
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
|
||||
@@ -140,7 +126,7 @@ public class WinIntelliJTextFieldUI extends TextFieldWithPopupHandlerUI {
|
||||
}
|
||||
};
|
||||
}
|
||||
return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/search.png", DarculaTextFieldUI.class, true);
|
||||
return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/search.png", DarculaTextFieldUI.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,7 +138,7 @@ public class WinIntelliJTextFieldUI extends TextFieldWithPopupHandlerUI {
|
||||
protected Icon getClearIcon(boolean hovered, boolean clickable) {
|
||||
if (!clickable) return null;
|
||||
Icon icon = UIManager.getIcon("TextField.darcula.clear.icon");
|
||||
return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/clear.png", DarculaTextFieldUI.class, true);
|
||||
return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/clear.png", DarculaTextFieldUI.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.openapi.util.SystemInfoRt
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.util.text.StringUtilRt
|
||||
import com.intellij.testFramework.assertions.Assertions.assertThat
|
||||
import com.intellij.util.ThreeState
|
||||
import com.intellij.util.ui.LafIconLookup
|
||||
import gnu.trove.THashMap
|
||||
import org.apache.batik.anim.dom.SVGDOMImplementation
|
||||
@@ -58,7 +59,7 @@ internal class SvgRenderer(val svgFileDir: Path, private val deviceConfiguration
|
||||
for (name in arrayOf("checkBox", "radio", "gear", "spinnerRight")) {
|
||||
val iconWrapper = when (name) {
|
||||
"gear" -> IconLoader.getIcon("/general/gear.png")
|
||||
else -> LafIconLookup.findIcon(name)
|
||||
else -> LafIconLookup.findIcon(name, isThrowErrorIfNotFound = ThreeState.NO)
|
||||
} ?: continue
|
||||
|
||||
if (isImage(iconWrapper)) {
|
||||
@@ -66,7 +67,7 @@ internal class SvgRenderer(val svgFileDir: Path, private val deviceConfiguration
|
||||
}
|
||||
}
|
||||
for (name in arrayOf("checkBox", "radio")) {
|
||||
val iconWrapper = LafIconLookup.findIcon(name, selected = true) ?: continue
|
||||
val iconWrapper = LafIconLookup.findIcon(name, selected = true, isThrowErrorIfNotFound = ThreeState.NO) ?: continue
|
||||
if (isImage(iconWrapper)) {
|
||||
return getIconRelativePath(iconWrapper.toString())
|
||||
}
|
||||
|
||||
@@ -168,16 +168,26 @@ public final class IconLoader {
|
||||
*/
|
||||
@Nullable
|
||||
public static Icon findIcon(@NotNull final String path, @NotNull final Class aClass) {
|
||||
return findIcon(path, aClass, false);
|
||||
//noinspection deprecation
|
||||
return findIcon(path, aClass, false, STRICT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #findIcon(String, Class)}
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public static Icon findIcon(@NotNull String path, @NotNull final Class aClass, boolean computeNow) {
|
||||
return findIcon(path, aClass, computeNow, STRICT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #findIcon(String, Class)}
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Nullable
|
||||
public static Icon findIcon(@NotNull String path, @NotNull Class aClass, boolean computeNow, boolean strict) {
|
||||
@Deprecated
|
||||
public static Icon findIcon(@NotNull String path, @NotNull Class aClass, @SuppressWarnings("unused") boolean unused, boolean strict) {
|
||||
String originalPath = path;
|
||||
Pair<String, Class> patchedPath = patchPath(path);
|
||||
path = patchedPath.first;
|
||||
|
||||
Reference in New Issue
Block a user