Search in sources :

Example 1 with TTCNPPEditor

use of org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor in project titan.EclipsePlug-ins by eclipse.

the class GotoMatchingBracketAction method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof TTCNPPEditor) {
        this.targetEditor = (TTCNPPEditor) activeEditor;
    } else {
        this.targetEditor = null;
    }
    if (activeEditor == null) {
        return null;
    }
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                return null;
            }
        }
    }
    IDocument document = this.targetEditor.getDocument();
    int carretOffset = this.targetEditor.getCarretOffset();
    PairMatcher pairMatcher = new PairMatcher();
    IRegion region = pairMatcher.match(document, carretOffset);
    if (region == null) {
        return null;
    }
    int targetOffset;
    if (region.getOffset() + 1 == carretOffset) {
        targetOffset = region.getOffset() + region.getLength();
    } else {
        targetOffset = region.getOffset() + 1;
    }
    this.targetEditor.setCarretOffset(targetOffset);
    this.targetEditor.selectAndReveal(targetOffset, 0);
    return null;
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) PairMatcher(org.eclipse.titan.designer.editors.ttcnppeditor.PairMatcher) TextSelection(org.eclipse.jface.text.TextSelection) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with TTCNPPEditor

use of org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor in project titan.EclipsePlug-ins by eclipse.

the class IndentAction method performEdits.

@Override
protected void performEdits(final RewriteSessionEditProcessor processor) throws BadLocationException {
    MonoReconciler reconciler = ((TTCNPPEditor) getTargetEditor()).getReconciler();
    reconciler.setIsIncrementalReconciler(false);
    processor.performEdits();
    IPreferencesService prefs = Platform.getPreferencesService();
    reconciler.setIsIncrementalReconciler(prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEINCREMENTALPARSING, false, null));
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 3 with TTCNPPEditor

use of org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method doOpenDeclaration.

private final void doOpenDeclaration() {
    if (targetEditor == null || !(targetEditor instanceof TTCNPPEditor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    if (ResourceExclusionHelper.isExcluded(file)) {
        MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((TTCNPPEditor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("Can not find the module.");
        }
        return;
    }
    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;
    }
    selectAndRevealDeclaration(decl.getIdentifier().getLocation());
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) IFile(org.eclipse.core.resources.IFile) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) TextSelection(org.eclipse.jface.text.TextSelection) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 4 with TTCNPPEditor

use of org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor in project titan.EclipsePlug-ins by eclipse.

the class OrganizeFromEditor method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (editor == null || !(editor instanceof TTCN3Editor || editor instanceof TTCNPPEditor)) {
        ErrorReporter.logError("The editor is not found or not a Titan TTCN-3 editor");
        return null;
    }
    final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    TextFileChange change = null;
    try {
        change = OrganizeImports.organizeImportsChange(file);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace("Error while creating the needed import changes", e);
        return null;
    }
    try {
        change.perform(new NullProgressMonitor());
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace("Error while performing the needed import changes", e);
    }
    final IProject project = file.getProject();
    GlobalParser.getProjectSourceParser(project).reportOutdating(file);
    GlobalParser.getProjectSourceParser(project).analyzeAll();
    return null;
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IEditorPart(org.eclipse.ui.IEditorPart) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) IProject(org.eclipse.core.resources.IProject)

Aggregations

TTCNPPEditor (org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor)4 IFile (org.eclipse.core.resources.IFile)2 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)2 TextSelection (org.eclipse.jface.text.TextSelection)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 MonoReconciler (org.eclipse.jface.text.reconciler.MonoReconciler)1 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)1 Module (org.eclipse.titan.designer.AST.Module)1 Declaration (org.eclipse.titan.designer.declarationsearch.Declaration)1 IdentifierFinderVisitor (org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor)1 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)1 PairMatcher (org.eclipse.titan.designer.editors.ttcnppeditor.PairMatcher)1 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)1