From cd527f01a6e1d2c2b4e8e9d2ecf37baaf117b439 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 6 Feb 2014 11:30:27 +0100 Subject: [PATCH] cleanup, prepare to fix WEB-9756 Quick evaluate expression popup: long values are cut and cannot be copy correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit don't set timeout for hint — our platform is not smart, hint will be hidden even if mouse over hint. In any case other flags are enough to hide hint on user activity --- .../preview/ImageOrColorPreviewManager.java | 2 +- .../codeInsight/hint/HintManagerImpl.java | 5 +- .../intellij/codeInsight/hint/HintUtil.java | 4 +- .../impl/evaluate/quick/XValueHint.java | 7 +- .../quick/common/AbstractValueHint.java | 70 +++++++++---------- .../impl/ui/tree/nodes/XValueNodeImpl.java | 3 + 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java index 779f6697f47b..5c023dafd1b9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/preview/ImageOrColorPreviewManager.java @@ -205,7 +205,7 @@ public class ImageOrColorPreviewManager implements Disposable, EditorMouseMotion } elementRef = new WeakReference(element); - for (ElementPreviewProvider provider : Extensions.getExtensions(ElementPreviewProvider.EP_NAME)) { + for (ElementPreviewProvider provider : ElementPreviewProvider.EP_NAME.getExtensions()) { try { provider.show(element, editor, point, keyTriggered); } diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java index c3be5108c4ae..d8e4246c47ac 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintManagerImpl.java @@ -332,10 +332,9 @@ public class HintManagerImpl extends HintManager implements Disposable { }); } - final HintInfo info = new HintInfo(hint, flags, reviveOnEditorChange); - myHintsStack.add(info); + myHintsStack.add(new HintInfo(hint, flags, reviveOnEditorChange)); if (timeout > 0) { - Timer timer = UIUtil.createNamedTimer("Hint timeout",timeout, new ActionListener() { + Timer timer = UIUtil.createNamedTimer("Hint timeout", timeout, new ActionListener() { @Override public void actionPerformed(ActionEvent event) { hint.hide(); diff --git a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java index ddb790b2ba11..64a64a7f695d 100644 --- a/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java +++ b/platform/platform-impl/src/com/intellij/codeInsight/hint/HintUtil.java @@ -90,6 +90,7 @@ public class HintUtil { @NotNull public static HintHint getInformationHint() { + //noinspection UseJBColor return new HintHint().setTextBg(INFORMATION_COLOR) .setTextFg(UIUtil.isUnderDarcula() ? UIUtil.getLabelForeground() : Color.black) .setFont(getBoldFont()) @@ -97,6 +98,7 @@ public class HintUtil { } public static CompoundBorder createHintBorder() { + //noinspection UseJBColor return BorderFactory.createCompoundBorder( new ColoredSideBorder(Color.white, Color.white, Color.gray, Color.gray, 1), BorderFactory.createEmptyBorder(2, 2, 2, 2) @@ -127,7 +129,7 @@ public class HintUtil { return label; } - public static JComponent createInformationLabel(final SimpleColoredText text, final Icon icon) { + public static JComponent createInformationLabel(@NotNull SimpleColoredText text, @Nullable Icon icon) { SimpleColoredComponent highlighted = new SimpleColoredComponent(); highlighted.setIcon(icon); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java index e9f8e04c13fe..d48b3b17b328 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/XValueHint.java @@ -85,7 +85,9 @@ public class XValueHint extends AbstractValueHint { public void applyPresentation(@Nullable Icon icon, @NotNull XValuePresentation valuePresenter, boolean hasChildren) { - if (isHintHidden()) return; + if (isHintHidden()) { + return; + } SimpleColoredText text = new SimpleColoredText(); text.append(myExpression, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES); @@ -114,8 +116,7 @@ public class XValueHint extends AbstractValueHint { @Override public boolean isObsolete() { - //todo[nik] - return false; + return isHintHidden(); } }, XValuePlace.TOOLTIP); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/AbstractValueHint.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/AbstractValueHint.java index f6b0cc2de57c..cf6e0348663f 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/AbstractValueHint.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/quick/common/AbstractValueHint.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -40,24 +40,25 @@ import java.util.EventObject; * @author nik */ public abstract class AbstractValueHint { - private static final Logger LOG = Logger.getInstance("#com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint"); - private static final Icon COLLAPSED_TREE_ICON = IconUtil.getAddIcon(); - private static final int HINT_TIMEOUT = 7000; // ms - private final KeyListener myEditorKeyListener = new KeyAdapter() { - @Override - public void keyReleased(KeyEvent e) { - if(!isAltMask(e.getModifiers())) { - ValueLookupManager.getInstance(myProject).hideHint(); - } - } - }; + private static final Logger LOG = Logger.getInstance(AbstractValueHint.class); + private static final TextAttributes ourReferenceAttributes = new TextAttributes(); + static { ourReferenceAttributes.setForegroundColor(JBColor.BLUE); ourReferenceAttributes.setEffectColor(JBColor.BLUE); ourReferenceAttributes.setEffectType(EffectType.LINE_UNDERSCORE); } + private final KeyListener myEditorKeyListener = new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + if (!isAltMask(e.getModifiers())) { + ValueLookupManager.getInstance(myProject).hideHint(); + } + } + }; + private RangeHighlighter myHighlighter; private Cursor myStoredCursor; private final Project myProject; @@ -83,19 +84,20 @@ public abstract class AbstractValueHint { protected abstract void evaluateAndShowHint(); public boolean isKeepHint(Editor editor, Point point) { - if (myCurrentHint != null && myCurrentHint.canControlAutoHide()) return true; + if (myCurrentHint != null && myCurrentHint.canControlAutoHide()) { + return true; + } - if(myType == ValueHintType.MOUSE_ALT_OVER_HINT) { + if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) { return false; } - else if(myType == ValueHintType.MOUSE_CLICK_HINT) { - if(myCurrentHint != null && myCurrentHint.isVisible()) { + else if (myType == ValueHintType.MOUSE_CLICK_HINT) { + if (myCurrentHint != null && myCurrentHint.isVisible()) { return true; } } else { int offset = calculateOffset(editor, point); - if (myCurrentRange != null && myCurrentRange.getStartOffset() <= offset && offset <= myCurrentRange.getEndOffset()) { return true; } @@ -111,7 +113,7 @@ public abstract class AbstractValueHint { public void hideHint() { myHintHidden = true; myCurrentRange = null; - if(myStoredCursor != null) { + if (myStoredCursor != null) { Component internalComponent = myEditor.getContentComponent(); internalComponent.setCursor(myStoredCursor); if (LOG.isDebugEnabled()) { @@ -120,11 +122,11 @@ public abstract class AbstractValueHint { internalComponent.removeKeyListener(myEditorKeyListener); } - if(myCurrentHint != null) { + if (myCurrentHint != null) { myCurrentHint.hide(); myCurrentHint = null; } - if(myHighlighter != null) { + if (myHighlighter != null) { myHighlighter.dispose(); myHighlighter = null; } @@ -133,7 +135,7 @@ public abstract class AbstractValueHint { public void invokeHint(Runnable hideRunnable) { myHideRunnable = hideRunnable; - if(!canShowHint()) { + if (!canShowHint()) { hideHint(); return; } @@ -171,7 +173,6 @@ public abstract class AbstractValueHint { return myType; } - protected boolean showHint(final JComponent component) { myCurrentHint = new LightweightHint(component); myCurrentHint.addHintListener(new HintListener() { @@ -183,17 +184,17 @@ public abstract class AbstractValueHint { } }); - //Editor may be disposed before later invokator process this action - final Editor editor = getEditor(); - final JRootPane rootPane = editor.getComponent().getRootPane(); - if(rootPane == null) return false; + // editor may be disposed before later invokator process this action + if (myEditor.isDisposed() || myEditor.getComponent().getRootPane() == null) { + return false; + } - Point p = HintManagerImpl.getHintPosition(myCurrentHint, editor, editor.xyToLogicalPosition(myPoint), HintManager.UNDER); - final HintHint hintHint = HintManagerImpl.createHintHint(editor, p, myCurrentHint, HintManager.UNDER, true); - - HintManagerImpl.getInstanceImpl().showEditorHint(myCurrentHint, editor, p, - HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, HINT_TIMEOUT, false, - hintHint); + Point p = HintManagerImpl.getHintPosition(myCurrentHint, myEditor, myEditor.xyToLogicalPosition(myPoint), HintManager.UNDER); + HintManagerImpl.getInstanceImpl().showEditorHint(myCurrentHint, myEditor, p, + HintManager.HIDE_BY_ANY_KEY | + HintManager.HIDE_BY_TEXT_CHANGE | + HintManager.HIDE_BY_SCROLLING, 0, false, + HintManagerImpl.createHintHint(myEditor, p, myCurrentHint, HintManager.UNDER, true)); return true; } @@ -202,7 +203,7 @@ public abstract class AbstractValueHint { } protected JComponent createExpandableHintComponent(final SimpleColoredText text, final Runnable expand) { - final JComponent component = HintUtil.createInformationLabel(text, COLLAPSED_TREE_ICON); + final JComponent component = HintUtil.createInformationLabel(text, IconUtil.getAddIcon()); addClickListenerToHierarchy(component, new ClickListener() { @Override public boolean onClick(MouseEvent event, int clickCount) { @@ -219,8 +220,7 @@ public abstract class AbstractValueHint { private static void addClickListenerToHierarchy(Component c, ClickListener l) { l.installOn(c); if (c instanceof Container) { - final Container container = (Container)c; - Component[] children = container.getComponents(); + Component[] children = ((Container)c).getComponents(); for (Component child : children) { addClickListenerToHierarchy(child, l); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java index 75f927ee91f1..ea1a2fdd2332 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/XValueNodeImpl.java @@ -190,6 +190,7 @@ public class XValueNodeImpl extends XValueContainerNode implements XValu return null; } + @Override @Nullable public String getName() { return myName; @@ -200,11 +201,13 @@ public class XValueNodeImpl extends XValueContainerNode implements XValu return myValuePresentation; } + @Override @Nullable public String getRawValue() { return myRawValue; } + @Override public boolean isComputed() { return myValuePresentation != null; }