Commit 251dc847 authored by Adam Knapp's avatar Adam Knapp
Browse files

Add size to content to hover window (issue #452)


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent 68c0e845
......@@ -17,6 +17,8 @@ import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
......@@ -38,13 +40,16 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
private boolean isRich;
private HoverContentType actualType = HoverContentType.loadAsProperty();
private ToolBarManager toolbar;
private int maxWidth = SWT.DEFAULT;
private int maxHeight = SWT.DEFAULT;
public Ttcn3HoverInfoControl(Shell parentShell, String string) {
super(parentShell, string);
create();
}
public Ttcn3HoverInfoControl(Shell parentShell, String string, boolean isRich, ToolBarManager toolbar) {
public Ttcn3HoverInfoControl(Shell parentShell, String string, final boolean isRich, final ToolBarManager toolbar) {
super(parentShell, toolbar);
this.toolbar = toolbar;
this.isRich = isRich;
......@@ -60,10 +65,11 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
@Override
public void setFocus() {
super.setFocus();
if (fShell != null)
if (fShell != null) {
fShell.setFocus();
}
}
@Override
public boolean hasContents() {
return content != null;
......@@ -80,14 +86,18 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
@Override
public void run() {
actualType = HoverContentType.INFO;
HoverContentType.storeAsProperty(actualType);
setHoverContentToActual();
setSize(computeSizeHint());
}
};
IAction sourceAction = new Action("", IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
actualType = HoverContentType.SOURCE;
HoverContentType.storeAsProperty(actualType);
setHoverContentToActual();
setSize(computeSizeHint());
}
};
infoAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
......@@ -103,7 +113,7 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
setStatusText("Hover to focus");
}
}
@Override
public IInformationControlCreator getInformationPresenterControlCreator() {
return new IInformationControlCreator() {
......@@ -116,7 +126,7 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
}
@Override
public void setInput(Object input) {
public void setInput(final Object input) {
if (input instanceof Ttcn3HoverContent) {
content = (Ttcn3HoverContent)input;
if (content.hasText(actualType)) {
......@@ -124,9 +134,8 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
}
}
}
private void setHoverContentToActual() {
HoverContentType.storeAsProperty(actualType);
final String text = content.getText(actualType);
if (text != null) {
viewer.setText(text);
......@@ -135,4 +144,30 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
}
}
}
@Override
public void setSizeConstraints(final int maxWidth, final int maxHeight) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
}
@Override
public Point computeSizeHint() {
fShell.layout();
return fShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
}
@Override
public void setSize(final int width, final int height) {
fShell.layout();
final Rectangle displayRect = fShell.getDisplay().getClientArea();
final Rectangle shellRect = fShell.getBounds();
maxWidth = displayRect.width - shellRect.x;
maxHeight = displayRect.height - shellRect.y;
fShell.setSize(Math.min(width + 10, maxWidth), Math.min(height + 10, maxHeight));
}
public void setSize(Point size) {
setSize(size.x, size.y);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment