mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ui: allow to override background color for Editor notification panel
This commit is contained in:
committed by
Aleksey Pivovarov
parent
1eed340cde
commit
1e42810fda
+2
-6
@@ -34,7 +34,6 @@ import com.intellij.psi.impl.source.PsiExtensibleClass
|
|||||||
import com.intellij.ui.EditorNotificationPanel
|
import com.intellij.ui.EditorNotificationPanel
|
||||||
import com.intellij.ui.EditorNotifications
|
import com.intellij.ui.EditorNotifications
|
||||||
import com.intellij.ui.LightColors
|
import com.intellij.ui.LightColors
|
||||||
import java.awt.Color
|
|
||||||
|
|
||||||
class LibrarySourceNotificationProvider(private val project: Project, notifications: EditorNotifications) :
|
class LibrarySourceNotificationProvider(private val project: Project, notifications: EditorNotifications) :
|
||||||
EditorNotifications.Provider<EditorNotificationPanel>() {
|
EditorNotifications.Provider<EditorNotificationPanel>() {
|
||||||
@@ -60,7 +59,8 @@ class LibrarySourceNotificationProvider(private val project: Project, notificati
|
|||||||
if (offender != null) {
|
if (offender != null) {
|
||||||
val clsFile = offender.originalElement.containingFile?.virtualFile
|
val clsFile = offender.originalElement.containingFile?.virtualFile
|
||||||
if (clsFile != null && !clsFile.path.matches(ANDROID_SDK_PATTERN)) {
|
if (clsFile != null && !clsFile.path.matches(ANDROID_SDK_PATTERN)) {
|
||||||
val panel = ColoredNotificationPanel(LightColors.RED)
|
val panel = EditorNotificationPanel()
|
||||||
|
panel.background(LightColors.RED)
|
||||||
panel.setText(ProjectBundle.message("library.source.mismatch", offender.name))
|
panel.setText(ProjectBundle.message("library.source.mismatch", offender.name))
|
||||||
panel.createActionLabel(ProjectBundle.message("library.source.open.class"), {
|
panel.createActionLabel(ProjectBundle.message("library.source.open.class"), {
|
||||||
OpenFileDescriptor(project, clsFile, -1).navigate(true)
|
OpenFileDescriptor(project, clsFile, -1).navigate(true)
|
||||||
@@ -95,7 +95,3 @@ class LibrarySourceNotificationProvider(private val project: Project, notificati
|
|||||||
.filter { !(it.isConstructor && it.parameterList.parametersCount == 0) }
|
.filter { !(it.isConstructor && it.parameterList.parametersCount == 0) }
|
||||||
private fun inners(clazz: PsiClass) = (clazz as? PsiExtensibleClass)?.ownInnerClasses ?: clazz.innerClasses.asList()
|
private fun inners(clazz: PsiClass) = (clazz as? PsiExtensibleClass)?.ownInnerClasses ?: clazz.innerClasses.asList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ColoredNotificationPanel(private val color: Color?) : EditorNotificationPanel() {
|
|
||||||
override fun getBackground(): Color? = color ?: super.getBackground()
|
|
||||||
}
|
|
||||||
@@ -30,7 +30,6 @@ import com.jetbrains.jsonSchema.ide.JsonSchemaService;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -67,12 +66,8 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications.
|
|||||||
final String message = worker.createMessage(descriptors);
|
final String message = worker.createMessage(descriptors);
|
||||||
if (message == null) return null;
|
if (message == null) return null;
|
||||||
|
|
||||||
final EditorNotificationPanel panel = new EditorNotificationPanel() {
|
final EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||||
@Override
|
panel.background(LightColors.RED);
|
||||||
public Color getBackground() {
|
|
||||||
return LightColors.RED;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
panel.setText(message);
|
panel.setText(message);
|
||||||
panel.createActionLabel("Edit JSON Schema Mappings", () -> {
|
panel.createActionLabel("Edit JSON Schema Mappings", () -> {
|
||||||
ShowSettingsUtil.getInstance().editConfigurable(myProject, new JsonSchemaMappingsConfigurable(myProject));
|
ShowSettingsUtil.getInstance().editConfigurable(myProject, new JsonSchemaMappingsConfigurable(myProject));
|
||||||
|
|||||||
@@ -87,27 +87,13 @@ public class DiffNotifications {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JPanel createNotification(@NotNull String text, @Nullable final Color background, boolean showHideAction) {
|
public static JPanel createNotification(@NotNull String text, @Nullable final Color background, boolean showHideAction) {
|
||||||
final MyEditorNotificationPanel panel = new MyEditorNotificationPanel();
|
final EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||||
panel.text(text);
|
panel.text(text);
|
||||||
panel.setBackgroundColor(background);
|
panel.background(background);
|
||||||
if (showHideAction) {
|
if (showHideAction) {
|
||||||
HyperlinkLabel link = panel.createActionLabel("Hide", () -> panel.setVisible(false));
|
HyperlinkLabel link = panel.createActionLabel("Hide", () -> panel.setVisible(false));
|
||||||
link.setToolTipText("Hide this notification");
|
link.setToolTipText("Hide this notification");
|
||||||
}
|
}
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MyEditorNotificationPanel extends EditorNotificationPanel {
|
|
||||||
@Nullable private Color myBackground;
|
|
||||||
|
|
||||||
public void setBackgroundColor(@Nullable Color value) {
|
|
||||||
myBackground = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public Color getBackground() {
|
|
||||||
return myBackground != null ? myBackground : super.getBackground();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-7
@@ -48,7 +48,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class FileLevelIntentionComponent extends EditorNotificationPanel {
|
public class FileLevelIntentionComponent extends EditorNotificationPanel {
|
||||||
private final Project myProject;
|
private final Project myProject;
|
||||||
private final Color myBackground;
|
|
||||||
|
|
||||||
public FileLevelIntentionComponent(final String description,
|
public FileLevelIntentionComponent(final String description,
|
||||||
@NotNull HighlightSeverity severity,
|
@NotNull HighlightSeverity severity,
|
||||||
@@ -58,7 +57,7 @@ public class FileLevelIntentionComponent extends EditorNotificationPanel {
|
|||||||
@NotNull final PsiFile psiFile,
|
@NotNull final PsiFile psiFile,
|
||||||
@NotNull final Editor editor, @Nullable String tooltip) {
|
@NotNull final Editor editor, @Nullable String tooltip) {
|
||||||
myProject = project;
|
myProject = project;
|
||||||
myBackground = getColor(severity);
|
background(getColor(severity));
|
||||||
|
|
||||||
final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
|
final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
|
||||||
|
|
||||||
@@ -106,11 +105,6 @@ public class FileLevelIntentionComponent extends EditorNotificationPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color getBackground() {
|
|
||||||
return myBackground;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Color getColor(@NotNull HighlightSeverity severity) {
|
private Color getColor(@NotNull HighlightSeverity severity) {
|
||||||
if (SeverityRegistrar.getSeverityRegistrar(myProject).compare(severity, HighlightSeverity.ERROR) >= 0) {
|
if (SeverityRegistrar.getSeverityRegistrar(myProject).compare(severity, HighlightSeverity.ERROR) >= 0) {
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ import com.intellij.openapi.actionSystem.AnAction;
|
|||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.editor.EditorBundle;
|
import com.intellij.openapi.editor.EditorBundle;
|
||||||
|
import com.intellij.openapi.editor.colors.ColorKey;
|
||||||
import com.intellij.openapi.editor.colors.EditorColors;
|
import com.intellij.openapi.editor.colors.EditorColors;
|
||||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||||
|
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Iconable;
|
import com.intellij.openapi.util.Iconable;
|
||||||
import com.intellij.openapi.util.Weighted;
|
import com.intellij.openapi.util.Weighted;
|
||||||
@@ -55,6 +57,8 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
|
|||||||
protected final JLabel myLabel = new JLabel();
|
protected final JLabel myLabel = new JLabel();
|
||||||
protected final JLabel myGearLabel = new JLabel();
|
protected final JLabel myGearLabel = new JLabel();
|
||||||
protected final JPanel myLinksPanel = new NonOpaquePanel(new HorizontalLayout(JBUI.scale(5)));
|
protected final JPanel myLinksPanel = new NonOpaquePanel(new HorizontalLayout(JBUI.scale(5)));
|
||||||
|
protected Color myBackgroundColor;
|
||||||
|
protected ColorKey myBackgroundColorKey;
|
||||||
|
|
||||||
public EditorNotificationPanel() {
|
public EditorNotificationPanel() {
|
||||||
super(new BorderLayout());
|
super(new BorderLayout());
|
||||||
@@ -79,6 +83,16 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EditorNotificationPanel background(@Nullable Color color) {
|
||||||
|
myBackgroundColor = color;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditorNotificationPanel background(@Nullable ColorKey colorKey) {
|
||||||
|
myBackgroundColorKey = colorKey;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public EditorNotificationPanel icon(@NotNull Icon icon) {
|
public EditorNotificationPanel icon(@NotNull Icon icon) {
|
||||||
myLabel.setIcon(icon);
|
myLabel.setIcon(icon);
|
||||||
return this;
|
return this;
|
||||||
@@ -86,8 +100,14 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getBackground() {
|
public Color getBackground() {
|
||||||
Color color = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.NOTIFICATION_BACKGROUND);
|
EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
|
||||||
return color == null ? UIUtil.getToolTipBackground() : color;
|
if (myBackgroundColor != null) return myBackgroundColor;
|
||||||
|
if (myBackgroundColorKey != null) {
|
||||||
|
Color color = globalScheme.getColor(myBackgroundColorKey);
|
||||||
|
if (color != null) return color;
|
||||||
|
}
|
||||||
|
Color color = globalScheme.getColor(EditorColors.NOTIFICATION_BACKGROUND);
|
||||||
|
return color != null ? color : UIUtil.getToolTipBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HyperlinkLabel createActionLabel(final String text, @NonNls final String actionId) {
|
public HyperlinkLabel createActionLabel(final String text, @NonNls final String actionId) {
|
||||||
|
|||||||
+4
-8
@@ -18,7 +18,6 @@ import org.editorconfig.core.EditorConfig;
|
|||||||
import org.editorconfig.settings.EditorConfigSettings;
|
import org.editorconfig.settings.EditorConfigSettings;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,13 +42,10 @@ public class EditorConfigNotifierProvider extends EditorNotifications.Provider<E
|
|||||||
|
|
||||||
final List<EditorConfig.OutPair> pairs = SettingsProviderComponent.getInstance().getOutPairs(project, Utils.getFilePath(project, file));
|
final List<EditorConfig.OutPair> pairs = SettingsProviderComponent.getInstance().getOutPairs(project, Utils.getFilePath(project, file));
|
||||||
if (!pairs.isEmpty()) {
|
if (!pairs.isEmpty()) {
|
||||||
final EditorNotificationPanel panel = new EditorNotificationPanel() {
|
final EditorNotificationPanel panel = new EditorNotificationPanel()
|
||||||
@Override
|
.background(LightColors.GREEN)
|
||||||
public Color getBackground() {
|
.text("EditorConfig is overriding Code Style settings for this file")
|
||||||
return LightColors.GREEN;
|
.icon(EditorconfigIcons.Editorconfig);
|
||||||
}
|
|
||||||
}.text("EditorConfig is overriding Code Style settings for this file").
|
|
||||||
icon(EditorconfigIcons.Editorconfig);
|
|
||||||
panel.createActionLabel("OK", () -> {
|
panel.createActionLabel("OK", () -> {
|
||||||
PropertiesComponent.getInstance(project).setValue(EDITOR_CONFIG_ACCEPTED, true);
|
PropertiesComponent.getInstance(project).setValue(EDITOR_CONFIG_ACCEPTED, true);
|
||||||
EditorNotifications.getInstance(project).updateAllNotifications();
|
EditorNotifications.getInstance(project).updateAllNotifications();
|
||||||
|
|||||||
+2
-10
@@ -3,7 +3,6 @@ package com.jetbrains.edu.coursecreator;
|
|||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
import com.intellij.openapi.editor.colors.EditorColors;
|
import com.intellij.openapi.editor.colors.EditorColors;
|
||||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
|
||||||
import com.intellij.openapi.fileEditor.FileEditor;
|
import com.intellij.openapi.fileEditor.FileEditor;
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||||
import com.intellij.openapi.project.DumbAware;
|
import com.intellij.openapi.project.DumbAware;
|
||||||
@@ -32,10 +31,8 @@ import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CCSubtaskEditorNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
|
public class CCSubtaskEditorNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
|
||||||
private static final Key<EditorNotificationPanel> KEY = Key.create("edu.coursecreator.subtask");
|
private static final Key<EditorNotificationPanel> KEY = Key.create("edu.coursecreator.subtask");
|
||||||
@@ -68,13 +65,8 @@ public class CCSubtaskEditorNotificationProvider extends EditorNotifications.Pro
|
|||||||
if (task == null || !task.hasSubtasks()) {
|
if (task == null || !task.hasSubtasks()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
EditorNotificationPanel panel = new EditorNotificationPanel() {
|
EditorNotificationPanel panel = new EditorNotificationPanel();
|
||||||
@Override
|
panel.background(EditorColors.GUTTER_BACKGROUND);
|
||||||
public Color getBackground() {
|
|
||||||
Color color = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.GUTTER_BACKGROUND);
|
|
||||||
return color == null ? super.getBackground() : color;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
String header = (isTestFile ? "test" : "task") + " file";
|
String header = (isTestFile ? "test" : "task") + " file";
|
||||||
int activeSubtaskIndex = task.getActiveSubtaskIndex() + 1;
|
int activeSubtaskIndex = task.getActiveSubtaskIndex() + 1;
|
||||||
int subtaskSize = task.getLastSubtaskIndex() + 1;
|
int subtaskSize = task.getLastSubtaskIndex() + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user