Commit 0923cb20 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Implemented toolbar for HoverInfoControl


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 436d9f7d
......@@ -550,6 +550,9 @@ public final class Def_Type extends Definition {
super.getHoverContent(editor, assignment);
final CompilationTimeStamp timestamp = getLastTimeChecked();
if (timestamp == null) {
return null;
}
final IType varType = assignment.getType(timestamp);
if (varType instanceof Class_Type) {
......
......@@ -7,6 +7,9 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.controls;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.text.AbstractInformationControl;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
......@@ -15,11 +18,12 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.editors.actions.SwitchHoverWindowContentAction;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.keys.IBindingService;
/**
* Control for handling ttcn3 source editor hovers
......@@ -33,17 +37,17 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
private Shell fShell;
private boolean isRich;
private HoverContentType actualType = HoverContentType.loadAsProperty();
private ToolBarManager toolbar;
public Ttcn3HoverInfoControl(Shell parentShell, String string) {
super(parentShell, string);
createContent(parentShell);
create();
}
public Ttcn3HoverInfoControl(Shell parentShell, String string, boolean isRich) {
super(parentShell, isRich);
public Ttcn3HoverInfoControl(Shell parentShell, String string, boolean isRich, ToolBarManager toolbar) {
super(parentShell, toolbar);
this.toolbar = toolbar;
this.isRich = isRich;
createContent(parentShell);
create();
}
......@@ -72,19 +76,32 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
viewer.setEditable(false);
viewer.setBackground(fShell.getBackground());
if (isRich) {
String keyBinding= null;
IBindingService bindingService= PlatformUI.getWorkbench().getAdapter(IBindingService.class);
if (bindingService != null) {
keyBinding = bindingService.getBestActiveBindingFormattedFor(SwitchHoverWindowContentAction.getCommandId());
}
if (keyBinding == null) {
keyBinding = "<unbound>";
}
setStatusText("Press " + keyBinding + " for code view mode");
IAction infoAction = new Action("", IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
actualType = HoverContentType.INFO;
setHoverContentToActual();
}
};
IAction sourceAction = new Action("", IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
actualType = HoverContentType.SOURCE;
setHoverContentToActual();
}
};
infoAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
infoAction.setToolTipText("Switch to info view");
sourceAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
sourceAction.setToolTipText("Switch to source view");
ToolBar tb = toolbar.createControl(parent);
tb.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
toolbar.add(infoAction);
toolbar.add(sourceAction);
toolbar.update(true);
} else {
setStatusText("Hover to focus");
}
}
@Override
......@@ -92,7 +109,8 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
return new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(Shell parent) {
return new Ttcn3HoverInfoControl(parent, EditorsUI.getTooltipAffordanceString(), true);
ToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
return new Ttcn3HoverInfoControl(parent, EditorsUI.getTooltipAffordanceString(), true, toolbar);
}
};
}
......@@ -109,4 +127,11 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
}
}
}
private void setHoverContentToActual() {
viewer.setText(content.getText(actualType));
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
}
}
}
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