mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-200666 IDEA-205655 UI corrections for the popup
This commit is contained in:
@@ -39,8 +39,10 @@ import com.intellij.openapi.wm.ex.WindowManagerEx;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.ScrollingUtil;
|
||||
import com.intellij.ui.WindowMoveListener;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.components.breadcrumbs.Crumb;
|
||||
import com.intellij.ui.components.panels.NonOpaquePanel;
|
||||
import com.intellij.ui.speedSearch.ListWithFilter;
|
||||
import com.intellij.ui.speedSearch.NameFilteringListModel;
|
||||
import com.intellij.ui.speedSearch.SpeedSearch;
|
||||
@@ -49,11 +51,11 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.Topic;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -106,7 +108,7 @@ public class RecentLocationsAction extends AnAction {
|
||||
ScrollingUtil.ensureSelectionExists(list);
|
||||
|
||||
JLabel title = createTitle(showChanged);
|
||||
JPanel topPanel = createTopPanel(createCheckbox(project, listWithFilter, e, showChanged), title);
|
||||
JPanel topPanel = createHeaderPanel(title, createCheckbox(project, listWithFilter, e, showChanged));
|
||||
JPanel mainPanel = createMainPanel(listWithFilter, topPanel);
|
||||
|
||||
Ref<Boolean> navigationRef = Ref.create(false);
|
||||
@@ -123,7 +125,6 @@ public class RecentLocationsAction extends AnAction {
|
||||
})
|
||||
.setResizable(true)
|
||||
.setMovable(true)
|
||||
.setShowBorder(false)
|
||||
.setDimensionServiceKey(project, LOCATION_SETTINGS_KEY, true)
|
||||
.setMinSize(new Dimension(DEFAULT_POPUP_WIDTH, JBUI.scale(100)))
|
||||
.createPopup();
|
||||
@@ -230,27 +231,18 @@ public class RecentLocationsAction extends AnAction {
|
||||
private static JPanel createMainPanel(@NotNull ListWithFilter listWithFilter, @NotNull JPanel topPanel) {
|
||||
JPanel mainPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
|
||||
mainPanel.add(topPanel);
|
||||
JLabel line = createLine();
|
||||
mainPanel.add(line);
|
||||
mainPanel.add(listWithFilter);
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder());
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JLabel createLine() {
|
||||
JLabel line = new JLabel();
|
||||
Border bottom = JBUI.Borders.customLine(JBUI.CurrentTheme.Popup.separatorTextColor(), 0, 0, 1, 0);
|
||||
line.setBorder(bottom);
|
||||
return line;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JPanel createTopPanel(@NotNull JComponent checkbox, @NotNull JLabel title) {
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
private static JPanel createHeaderPanel(@NotNull JLabel title, @NotNull JComponent checkbox) {
|
||||
JPanel topPanel = new NonOpaquePanel(new BorderLayout());
|
||||
topPanel.add(title, BorderLayout.WEST);
|
||||
topPanel.add(checkbox, BorderLayout.EAST);
|
||||
topPanel.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
|
||||
topPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
topPanel.setBackground(JBUI.CurrentTheme.Popup.headerBackground(true));
|
||||
|
||||
WindowMoveListener moveListener = new WindowMoveListener(topPanel);
|
||||
topPanel.addMouseListener(moveListener);
|
||||
@@ -275,14 +267,15 @@ public class RecentLocationsAction extends AnAction {
|
||||
action.getTemplatePresentation().putClientProperty(COMPONENT_KEY, checkbox);
|
||||
action.setSelected(event, changed);
|
||||
checkbox.setBorder(BorderFactory.createEmptyBorder());
|
||||
checkbox.setForeground(UIUtil.getContextHelpForeground());
|
||||
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JLabel createTitle(boolean showChanged) {
|
||||
JLabel title = new JLabel();
|
||||
title.setBorder(BorderFactory.createEmptyBorder());
|
||||
JBLabel title = new JBLabel();
|
||||
title.setFont(title.getFont().deriveFont(Font.BOLD));
|
||||
updateTitleText(title, showChanged);
|
||||
return title;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.openapi.editor.CaretState;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actions.EditorActionUtil;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.VerticalFlowLayout;
|
||||
@@ -23,9 +24,10 @@ import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.intellij.ide.actions.RecentLocationsAction.getBreadcrumbs;
|
||||
|
||||
class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem> {
|
||||
private static final JBColor BACKGROUND_COLOR = JBColor.namedColor("Table.lightSelectionBackground", new JBColor(0xE9EEF5, 0x464A4D));
|
||||
private static final Color TITLE_FOREGROUND_COLOR = UIUtil.getLabelForeground().darker();
|
||||
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final SpeedSearch mySpeedSearch;
|
||||
@@ -46,47 +48,51 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
|
||||
return super.getListCellRendererComponent(list, value, index, selected, hasFocus);
|
||||
}
|
||||
|
||||
Color background = selected ? BACKGROUND_COLOR : editor.getColorsScheme().getDefaultBackground();
|
||||
if (index % 2 == 1) {
|
||||
background = adjustBackgroundColor(background);
|
||||
}
|
||||
|
||||
IdeDocumentHistoryImpl.PlaceInfo placeInfo = value.getInfo();
|
||||
String breadcrumb = RecentLocationsAction.getBreadcrumbs(myProject, placeInfo);
|
||||
|
||||
JComponent title = JBUI.Panels
|
||||
.simplePanel()
|
||||
.addToLeft(createBreadcrumbsComponent(list, mySpeedSearch, breadcrumb, background, selected))
|
||||
.addToCenter(createTitledSeparator(background))
|
||||
.addToRight(createFileNameComponent(list, mySpeedSearch, breadcrumb, placeInfo, selected))
|
||||
.withBackground(background);
|
||||
|
||||
Color defaultBackground = editor.getColorsScheme().getDefaultBackground();
|
||||
String breadcrumbs = getBreadcrumbs(myProject, value.getInfo());
|
||||
JPanel panel = new JPanel(new VerticalFlowLayout(0, 0));
|
||||
panel.add(title);
|
||||
panel.add(createTitleComponent(list, mySpeedSearch, breadcrumbs, value.getInfo(), defaultBackground, selected));
|
||||
|
||||
String text = editor.getDocument().getText();
|
||||
if (!StringUtil.isEmpty(text)) {
|
||||
addEditorComponent(panel, editor, text, background, mySpeedSearch);
|
||||
panel.add(setupEditorComponent(editor, text, mySpeedSearch, selected ? BACKGROUND_COLOR : defaultBackground));
|
||||
}
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JComponent createTitledSeparator(@NotNull Color background) {
|
||||
JComponent titledSeparator = new TitledSeparator();
|
||||
private static JComponent createTitleComponent(@NotNull JList<? extends RecentLocationItem> list,
|
||||
@NotNull SpeedSearch speedSearch,
|
||||
@NotNull String breadcrumb,
|
||||
@NotNull IdeDocumentHistoryImpl.PlaceInfo placeInfo,
|
||||
@NotNull Color background,
|
||||
boolean selected) {
|
||||
JComponent title = JBUI.Panels
|
||||
.simplePanel()
|
||||
.addToLeft(createTitleTextComponent(list, speedSearch, placeInfo, breadcrumb, selected))
|
||||
.addToCenter(createTitledSeparator(background));
|
||||
|
||||
title.setBorder(BorderFactory.createEmptyBorder(2, 0, 1, 0));
|
||||
title.setBackground(background);
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static TitledSeparator createTitledSeparator(@NotNull Color background) {
|
||||
TitledSeparator titledSeparator = new TitledSeparator();
|
||||
titledSeparator.setBorder(BorderFactory.createEmptyBorder());
|
||||
titledSeparator.setBackground(background);
|
||||
return titledSeparator;
|
||||
}
|
||||
|
||||
private static void addEditorComponent(@NotNull JPanel panel,
|
||||
@NotNull EditorEx editor,
|
||||
@NotNull String text,
|
||||
@NotNull Color background,
|
||||
@NotNull SpeedSearch speedSearch) {
|
||||
editor.setBackgroundColor(background);
|
||||
@NotNull
|
||||
private static JComponent setupEditorComponent(@NotNull EditorEx editor,
|
||||
@NotNull String text,
|
||||
@NotNull SpeedSearch speedSearch,
|
||||
@NotNull Color backgroundColor) {
|
||||
Iterable<TextRange> ranges = speedSearch.matchingFragments(text);
|
||||
|
||||
if (ranges != null) {
|
||||
selectSearchResultsInEditor(editor, ranges.iterator());
|
||||
}
|
||||
@@ -94,49 +100,43 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
|
||||
RecentLocationsAction.clearSelectionInEditor(editor);
|
||||
}
|
||||
|
||||
JComponent editorComponent = editor.getComponent();
|
||||
editorComponent.setBorder(BorderFactory.createEmptyBorder());
|
||||
panel.add(editorComponent);
|
||||
editor.setBackgroundColor(backgroundColor);
|
||||
editor.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
|
||||
|
||||
editor.setBorder(BorderFactory.createEmptyBorder());
|
||||
return editor.getComponent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static SimpleColoredComponent createBreadcrumbsComponent(@NotNull JList<? extends RecentLocationItem> list,
|
||||
@NotNull SpeedSearch speedSearch,
|
||||
@NotNull String breadcrumb,
|
||||
@NotNull Color background,
|
||||
boolean selected) {
|
||||
SimpleColoredComponent breadcrumbTextComponent = new SimpleColoredComponent();
|
||||
breadcrumbTextComponent.setForeground(TITLE_FOREGROUND_COLOR);
|
||||
breadcrumbTextComponent.setBackground(background);
|
||||
breadcrumbTextComponent.append(breadcrumb);
|
||||
Iterable<TextRange> breadCrumbRanges = speedSearch.matchingFragments(breadcrumb);
|
||||
if (breadCrumbRanges != null) {
|
||||
SpeedSearchUtil.applySpeedSearchHighlighting(list, breadcrumbTextComponent, true, selected);
|
||||
private static SimpleColoredComponent createTitleTextComponent(@NotNull JList<? extends RecentLocationItem> list,
|
||||
@NotNull SpeedSearch speedSearch,
|
||||
@NotNull IdeDocumentHistoryImpl.PlaceInfo placeInfo,
|
||||
@NotNull String breadcrumbText,
|
||||
boolean selected) {
|
||||
SimpleColoredComponent titleTextComponent = new SimpleColoredComponent();
|
||||
titleTextComponent.append(breadcrumbText);
|
||||
|
||||
String text = breadcrumbText;
|
||||
String fileName = placeInfo.getFile().getName();
|
||||
if (!StringUtil.equals(breadcrumbText, fileName)) {
|
||||
text += " " + fileName;
|
||||
titleTextComponent.append(" ");
|
||||
titleTextComponent.append(fileName, createLabelDisabledForegroundAttributes());
|
||||
}
|
||||
|
||||
return breadcrumbTextComponent;
|
||||
if (speedSearch.matchingFragments(text) != null) {
|
||||
SpeedSearchUtil.applySpeedSearchHighlighting(list, titleTextComponent, false, selected);
|
||||
}
|
||||
|
||||
titleTextComponent.setBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
return titleTextComponent;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static SimpleColoredComponent createFileNameComponent(@NotNull JList<? extends RecentLocationItem> list,
|
||||
@NotNull SpeedSearch speedSearch,
|
||||
@NotNull String breadcrumb,
|
||||
@NotNull IdeDocumentHistoryImpl.PlaceInfo placeInfo,
|
||||
boolean selected) {
|
||||
SimpleColoredComponent fileNameComponent = new SimpleColoredComponent();
|
||||
fileNameComponent.setForeground(TITLE_FOREGROUND_COLOR);
|
||||
if (!StringUtil.equals(breadcrumb, placeInfo.getFile().getName())) {
|
||||
fileNameComponent.append(placeInfo.getFile().getName());
|
||||
fileNameComponent.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 2));
|
||||
Iterable<TextRange> fileNameRanges = speedSearch.matchingFragments(placeInfo.getFile().getName());
|
||||
if (fileNameRanges != null) {
|
||||
SpeedSearchUtil.applySpeedSearchHighlighting(list, fileNameComponent, true, selected);
|
||||
}
|
||||
}
|
||||
|
||||
return fileNameComponent;
|
||||
private static SimpleTextAttributes createLabelDisabledForegroundAttributes() {
|
||||
TextAttributes textAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES.toTextAttributes();
|
||||
textAttributes.setForegroundColor(UIUtil.getLabelDisabledForeground());
|
||||
return SimpleTextAttributes.fromTextAttributes(textAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,18 +147,6 @@ class RecentLocationsRenderer extends ColoredListCellRenderer<RecentLocationItem
|
||||
boolean hasFocus) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Color adjustBackgroundColor(@NotNull Color background) {
|
||||
Color brighterColor = ColorUtil.brighter(background, 1);
|
||||
if (!background.equals(brighterColor)) {
|
||||
background = brighterColor;
|
||||
}
|
||||
else {
|
||||
background = ColorUtil.hackBrightness(background, 1, 1 / 1.03F);
|
||||
}
|
||||
return background;
|
||||
}
|
||||
|
||||
private static void selectSearchResultsInEditor(@NotNull Editor editor, @NotNull Iterator<TextRange> resultIterator) {
|
||||
if (!editor.getCaretModel().supportsMultipleCarets()) {
|
||||
return;
|
||||
|
||||
@@ -472,10 +472,10 @@ command.select.all=Select All
|
||||
message.no.targets.available=No targets available in this context
|
||||
title.popup.select.target=Select In
|
||||
title.popup.recent.files=Recent Files
|
||||
recent.locations.popup.title=Recent locations
|
||||
recent.locations.changed.locations=Recent changed locations
|
||||
recent.locations.popup.title=Recent Locations
|
||||
recent.locations.changed.locations=Recent Changed Locations
|
||||
recent.locations.popup.empty.text=No recent locations found
|
||||
recent.locations.title.text=Changed locations ({0})
|
||||
recent.locations.title.text=Show Changed Locations {0}
|
||||
action.split.vertically=Split _Vertically
|
||||
action.split.horizontally=Split Hori_zontally
|
||||
action.sync.completed.successfully={0} completed successfully.
|
||||
|
||||
Reference in New Issue
Block a user