IDEA-200666 UX-481 UI correction for RL popup; new "Recent locations selection" color has been introduced

This commit is contained in:
Dmitry.Krasilschikov
2019-02-06 18:30:32 +02:00
parent 43b8f15802
commit 1ff1e4c014
5 changed files with 84 additions and 43 deletions
@@ -134,6 +134,7 @@ public class GeneralColorsPage implements ColorSettingsPage, InspectionColorSett
new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.popups.information"), HintUtil.INFORMATION_COLOR_KEY, ColorDescriptor.Kind.BACKGROUND),
new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.popups.question"), HintUtil.QUESTION_COLOR_KEY, ColorDescriptor.Kind.BACKGROUND),
new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.popups.error"), HintUtil.ERROR_COLOR_KEY, ColorDescriptor.Kind.BACKGROUND),
new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.popups.recent.locations.selection"), HintUtil.RECENT_LOCATIONS_SELECTION_KEY, ColorDescriptor.Kind.BACKGROUND),
new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.popups.tooltip"), IdeTooltipManager.TOOLTIP_COLOR_KEY, ColorDescriptor.Kind.BACKGROUND),
new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.visual.guides"), EditorColors.VISUAL_INDENT_GUIDE_COLOR, ColorDescriptor.Kind.FOREGROUND),
@@ -40,6 +40,9 @@ public class HintUtil {
public static final Color QUESTION_UNDERSCORE_COLOR = JBColor.foreground();
public static final ColorKey RECENT_LOCATIONS_SELECTION_KEY = ColorKey
.createColorKey("RECENT_LOCATIONS_SELECTION", JBColor.namedColor("Table.lightSelectionBackground", new JBColor(0xE9EEF5, 0x464A4D)));
private HintUtil() {
}
@@ -58,6 +61,11 @@ public class HintUtil {
return notNull(getGlobalOrDefaultColor(ERROR_COLOR_KEY), ERROR_COLOR_KEY.getDefaultColor());
}
@NotNull
public static Color getRecentLocationsSelectionColor() {
return notNull(getGlobalOrDefaultColor(RECENT_LOCATIONS_SELECTION_KEY), RECENT_LOCATIONS_SELECTION_KEY.getDefaultColor());
}
public static JComponent createInformationLabel(@NotNull String text) {
return createInformationLabel(text, null, null, null);
}
@@ -197,12 +205,12 @@ public class HintUtil {
}
return label;
}
@NotNull
public static String prepareHintText(@NotNull String text, @NotNull HintHint hintHint) {
return prepareHintText(new Html(text), hintHint);
}
public static String prepareHintText(@NotNull Html text, @NotNull HintHint hintHint) {
String htmlBody = UIUtil.getHtmlBody(text);
return String.format(
@@ -33,10 +33,7 @@ import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.util.DimensionService;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.ex.WindowManagerEx;
@@ -151,6 +148,7 @@ public class RecentLocationsAction extends AnAction {
})
.setResizable(true)
.setMovable(true)
.setBorderColor(SystemInfoRt.isMac && UIUtil.isUnderDarcula() ? topPanel.getBackground() : null)
.setDimensionServiceKey(project, LOCATION_SETTINGS_KEY, true)
.setMinSize(new Dimension(DEFAULT_WIDTH, MINIMUM_HEIGHT))
.setLocateWithinScreenBounds(false)
@@ -1,13 +1,17 @@
// Copyright 2000-2019 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.actions;
import com.intellij.codeInsight.hint.HintUtil;
import com.intellij.ide.actions.RecentLocationsAction.RecentLocationItem;
import com.intellij.lang.Language;
import com.intellij.lang.LanguageUtil;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.editor.CaretState;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.actions.EditorActionUtil;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.markup.HighlighterLayer;
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
@@ -17,6 +21,7 @@ import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.SystemInfoRt;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
@@ -24,6 +29,7 @@ import com.intellij.psi.PsiManager;
import com.intellij.ui.*;
import com.intellij.ui.speedSearch.SpeedSearch;
import com.intellij.ui.speedSearch.SpeedSearchUtil;
import com.intellij.util.FontUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
@@ -38,8 +44,6 @@ import java.util.Map;
import static com.intellij.ide.actions.RecentLocationsAction.EMPTY_FILE_TEXT;
class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem> {
private static final JBColor BACKGROUND_COLOR = JBColor.namedColor("Table.lightSelectionBackground", new JBColor(0xE9EEF5, 0x464A4D));
@NotNull private final Project myProject;
@NotNull private final SpeedSearch mySpeedSearch;
@NotNull private final Ref<Map<IdeDocumentHistoryImpl.PlaceInfo, String>> myBreadcrumbsMap;
@@ -63,52 +67,58 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
return super.getListCellRendererComponent(list, value, index, selected, hasFocus);
}
Color defaultBackground = editor.getColorsScheme().getDefaultBackground();
EditorColorsScheme colorsScheme = editor.getColorsScheme();
String breadcrumbs = myBreadcrumbsMap.get().get(value.getInfo());
JPanel panel = new JPanel(new VerticalFlowLayout(0, 0));
panel.add(createTitleComponent(myProject, list, mySpeedSearch, breadcrumbs, value.getInfo(), defaultBackground, selected, index));
String text = editor.getDocument().getText();
if (!StringUtil.isEmpty(text)) {
panel.add(setupEditorComponent(editor, text, mySpeedSearch, selected ? BACKGROUND_COLOR : defaultBackground));
if (index != 0) {
panel.add(createSeparatorLine(colorsScheme));
}
panel.add(createTitleComponent(myProject, list, mySpeedSearch, breadcrumbs, value.getInfo(), colorsScheme, selected));
panel.add(setupEditorComponent(editor, editor.getDocument().getText(), mySpeedSearch, colorsScheme, selected));
return panel;
}
@NotNull
private static Color getBackgroundColor(@NotNull EditorColorsScheme colorsScheme, boolean selected) {
return selected ? HintUtil.getRecentLocationsSelectionColor() : colorsScheme.getDefaultBackground();
}
@NotNull
private static JComponent createTitleComponent(@NotNull Project project,
@NotNull JList<? extends RecentLocationItem> list,
@NotNull SpeedSearch speedSearch,
@Nullable String breadcrumb,
@NotNull IdeDocumentHistoryImpl.PlaceInfo placeInfo,
@NotNull Color background,
boolean selected,
int index) {
@NotNull EditorColorsScheme colorsScheme,
boolean selected) {
JComponent title = JBUI.Panels
.simplePanel()
.withBorder(JBUI.Borders.empty())
.addToLeft(createTitleTextComponent(project, list, speedSearch, placeInfo, breadcrumb, selected))
.addToCenter(createTitledSeparator(background));
.addToLeft(createTitleTextComponent(project, list, speedSearch, placeInfo, colorsScheme, breadcrumb, selected));
title.setBorder(BorderFactory.createEmptyBorder(index == 0 ? 5 : 15, 8, 6, 0));
title.setBackground(background);
title.setBorder(JBUI.Borders.empty(8, 6, 6, 0));
title.setBackground(getBackgroundColor(colorsScheme, selected));
return title;
}
@NotNull
private static TitledSeparator createTitledSeparator(@NotNull Color background) {
TitledSeparator titledSeparator = new TitledSeparator();
titledSeparator.setBackground(background);
return titledSeparator;
private static JPanel createSeparatorLine(@NotNull EditorColorsScheme colorsScheme) {
Color color = colorsScheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
if (color == null) {
color = JBColor.namedColor("Group.separatorColor", new JBColor(Gray.xCD, Gray.x51));
}
return JBUI.Panels.simplePanel().withBorder(JBUI.Borders.customLine(color, 1, 0, 0, 0));
}
@NotNull
private static JComponent setupEditorComponent(@NotNull EditorEx editor,
@NotNull String text,
@NotNull SpeedSearch speedSearch,
@NotNull Color backgroundColor) {
@NotNull EditorColorsScheme colorsScheme,
boolean selected) {
Iterable<TextRange> ranges = speedSearch.matchingFragments(text);
if (ranges != null) {
selectSearchResultsInEditor(editor, ranges.iterator());
@@ -117,14 +127,14 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
RecentLocationsAction.clearSelectionInEditor(editor);
}
editor.setBackgroundColor(backgroundColor);
editor.setBorder(JBUI.Borders.emptyLeft(5));
editor.setBackgroundColor(getBackgroundColor(colorsScheme, selected));
editor.setBorder(JBUI.Borders.empty(0, 4, 4, 0));
if (EMPTY_FILE_TEXT.equals(editor.getDocument().getText())) {
editor.getMarkupModel().addRangeHighlighter(0,
EMPTY_FILE_TEXT.length(),
HighlighterLayer.SYNTAX,
createEmptyTextForegroundTextAttributes(),
createEmptyTextForegroundTextAttributes(colorsScheme),
HighlighterTargetArea.EXACT_RANGE);
}
@@ -136,18 +146,19 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
@NotNull JList<? extends RecentLocationItem> list,
@NotNull SpeedSearch speedSearch,
@NotNull IdeDocumentHistoryImpl.PlaceInfo placeInfo,
@NotNull EditorColorsScheme colorsScheme,
@Nullable String breadcrumbText,
boolean selected) {
SimpleColoredComponent titleTextComponent = new SimpleColoredComponent();
String fileName = placeInfo.getFile().getName();
String text = fileName;
titleTextComponent.append(fileName, SimpleTextAttributes.fromTextAttributes(createLabelForegroundTextAttributes()));
titleTextComponent.append(fileName, createFileNameTextAttributes(colorsScheme, selected));
if (StringUtil.isNotEmpty(breadcrumbText) && !StringUtil.equals(breadcrumbText, fileName)) {
text += " " + breadcrumbText;
titleTextComponent.append(" ");
titleTextComponent.append(breadcrumbText, SimpleTextAttributes.fromTextAttributes(createBreadcrumbsTextAttributes()));
titleTextComponent.append(breadcrumbText, createBreadcrumbsTextAttributes(colorsScheme, selected));
}
Icon icon = fetchIcon(project, placeInfo);
@@ -159,6 +170,10 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
titleTextComponent.setBorder(JBUI.Borders.empty());
if (!SystemInfoRt.isWindows) {
titleTextComponent.setFont(FontUtil.minusOne(UIUtil.getLabelFont()));
}
if (speedSearch.matchingFragments(text) != null) {
SpeedSearchUtil.applySpeedSearchHighlighting(list, titleTextComponent, false, selected);
}
@@ -191,25 +206,43 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
}
@NotNull
private static TextAttributes createLabelForegroundTextAttributes() {
TextAttributes textAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES.toTextAttributes();
private static SimpleTextAttributes createFileNameTextAttributes(@NotNull EditorColorsScheme colorsScheme, boolean selected) {
TextAttributes textAttributes = createDefaultTextAttributesWithBackground(colorsScheme, getBackgroundColor(colorsScheme, selected));
textAttributes.setFontType(Font.BOLD);
textAttributes.setForegroundColor(UIUtil.getLabelTextForeground());
return textAttributes;
return SimpleTextAttributes.fromTextAttributes(textAttributes);
}
@NotNull
private static TextAttributes createBreadcrumbsTextAttributes() {
TextAttributes textAttributes = SimpleTextAttributes.GRAYED_SMALL_ATTRIBUTES.toTextAttributes();
textAttributes.setFontType(Font.BOLD);
return textAttributes;
private static SimpleTextAttributes createBreadcrumbsTextAttributes(@NotNull EditorColorsScheme colorsScheme, boolean selected) {
Color backgroundColor = getBackgroundColor(colorsScheme, selected);
TextAttributes attributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
if (attributes != null) {
Color unusedForeground = attributes.getForegroundColor();
if (unusedForeground != null) {
return SimpleTextAttributes.fromTextAttributes(new TextAttributes(unusedForeground, backgroundColor, null, null, Font.PLAIN));
}
}
return SimpleTextAttributes.fromTextAttributes(createDefaultTextAttributesWithBackground(colorsScheme, backgroundColor));
}
@NotNull
private static TextAttributes createEmptyTextForegroundTextAttributes() {
TextAttributes textAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES.toTextAttributes();
textAttributes.setForegroundColor(UIUtil.getLabelDisabledForeground());
return textAttributes;
private static TextAttributes createDefaultTextAttributesWithBackground(@NotNull EditorColorsScheme colorsScheme, @NotNull Color backgroundColor) {
TextAttributes defaultTextAttributes = new TextAttributes();
TextAttributes textAttributes = colorsScheme.getAttributes(HighlighterColors.TEXT);
if (textAttributes != null) {
defaultTextAttributes = textAttributes.clone();
defaultTextAttributes.setBackgroundColor(backgroundColor);
}
return defaultTextAttributes;
}
@NotNull
private static TextAttributes createEmptyTextForegroundTextAttributes(@NotNull EditorColorsScheme colorsScheme) {
TextAttributes unusedAttributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
return unusedAttributes != null ? unusedAttributes : SimpleTextAttributes.GRAYED_ATTRIBUTES.toTextAttributes();
}
@Override
@@ -183,6 +183,7 @@ options.general.color.descriptor.popups.documentation=Popups and Hints//Document
options.general.color.descriptor.popups.information=Popups and Hints//Information hint
options.general.color.descriptor.popups.question=Popups and Hints//Question hint
options.general.color.descriptor.popups.error=Popups and Hints//Error hint
options.general.color.descriptor.popups.recent.locations.selection=Popups and Hints//Recent locations selection
options.general.color.descriptor.popups.tooltip=Popups and Hints//Tooltip
options.general.color.descriptor.highlighted.folding.border=Text//Folded text with highlighting