Skip to content

Commit

Permalink
A first try at tooltips that display the originating module and use r…
Browse files Browse the repository at this point in the history
…ich text (rather than just plain or bold).
  • Loading branch information
Oblosys committed Jul 18, 2012
1 parent 796ee57 commit 1a2fa29
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 24 deletions.
Expand Up @@ -6,6 +6,8 @@


import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.AbstractInformationControl; import org.eclipse.jface.text.AbstractInformationControl;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.util.Geometry; import org.eclipse.jface.util.Geometry;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser; import org.eclipse.swt.browser.Browser;
Expand All @@ -20,9 +22,11 @@
* @author Alejandro Serrano * @author Alejandro Serrano
* *
*/ */
@Deprecated
public class HaskellInformationControl extends AbstractInformationControl { public class HaskellInformationControl extends AbstractInformationControl {


private static final int HOVER_WIDTH = 600; // size of the tooltip for
private static final int HOVER_HEIGHT = 80; // type info and errors/warnings

private Browser doc; private Browser doc;
private boolean hasContents = false; private boolean hasContents = false;


Expand All @@ -40,16 +44,16 @@ public void setInformation( final String content ) {
protected void createContent( final Composite parent ) { protected void createContent( final Composite parent ) {
doc = new Browser( parent, SWT.NONE ); doc = new Browser( parent, SWT.NONE );


//doc.setForeground( parent.getForeground() ); // These have no effect, so we set the colors with css.
//doc.setBackground( parent.getBackground() ); // Unfortunately, the background remains white, which is sometimes visible when scrolling
doc.setForeground( parent.getDisplay().getSystemColor( SWT.COLOR_INFO_FOREGROUND ) ); doc.setForeground( parent.getDisplay().getSystemColor( SWT.COLOR_INFO_FOREGROUND ) );
doc.setBackground( parent.getDisplay().getSystemColor( SWT.COLOR_INFO_BACKGROUND ) ); doc.setBackground( parent.getDisplay().getSystemColor( SWT.COLOR_YELLOW ) );
doc.setFont( JFaceResources.getDialogFont() ); doc.setFont( JFaceResources.getTextFont() );
} }


public void setDocumentation( final String content ) { public void setDocumentation( final String content ) {
hasContents = content.length() > 0; hasContents = content.length() > 0;
doc.setText( content ); doc.setText( "<html><body style=\"background-color: #fafbc5; margin:0; padding:0; font-size: 8pt\">"+content+"<body></html>" );
} }


/* /*
Expand All @@ -64,6 +68,7 @@ public void setVisible( final boolean visible ) {
/* /*
* @see IInformationControl#computeSizeHint() * @see IInformationControl#computeSizeHint()
*/ */
/*
@Override @Override
public Point computeSizeHint() { public Point computeSizeHint() {
// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=117602 // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=117602
Expand All @@ -75,6 +80,18 @@ public Point computeSizeHint() {
return getShell().computeSize( widthHint, SWT.DEFAULT, true ); return getShell().computeSize( widthHint, SWT.DEFAULT, true );
} }
For some reason, the method above causes a very large tooltip to be generated, which is
briefly visible before it shrinks to its normal size. Unfortunately, this doesn't happen
on test runs, but only when the plug-in is deployed, making it extremely difficult to debug.
The problem doesn't seem to occur in Eclipse Juno.
For some other reason, everything works fine if we specify the size with computeSizeConstraints.
*/
@Override
public Point computeSizeConstraints(final int widthInChars, final int heightInChars) {
return new Point(HOVER_WIDTH,HOVER_HEIGHT);
}

/* /*
* @see org.eclipse.jface.text.AbstractInformationControl#computeTrim() * @see org.eclipse.jface.text.AbstractInformationControl#computeTrim()
*/ */
Expand Down Expand Up @@ -116,4 +133,22 @@ public void setFocus() {
doc.setFocus(); doc.setFocus();
} }


// Without this, the hover text disappears immediately on a mouse move.
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator()
* @since 3.4
*/
@Override
public IInformationControlCreator getInformationPresenterControlCreator() {
return new IInformationControlCreator() {
/*
* @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
*/
@Override
public IInformationControl createInformationControl(final Shell parent) {
return new HaskellInformationControl(parent);
}
};
}

} }
Expand Up @@ -11,10 +11,10 @@
import net.sf.eclipsefp.haskell.buildwrapper.types.ThingAtPoint; import net.sf.eclipsefp.haskell.buildwrapper.types.ThingAtPoint;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin; import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.imports.ImportsManager; import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.imports.ImportsManager;
import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
import net.sf.eclipsefp.haskell.ui.internal.util.UITexts; import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.DefaultTextHover; import org.eclipse.jface.text.DefaultTextHover;
import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IInformationControlCreator;
Expand Down Expand Up @@ -51,11 +51,11 @@ public String getHoverInfo( final ITextViewer textViewer,
final IRegion hoverRegion ) { final IRegion hoverRegion ) {
// TODO TtC this method does not get called when hovering over a string literal // TODO TtC this method does not get called when hovering over a string literal
// which leads to potential problem annotation hovers not appearing // which leads to potential problem annotation hovers not appearing
String hoverInfo = computeProblemInfo( textViewer, hoverRegion,fMarkerAnnotationAccess ); String hoverInfo = computeProblemInfo( textViewer, hoverRegion,fMarkerAnnotationAccess);
if (hoverInfo != null) { if (hoverInfo != null) {
return hoverInfo; return hoverInfo;
} }
return computeThingAtPoint( textViewer, hoverRegion,false ); return computeThingAtPoint( textViewer, hoverRegion,false );
} }


/* (non-Javadoc) /* (non-Javadoc)
Expand All @@ -64,7 +64,7 @@ public String getHoverInfo( final ITextViewer textViewer,
@Override @Override
public Object getHoverInfo2( final ITextViewer textViewer, public Object getHoverInfo2( final ITextViewer textViewer,
final IRegion hoverRegion) { final IRegion hoverRegion) {
String hoverInfo = computeProblemInfo( textViewer, hoverRegion,fMarkerAnnotationAccess ); String hoverInfo = computeProblemInfo( textViewer, hoverRegion,fMarkerAnnotationAccess);
if (hoverInfo != null) { if (hoverInfo != null) {
return hoverInfo; return hoverInfo;
} }
Expand All @@ -80,8 +80,8 @@ public IInformationControlCreator getHoverControlCreator() {


@Override @Override
public IInformationControl createInformationControl( final Shell parent ) { public IInformationControl createInformationControl( final Shell parent ) {
//return new HaskellInformationControl(parent,editor.getFont()); return new HaskellInformationControl(parent);
return new DefaultInformationControl( parent, false ); //return new DefaultInformationControl( parent, false ); // for bold-only tooltips
} }
} ; } ;
} }
Expand All @@ -100,7 +100,9 @@ public static String computeProblemInfo( final ITextViewer textViewer, final IRe
fMarkerAnnotationAccess.isSubtype( type, WARNING_ANNOTATION_TYPE )) { fMarkerAnnotationAccess.isSubtype( type, WARNING_ANNOTATION_TYPE )) {
Position p = annotationModel.getPosition( a ); Position p = annotationModel.getPosition( a );
if (p.overlapsWith( hoverRegion.getOffset(), hoverRegion.getLength() )) { if (p.overlapsWith( hoverRegion.getOffset(), hoverRegion.getLength() )) {
return a.getText(); return "<div style='font-family: verdana; padding:2px'>" +
a.getText() +
"</div>";
} }
} }
} }
Expand All @@ -123,26 +125,36 @@ protected String computeThingAtPoint( final ITextViewer textViewer, final IRegio
ThingAtPoint tap=f.getThingAtPoint(file,location); ThingAtPoint tap=f.getThingAtPoint(file,location);
if (tap!=null){ if (tap!=null){
StringBuilder sb=new StringBuilder(); StringBuilder sb=new StringBuilder();


sb.append(html ? "<div style='font-family: monaco; padding:2px'>" : "");
sb.append(tap.getName()); sb.append(tap.getName());
String moduleColor = HaskellUIPlugin.getDefault().getPreferenceStore().getString( IEditorPreferenceNames.EDITOR_CON_COLOR );

if (tap.getType()!=null){ if (tap.getType()!=null){
sb.append(" :: "); sb.append(" :: ");
sb.append(html ? "<b>" : "");
sb.append(tap.getType()); sb.append(tap.getType());
sb.append(html ? "</b>" : "");
} }
if(html){ if (tap.getModule()!=null){
sb.insert( 0, "<b>" ); sb.append(html ? "<br/>" : "\n");
sb.append( "</b>" ); sb.append(html ? "<span style='color: grey'>module:</span> <span style='color:rgb("+moduleColor+"); font-weight: bold'>" : "");
sb.append(tap.getModule());
sb.append(html ? "</span>" : "");
} }
sb.append(html ? "</div>" : "");


ImportsManager im=editor.getImportsManager(); ImportsManager im=editor.getImportsManager();
Documented d=im.getDeclarations().get( tap.getName() ); Documented d=im.getDeclarations().get( tap.getName() );
if (d!=null && d.getDoc()!=null && d.getDoc().length()>0){ if (d!=null && d.getDoc()!=null && d.getDoc().length()>0){
if(html){ sb.append(html ? "<hr/>" : "\n");
sb.append( "<br/>" ); sb.append(html ? "<div style='font-family: verdana; padding:2px'>" : "");
} else {
sb.append("\n");
}
sb.append(d.getDoc()); sb.append(d.getDoc());
sb.append(html ? "</div>" : "");

} }

return sb.toString(); return sb.toString();
} }
//} finally { //} finally {
Expand Down

0 comments on commit 1a2fa29

Please sign in to comment.