From e7ec0c6c4866de68ea1d02061992cd5ea5381853 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 2 May 2018 14:46:55 +0200 Subject: [PATCH] IDEA-187518 Support italic in completion lookup element item text --- .../codeInsight/lookup/LookupElementBuilder.java | 10 ++++++++++ .../codeInsight/lookup/LookupElementPresentation.java | 10 ++++++++++ .../codeInsight/lookup/impl/LookupCellRenderer.java | 9 ++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java index ba39aa60b1e3..e971874cd397 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java @@ -238,6 +238,16 @@ public final class LookupElementBuilder extends LookupElement { return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation, myPsiElement, myAllLookupStrings, myCaseSensitive); } + /** + * @since 2018.2 + */ + @Contract(pure=true) + public LookupElementBuilder withItemTextItalic(boolean italic) { + final LookupElementPresentation presentation = copyPresentation(); + presentation.setItemTextItalic(italic); + return new LookupElementBuilder(myLookupString, myObject, myInsertHandler, null, presentation, myPsiElement, myAllLookupStrings, myCaseSensitive); + } + /** * @deprecated use {@link #withTypeText(String)} */ diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java index 515273778b8e..8d3f3d106d35 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java @@ -40,6 +40,7 @@ public class LookupElementPresentation { private Color myItemTextForeground = JBColor.foreground(); private boolean myItemTextBold; private boolean myItemTextUnderlined; + private boolean myItemTextItalic; private boolean myTypeGrayed; @Nullable private List myTail; @@ -59,6 +60,10 @@ public class LookupElementPresentation { myItemTextBold = bold; } + public void setItemTextItalic(boolean itemTextItalic) { + myItemTextItalic = itemTextItalic; + } + public void setTailText(@Nullable String text) { setTailText(text, false); } @@ -165,6 +170,10 @@ public class LookupElementPresentation { return myItemTextBold; } + public boolean isItemTextItalic() { + return myItemTextItalic; + } + public boolean isItemTextUnderlined() { return myItemTextUnderlined; } @@ -192,6 +201,7 @@ public class LookupElementPresentation { myTypeText = presentation.myTypeText; myStrikeout = presentation.myStrikeout; myItemTextBold = presentation.myItemTextBold; + myItemTextItalic = presentation.myItemTextItalic; myTypeGrayed = presentation.myTypeGrayed; myTypeIconRightAligned = presentation.myTypeIconRightAligned; myItemTextUnderlined = presentation.myItemTextUnderlined; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java index e83b13ab8a2e..ffea30063054 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java @@ -261,7 +261,7 @@ public class LookupCellRenderer implements ListCellRenderer { Color foreground, int allowedWidth, boolean nonFocusedSelection, FontMetrics fontMetrics) { - int style = getStyle(false, presentation.isStrikeout(), false); + int style = getStyle(false, presentation.isStrikeout(), false, false); for (LookupElementPresentation.TextFragment fragment : presentation.getTailFragments()) { if (allowedWidth < 0) { @@ -341,7 +341,7 @@ public class LookupCellRenderer implements ListCellRenderer { Font customItemFont = myLookup.getCustomFont(item, bold); myNameComponent.setFont(customItemFont != null ? customItemFont : bold ? myBoldFont : myNormalFont); - int style = getStyle(bold, presentation.isStrikeout(), presentation.isItemTextUnderlined()); + int style = getStyle(bold, presentation.isStrikeout(), presentation.isItemTextUnderlined(), presentation.isItemTextItalic()); final FontMetrics metrics = getRealFontMetrics(item, bold); final String name = trimLabelText(presentation.getItemText(), allowedWidth, metrics); @@ -361,7 +361,7 @@ public class LookupCellRenderer implements ListCellRenderer { } @SimpleTextAttributes.StyleAttributeConstant - private static int getStyle(boolean bold, boolean strikeout, boolean underlined) { + private static int getStyle(boolean bold, boolean strikeout, boolean underlined, boolean italic) { int style = bold ? SimpleTextAttributes.STYLE_BOLD : SimpleTextAttributes.STYLE_PLAIN; if (strikeout) { style |= SimpleTextAttributes.STYLE_STRIKEOUT; @@ -369,6 +369,9 @@ public class LookupCellRenderer implements ListCellRenderer { if (underlined) { style |= SimpleTextAttributes.STYLE_UNDERLINE; } + if (italic) { + style |= SimpleTextAttributes.STYLE_ITALIC; + } return style; }