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

Added code peek support for definitions located in external files


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 4d7a4607
......@@ -120,7 +120,7 @@ public class Ttcn3SourceViewControl implements IInformationControl, IInformation
if (token.getData() instanceof TextAttribute) {
TextAttribute attrib = (TextAttribute)token.getData();
//range.fontStyle = attrib.getFont()
range.fontStyle = attrib.getStyle();
range.foreground = attrib.getForeground();
}
......
......@@ -7,14 +7,19 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor.actions;
import java.io.File;
import java.io.RandomAccessFile;
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.resources.IResource;
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.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
......@@ -138,13 +143,41 @@ public class PeekDeclaration extends AbstractHandler implements IEditorActionDel
codeLoc = ass.getLocation();
}
if (codeLoc != null) {
final IResource fileToLoad = codeLoc.getFile();
IResource actual = (IResource)file;
Shell shell = targetEditor.getSite().getShell();
String codeText = null;
if (targetEditor instanceof ITextEditor)
{
ITextEditor textEditor = (ITextEditor) targetEditor;
IDocumentProvider provider = textEditor.getDocumentProvider();
IEditorInput input = targetEditor.getEditorInput();
IDocument document = provider.getDocument(input);
IDocument document;
if (actual.getFullPath().equals(fileToLoad.getFullPath())) {
document = provider.getDocument(input);
StringBuilder code = new StringBuilder();
try {
for (int i = codeLoc.getOffset(); i <= codeLoc.getEndOffset(); i++) {
char c = document.getChar(i);
code.append(c);
}
} catch (Exception e) {
return;
}
codeText = code.toString();
} else {
// external file
try {
RandomAccessFile f2 = new RandomAccessFile(fileToLoad.getLocation().toString(), "r");
final int size = codeLoc.getEndOffset() - codeLoc.getOffset();
byte[] buffer = new byte[size + 1];
f2.seek(codeLoc.getOffset());
f2.read(buffer, 0, size);
codeText = new String(buffer);
} catch (Exception e) {
return;
}
}
Ttcn3SourceViewControl con = Ttcn3SourceViewControl.getInstance();
con.createControl(shell);
......@@ -160,16 +193,7 @@ public class PeekDeclaration extends AbstractHandler implements IEditorActionDel
con.setLocation(displayLocation);
}
StringBuilder code = new StringBuilder();
try {
for (int i = codeLoc.getOffset(); i <= codeLoc.getEndOffset(); i++) {
char c = document.getChar(i);
code.append(c);
}
} catch (Exception e) {
}
con.setInformation(code.toString());
con.setInformation(codeText);
con.setVisible(true);
con.setFocus();
}
......
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