Commit 6669aacb authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Initial support form marker hovers in Ttcn3HoverInfoControl


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent dcac2eee
......@@ -25,7 +25,10 @@ import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.LineRange;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.editors.controls.MarkerHoverContent;
import org.eclipse.titan.designer.editors.controls.MarkerHoverInfoControl;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.MarkerAnnotation;
/**
......@@ -84,7 +87,7 @@ public final class AnnotationHover implements IAnnotationHover, IAnnotationHover
return new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(Shell parent) {
return new MarkerHoverInfoControl(parent, true);
return new Ttcn3HoverInfoControl(parent, EditorsUI.getTooltipAffordanceString());
}
};
}
......@@ -108,8 +111,7 @@ public final class AnnotationHover implements IAnnotationHover, IAnnotationHover
}
}
}
IDocument document = new Document(builder.toString());
return document;
return new MarkerHoverContent(builder.toString());
}
@Override
......
package org.eclipse.titan.designer.editors.controls;
/**
* This class represents information to be displayed for marker hovers
*
* Used for ttcn3 editor annotation hover support returned by getHoverInfo as an 'object'
*
* @author Miklos Magyari
*/
public class MarkerHoverContent {
private String text;
public MarkerHoverContent(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.editors.controls;
import org.eclipse.jface.text.AbstractInformationControl;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
/**
* Control for handling ttcn3 editor error marker hovers
*
* @author Miklos Magyari
*
*/
public class MarkerHoverInfoControl extends AbstractInformationControl implements IInformationControlExtension2 {
private Shell fShell;
private TextViewer viewer;
private IDocument content;
public MarkerHoverInfoControl(Shell parentShell, boolean isResizable) {
super(parentShell, isResizable);
create();
}
@Override
public boolean hasContents() {
return content != null;
}
@Override
public void setInput(Object input) {
if (input instanceof IDocument) {
content = (IDocument)input;
}
viewer.setDocument(content);
}
@Override
protected void createContent(Composite parent) {
fShell = parent.getShell();
viewer = new TextViewer(fShell, 0);
viewer.setEditable(false);
}
}
......@@ -29,15 +29,21 @@ import org.eclipse.ui.editors.text.EditorsUI;
* Control for handling ttcn3 source editor hovers
*
* @author Miklos Magyari
* @author Adam Knapp
*
*/
public class Ttcn3HoverInfoControl extends AbstractInformationControl implements IInformationControlExtension2 {
private enum ViewMode { CodeHover, MarkerHover }
private StyledText viewer;
private Ttcn3HoverContent content;
private MarkerHoverContent markerContent;
private Shell fShell;
private boolean isRich;
private HoverContentType actualType = HoverContentType.loadAsProperty();
private ToolBarManager toolbar;
private ViewMode viewMode;
private Composite fParent;
private int maxWidth = SWT.DEFAULT;
private int maxHeight = SWT.DEFAULT;
......@@ -90,26 +96,18 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
@Override
public boolean hasContents() {
return content != null;
return content != null || markerContent != null;
}
@Override
protected void createContent(Composite parent) {
fParent = parent;
fShell = parent.getShell();
viewer = new StyledText(parent, isRich ? (SWT.H_SCROLL | SWT.V_SCROLL) : 0);
viewer.setEditable(false);
viewer.setBackground(fShell.getBackground());
if (isRich) {
final ToolBar tb = toolbar.createControl(parent);
tb.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
tb.setForeground(fShell.getDisplay().getSystemColor(SWT.COLOR_LINK_FOREGROUND));
switchAction.setText(getButtonText());
toolbar.add(switchAction);
toolbar.update(true);
toolbarTextSize = tb.getSize().x;
} else {
setStatusText("Hover to focus");
}
setStatusText("Hover to focus");
}
@Override
......@@ -117,7 +115,7 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
return new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(Shell parent) {
ToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
ToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.VERTICAL);
return new Ttcn3HoverInfoControl(parent, EditorsUI.getTooltipAffordanceString(), true, toolbar);
}
};
......@@ -126,19 +124,52 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
@Override
public void setInput(final Object input) {
if (input instanceof Ttcn3HoverContent) {
viewMode = ViewMode.CodeHover;
content = (Ttcn3HoverContent)input;
if (content.hasText(actualType)) {
setHoverContentToActual();
}
}
if (input instanceof MarkerHoverContent) {
viewMode = ViewMode.MarkerHover;
markerContent = (MarkerHoverContent)input;
setHoverContentToActual();
}
}
private void setHoverContentToActual() {
final String text = content.getText(actualType);
if (text != null) {
viewer.setText(text);
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
switch (viewMode) {
case CodeHover:
final String text = content.getText(actualType);
if (text != null) {
viewer.setText(text);
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
}
};
if (isRich) {
if (toolbar != null) {
final ToolBar tb = toolbar.createControl(fParent);
tb.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
tb.setForeground(fShell.getDisplay().getSystemColor(SWT.COLOR_LINK_FOREGROUND));
switchAction.setText(getButtonText());
toolbar.add(switchAction);
tb.setSize(SWT.DEFAULT, 30);
toolbar.update(true);
toolbarTextSize = tb.getSize().x;
}
}
break;
case MarkerHover:
final String markersText = markerContent.getText();
if (markersText != null) {
viewer.setText(markersText);
}
if (isRich) {
if (toolbar != null) {
// add proposals here
}
}
}
}
......
......@@ -31,6 +31,7 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.IHoverContent;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.MarkerHoverContent;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
......@@ -103,7 +104,7 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
final IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
if (annotationModel != null) {
final Iterator<?> iterator = annotationModel.getAnnotationIterator();
Ttcn3HoverContent markerInfo = null;
StringBuilder markerInfo = new StringBuilder();
while (iterator.hasNext()) {
final Object o = iterator.next();
if (o instanceof MarkerAnnotation) {
......@@ -116,14 +117,13 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
ErrorReporter.INTERNAL_ERROR("The marker at " + markerPosition.getOffset() + " does not seem to have any text");
}
if (markerInfo == null) {
markerInfo = new Ttcn3HoverContent();
// FIXME error handling
}
markerInfo.addText(message);
markerInfo.append(message);
}
}
if (markerInfo != null) {
markerInfo.addContent(HoverContentType.INFO);
return markerInfo;
if (markerInfo.length() > 0) {
return new MarkerHoverContent(markerInfo.toString());
}
}
}
......
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