cleanup, prepare to fix WEB-9756 Quick evaluate expression popup: long values are cut and cannot be copy correctly

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
This commit is contained in:
Vladimir Krivosheev
2014-02-06 13:09:25 +01:00
parent 882965b8e4
commit cd527f01a6
6 changed files with 48 additions and 43 deletions
@@ -205,7 +205,7 @@ public class ImageOrColorPreviewManager implements Disposable, EditorMouseMotion
}
elementRef = new WeakReference<PsiElement>(element);
for (ElementPreviewProvider provider : Extensions.getExtensions(ElementPreviewProvider.EP_NAME)) {
for (ElementPreviewProvider provider : ElementPreviewProvider.EP_NAME.getExtensions()) {
try {
provider.show(element, editor, point, keyTriggered);
}
@@ -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();
@@ -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);
@@ -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);
}
@@ -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);
}
@@ -190,6 +190,7 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
return null;
}
@Override
@Nullable
public String getName() {
return myName;
@@ -200,11 +201,13 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
return myValuePresentation;
}
@Override
@Nullable
public String getRawValue() {
return myRawValue;
}
@Override
public boolean isComputed() {
return myValuePresentation != null;
}