Search in sources :

Example 31 with ITextViewerExtension

use of org.eclipse.jface.text.ITextViewerExtension in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method dispose.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IWorkbenchPart#dispose()
	 */
public void dispose() {
    // $NON-NLS-1$ //$NON-NLS-2$
    Logger.trace("Source Editor", "StructuredTextEditor::dispose entry");
    if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) {
        // $NON-NLS-1$
        System.out.println("Total calls to getAdapter: " + adapterRequests);
        // $NON-NLS-1$
        System.out.println("Total time in getAdapter: " + adapterTime);
        // $NON-NLS-1$
        System.out.println("Average time per call: " + (adapterTime / adapterRequests));
    }
    ISourceViewer viewer = getSourceViewer();
    if (viewer instanceof ITextViewerExtension)
        ((ITextViewerExtension) viewer).removeVerifyKeyListener(fPairInserter);
    // dispose of information presenter
    if (fInformationPresenter != null) {
        fInformationPresenter.dispose();
        fInformationPresenter = null;
    }
    if (fOutlineHandler != null) {
        fOutlineHandler.dispose();
        fOutlineHandler = null;
    }
    // dispose of selection history
    if (fSelectionHistory != null) {
        fSelectionHistory.dispose();
        fSelectionHistory = null;
    }
    if (fProjectionSupport != null) {
        fProjectionSupport.dispose();
        fProjectionSupport = null;
    }
    if (fFoldingGroup != null) {
        fFoldingGroup.dispose();
        fFoldingGroup = null;
    }
    // dispose of menus that were being tracked
    if (fTextContextMenu != null) {
        fTextContextMenu.dispose();
        fTextContextMenu = null;
    }
    if (fRulerContextMenu != null) {
        fRulerContextMenu.dispose();
        fRulerContextMenu = null;
    }
    if (fTextContextMenuManager != null) {
        fTextContextMenuManager.removeMenuListener(getContextMenuListener());
        fTextContextMenuManager.removeAll();
        fTextContextMenuManager.dispose();
    }
    if (fRulerContextMenuManager != null) {
        fRulerContextMenuManager.removeMenuListener(getContextMenuListener());
        fRulerContextMenuManager.removeAll();
        fRulerContextMenuManager.dispose();
    }
    // less severe.
    if (fStructuredModel != null) {
        fStructuredModel.removeModelStateListener(getInternalModelStateListener());
    // fStructuredModel.setStructuredDocument(null);
    /* BUG398460 - Editor is still marked dirty when relaunching editor after closing without saving changes */
    // fStructuredModel = null;
    }
    // to document, so nothing to remove
    if (getDocumentProvider() != null) {
        IDocument doc = getDocumentProvider().getDocument(getEditorInput());
        if (doc != null) {
            if (doc instanceof IExecutionDelegatable) {
                ((IExecutionDelegatable) doc).setExecutionDelegate(null);
            }
        }
    }
    // up after themselves
    if (fOutlinePage != null) {
        if (fOutlinePage instanceof ConfigurableContentOutlinePage && fOutlinePageListener != null) {
            ((ConfigurableContentOutlinePage) fOutlinePage).removeDoubleClickListener(fOutlinePageListener);
        }
        if (fOutlinePageListener != null) {
            fOutlinePage.removeSelectionChangedListener(fOutlinePageListener);
            fOutlinePageListener = null;
        }
        fOutlinePage = null;
    }
    fEditorDisposed = true;
    disposeModelDependentFields();
    if (fDropTarget != null)
        fDropTarget.dispose();
    if (fPartListener != null) {
        getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener);
        fPartListener = null;
    }
    uninstallSemanticHighlighting();
    if (fPairInserter != null) {
        fPairInserter.dispose();
        fPairInserter = null;
    }
    setPreferenceStore(null);
    /*
		 * Strictly speaking, but following null outs should not be needed,
		 * but in the event of a memory leak, they make the memory leak less
		 * severe
		 */
    fDropAdapter = null;
    fDropTarget = null;
    if (fStructuredSelectionProvider != null) {
        fStructuredSelectionProvider.dispose();
        fStructuredSelectionProvider = null;
    }
    if (fStatusLineLabelProvider != null) {
        fStatusLineLabelProvider.dispose();
        fStatusLineLabelProvider = null;
    }
    setStatusLineMessage(null);
    super.dispose();
    // $NON-NLS-1$ //$NON-NLS-2$
    Logger.trace("Source Editor", "StructuredTextEditor::dispose exit");
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) ConfigurableContentOutlinePage(org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage) IExecutionDelegatable(org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 32 with ITextViewerExtension

use of org.eclipse.jface.text.ITextViewerExtension in project n4js by eclipse.

the class FQNImporter method applyWithImport.

/**
 * Applies the proposal and imports the given qualifiedName with the given alias (may be null). Prevents flickering
 * by temporarily disabling redraw on the text viewer widget.
 */
private void applyWithImport(QualifiedName qualifiedName, String alias, IDocument document, ConfigurableCompletionProposal proposal) throws BadLocationException {
    // Import does not introduce ambiguities - add import and insert short name
    int topPixel = -1;
    // store the pixel coordinates to prevent the ui from flickering
    StyledText widget = viewer.getTextWidget();
    if (widget != null)
        topPixel = widget.getTopPixel();
    ITextViewerExtension viewerExtension = null;
    if (viewer instanceof ITextViewerExtension) {
        viewerExtension = (ITextViewerExtension) viewer;
        viewerExtension.setRedraw(false);
    }
    DocumentRewriteSession rewriteSession = null;
    try {
        if (document instanceof IDocumentExtension4) {
            rewriteSession = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL);
        }
        int initialCursorLine = document.getLineOfOffset(proposal.getReplacementOffset());
        // apply short proposal and obtain the new cursor position
        int newCursorPositionInDocument = doApply(qualifiedName, alias, document, proposal);
        // set the pixel coordinates of the viewer widget, e.g. move it up one line if necessary
        int newCursorLine = document.getLineOfOffset(newCursorPositionInDocument);
        if (widget != null) {
            int additionalTopPixel = (newCursorLine - initialCursorLine) * widget.getLineHeight();
            widget.setTopPixel(topPixel + additionalTopPixel);
        }
    } finally {
        if (rewriteSession != null) {
            ((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
        }
        if (viewerExtension != null)
            viewerExtension.setRedraw(true);
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) StyledText(org.eclipse.swt.custom.StyledText) DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4)

Example 33 with ITextViewerExtension

use of org.eclipse.jface.text.ITextViewerExtension in project xtext-eclipse by eclipse.

the class TextViewerMoveLinesAction method beginCompoundEdit.

/**
 * Ends the compound change.
 */
private void beginCompoundEdit() {
    ITextViewer viewer = getTextViewer();
    if (fEditInProgress || viewer == null || !(viewer instanceof ITextViewerExtension))
        return;
    fEditInProgress = true;
    fStrategy.arm(viewer);
    IRewriteTarget target = ((ITextViewerExtension) viewer).getRewriteTarget();
    if (target != null) {
        target.beginCompoundChange();
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 34 with ITextViewerExtension

use of org.eclipse.jface.text.ITextViewerExtension in project xtext-eclipse by eclipse.

the class TextViewerMoveLinesAction method endCompoundEdit.

/**
 * Ends the compound change.
 */
private void endCompoundEdit() {
    ITextViewer viewer = getTextViewer();
    if (!fEditInProgress || viewer == null || !(viewer instanceof ITextViewerExtension))
        return;
    IRewriteTarget target = ((ITextViewerExtension) viewer).getRewriteTarget();
    if (target != null) {
        target.endCompoundChange();
    }
    fEditInProgress = false;
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 35 with ITextViewerExtension

use of org.eclipse.jface.text.ITextViewerExtension in project xtext-eclipse by eclipse.

the class MarkRegionTargetWithoutStatusline method setMarkAtCursor.

@Override
public void setMarkAtCursor(boolean set) {
    if (!(fViewer instanceof ITextViewerExtension))
        return;
    ITextViewerExtension viewerExtension = ((ITextViewerExtension) fViewer);
    if (set) {
        Point selection = fViewer.getSelectedRange();
        viewerExtension.setMark(selection.x);
    } else {
        viewerExtension.setMark(-1);
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Point(org.eclipse.swt.graphics.Point)

Aggregations

ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)36 StyledText (org.eclipse.swt.custom.StyledText)13 Point (org.eclipse.swt.graphics.Point)13 IDocument (org.eclipse.jface.text.IDocument)8 IRewriteTarget (org.eclipse.jface.text.IRewriteTarget)7 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)6 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 Control (org.eclipse.swt.widgets.Control)5 ITextViewer (org.eclipse.jface.text.ITextViewer)4 Composite (org.eclipse.swt.widgets.Composite)4 ICommandService (org.eclipse.ui.commands.ICommandService)4 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 IEditingSupportRegistry (org.eclipse.jface.text.IEditingSupportRegistry)2 IRegion (org.eclipse.jface.text.IRegion)2 ICompletionProposalExtension (org.eclipse.jface.text.contentassist.ICompletionProposalExtension)2 ICompletionProposalExtension2 (org.eclipse.jface.text.contentassist.ICompletionProposalExtension2)2 LinkedModeModel (org.eclipse.jface.text.link.LinkedModeModel)2 LinkedModeUI (org.eclipse.jface.text.link.LinkedModeUI)2 LinkedPosition (org.eclipse.jface.text.link.LinkedPosition)2