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

Added PeekDeclaration command (issue #449)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent e25dc99e
......@@ -197,6 +197,11 @@
id="org.eclipse.titan.designer.editors.asn1editor.ASN1GotoMatchingBracketAction"
name="Go to Matching Bracket">
</command>
<command
defaultHandler="org.eclipse.titan.designer.editors.ttcn3editor.actions.PeekDeclaration"
id="org.eclipse.titan.designer.editors.ttcn3editor.PeekDeclaration"
name="Peek Declaration">
</command>
</extension>
<extension
......@@ -606,6 +611,12 @@
id="org.eclipse.titan.designer.editors.ttcn3editor.RenameRefactoringAction"
label="Rename refactoring">
</command>
<command
commandId="org.eclipse.titan.designer.editors.ttcn3editor.PeekDeclaration"
icon="icons/titan.gif"
id="org.eclipse.titan.designer.editors.ttcn3editor.PeekDeclaration"
label="Peek Declaration">
</command>
</menuContribution>
<menuContribution
......@@ -1159,6 +1170,18 @@
name="Toggle Comment" />
<category id="org.eclipse.titan.designer.editors.TITANCommands"
name="TITAN Commands" />
<command
categoryId="org.eclipse.titan.designer.editors.TITANCommands"
description="Shows the source of the declaration in a popup"
id="org.eclipse.titan.designer.editors.ttcn3editor.OpenDeclaration"
name="Peek Declaration">
</command>
<command
categoryId="org.eclipse.titan.designer.editors.TITANCommands"
description="Peeks a declaration"
id="org.eclipse.titan.designer.editors.ttcn3editor.PeekDeclaration"
name="Peek declaration">
</command>
</extension>
<extension point="org.eclipse.ui.bindings">
<key commandId="org.eclipse.titan.designer.firstChar"
......@@ -1319,6 +1342,12 @@
contextId="org.eclipse.titan.designer.editors.TTCN3EditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+SHIFT+T" />
<key
commandId="org.eclipse.titan.designer.editors.ttcn3editor.PeekDeclaration"
contextId="org.eclipse.titan.designer.editors.TTCN3EditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F9">
</key>
</extension>
<extension point="org.eclipse.ui.contexts">
<context description="%context.editingText.description.testtest"
......
......@@ -39,7 +39,7 @@ public class Ttcn3SourceViewControl implements IInformationControl {
private int maxHeight = SWT.DEFAULT;
public Ttcn3SourceViewControl(Shell parent) {
myshell = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | SWT.TOOL | SWT.LEFT_TO_RIGHT | SWT.RESIZE);
myshell = new Shell(parent, SWT.ON_TOP | SWT.TOOL | SWT.LEFT_TO_RIGHT | SWT.RESIZE);
Composite composite = myshell;
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
......@@ -96,7 +96,8 @@ public class Ttcn3SourceViewControl implements IInformationControl {
@Override
public void setSize(int width, int height) {
myshell.setSize(width, height);
//myshell.setSize(width, height);
myshell.setSize(200, 200);
}
@Override
......@@ -142,8 +143,7 @@ public class Ttcn3SourceViewControl implements IInformationControl {
@Override
public void setFocus() {
// TODO Auto-generated method stub
myshell.setFocus();
}
@Override
......
/******************************************************************************
* 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.ttcn3editor.actions;
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.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type;
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.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.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* Action code for peek declaration feature
*
* @author Miklos Magyari
*
*/
public class PeekDeclaration extends AbstractHandler implements IEditorActionDelegate {
@Override
public void run(IAction action) {
peekDefinition();
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
// TODO Auto-generated method stub
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
peekDefinition();
return null;
}
@Override
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
// TODO Auto-generated method stub
}
private void peekDefinition() {
IEditorPart targetEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
ISelection selection = TextSelection.emptySelection();
if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
return;
}
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 {
offset = ((TTCN3Editor) targetEditor).getCarretOffset();
}
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
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;
}
final IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
module.accept(visitor);
final Declaration decl = visitor.getReferencedDeclaration();
if (decl == null) {
if (reportDebugInformation) {
TITANDebugConsole.println("No visible elements found");
}
return;
}
final Assignment ass = decl.getAssignment();
if (ass instanceof Def_Type) {
Shell shell = targetEditor.getSite().getShell();
if (targetEditor instanceof ITextEditor)
{
ITextEditor textEditor = (ITextEditor) targetEditor;
IDocumentProvider provider = textEditor.getDocumentProvider();
IEditorInput input = targetEditor.getEditorInput();
IDocument document = provider.getDocument(input);
Ttcn3SourceViewControl con = new Ttcn3SourceViewControl(shell);
Location loc = ass.getLocation();
StringBuilder code = new StringBuilder();
try {
for (int i = loc.getOffset(); i <= loc.getEndOffset(); i++) {
char c = document.getChar(i);
code.append(c);
}
} catch (Exception e) {
}
con.setInformation(code.toString());
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