Commit ed840a52 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Refactored hover and peek source part 2


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 5bd89d4e
......@@ -81,9 +81,9 @@ public class PeekSource {
return null;
}
public static void addStyledSource(String source, Ttcn3HoverContent viewer) {
public static void addStyledSource(String source, Ttcn3HoverContent content) {
if (source == null) {
viewer.addContent(ContentType.Source, source, null);
content.addContent(ContentType.Source, source, null);
return;
}
......@@ -154,6 +154,6 @@ public class PeekSource {
ranges.add(range);
}
viewer.addContent(ContentType.Source, source, ranges);;
content.addContent(ContentType.Source, source, ranges);;
}
}
......@@ -14,32 +14,44 @@ import java.util.Map;
import org.eclipse.swt.custom.StyleRange;
/**
* This class represents a styled text
* This class represents a collection of strings with style ranges
* Used for ttcn3 editor hover support returned by getHoverInfo2 as an 'object'
*
* @author Miklos Magyari
*/
public class Ttcn3HoverContent {
private class Entry {
public enum ContentType { Info, Source };
private class ContentEntry {
String text;
List<StyleRange> ranges;
Entry(String text, List<StyleRange> ranges) {
ContentEntry(String text, List<StyleRange> ranges) {
this.text = text;
this.ranges = ranges;
}
}
public enum ContentType { Info, Source };
private Map<ContentType, Entry> map = new HashMap<ContentType, Entry>();
private Map<ContentType, ContentEntry> map = new HashMap<ContentType, ContentEntry>();
public void addContent(ContentType type, String text, List<StyleRange> range) {
final Entry mapentry = new Entry(text, range);
final ContentEntry mapentry = new ContentEntry(text, range);
map.put(type, mapentry);
}
public boolean hasText(ContentType type) {
final ContentEntry mapentry = map.get(type);
if (mapentry == null) {
return false;
}
if (mapentry.text == null) {
return false;
}
return true;
}
public String getText(ContentType type) {
final Entry mapentry = map.get(type);
final ContentEntry mapentry = map.get(type);
if (mapentry == null) {
return null;
}
......@@ -47,7 +59,7 @@ public class Ttcn3HoverContent {
}
public List<StyleRange> getRanges(ContentType type) {
final Entry mapentry = map.get(type);
final ContentEntry mapentry = map.get(type);
if (mapentry == null) {
return null;
}
......
......@@ -14,10 +14,6 @@ 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.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.editors.actions.SwitchHoverWindowContentAction;
......@@ -89,14 +85,7 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
} else {
setStatusText("Hover to focus");
}
fShell.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
// TODO Auto-generated method stub
int i = 0;
}
});
}
@Override
......@@ -113,9 +102,11 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
public void setInput(Object input) {
if (input instanceof Ttcn3HoverContent) {
content = (Ttcn3HoverContent)input;
viewer.setText(content.getText(actualType));
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
if (content.hasText(actualType)) {
viewer.setText(content.getText(actualType));
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
}
}
}
}
......
......@@ -321,7 +321,9 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
addStyledText(sb, styles, body.getIdentifier().getDisplayName(), boldRange());
sb.append("\n\n");
addClassMembers(sb, styles, dc, timestamp, body);
addAuthors(sb, styles, dc);
if (dc != null) {
addAuthors(sb, styles, dc);
}
}
private void addClassMembers(StringBuilder sb, List<StyleRange> styles, DocumentComment dc, CompilationTimeStamp timestamp, ClassTypeBody body) {
......
......@@ -11,8 +11,6 @@ import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.TextSelection;
......@@ -24,17 +22,13 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.consoles.TITANDebugConsole;
import org.eclipse.titan.designer.declarationsearch.Declaration;
import org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3SourceViewControl;
import org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.GlobalParser;
import org.eclipse.titan.designer.parsers.ProjectSourceParser;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.titan.designer.productUtilities.ProductConstants;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
......@@ -79,16 +73,8 @@ public class PeekDeclaration extends AbstractHandler implements IEditorActionDel
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
final IPreferencesService prefs = Platform.getPreferencesService();
final boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION,
true, null);
int offset;
if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
final TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
......@@ -99,16 +85,6 @@ public class PeekDeclaration extends AbstractHandler implements IEditorActionDel
final Module module = projectSourceParser.containedModule(file);
if (module == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("The file " + file.getLocation() + "does not seem to contain a valid module.");
final CompilationTimeStamp timestamp = projectSourceParser.getLastTimeChecked();
if(timestamp == null) {
TITANDebugConsole.println("The project " + file.getProject() + " was not yet analyzed semantically");
} else {
TITANDebugConsole.println("The project " + file.getProject() + " was last checked in " + projectSourceParser.getLastTimeChecked().toString());
}
}
return;
}
......
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