Search in sources :

Example 6 with IRewriteTarget

use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.

the class ConvertLineDelimitersAction method run.

@Override
public void run() {
    try {
        ITextEditor editor = getTextEditor();
        if (editor == null)
            return;
        if (!validateEditorInputState())
            return;
        Object adapter = editor.getAdapter(IRewriteTarget.class);
        if (adapter instanceof IRewriteTarget) {
            IRewriteTarget target = (IRewriteTarget) adapter;
            IDocument document = target.getDocument();
            if (document != null) {
                Shell shell = getTextEditor().getSite().getShell();
                ConvertRunnable runnable = new ConvertRunnable(target, fLineDelimiter);
                if (document.getNumberOfLines() < 40) {
                    BusyIndicator.showWhile(shell.getDisplay(), runnable);
                } else {
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
                    dialog.run(false, true, runnable);
                }
            }
        }
    } catch (InterruptedException e) {
    // action canceled
    } catch (InvocationTargetException e) {
    // should not happen
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IDocument(org.eclipse.jface.text.IDocument) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with IRewriteTarget

use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.

the class HippieCompleteAction method clearState.

/**
 * Invalidates the cached completions, removes all registered listeners and
 * sets the cached document to <code>null</code>.
 */
private void clearState() {
    fLastCompletion = null;
    ITextEditor editor = getTextEditor();
    if (editor != null) {
        IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
        if (target != null) {
            fExitStrategy.disarm();
            target.endCompoundChange();
        }
    }
    fDocument = null;
}
Also used : IRewriteTarget(org.eclipse.jface.text.IRewriteTarget)

Example 8 with IRewriteTarget

use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.

the class HippieCompleteAction method updateState.

/**
 * Update the completion state. The completion cache is updated with the
 * completions based on the currently displayed document and the current
 * selection. To track the validity of the cached state, listeners are
 * registered with the editor and document, and the current document is
 * cached.
 */
private void updateState() {
    Assert.isNotNull(getTextEditor());
    clearState();
    List<IDocument> documents = HippieCompletionEngine.computeDocuments(getTextEditor());
    if (documents.size() > 0) {
        fDocument = documents.remove(0);
        Iterator<String> suggestions;
        try {
            String prefix = getCurrentPrefix();
            if (prefix == null) {
                notifyUser();
                return;
            }
            suggestions = fEngine.getMultipleDocumentsIterator(fDocument, documents, prefix, getSelectionOffset());
        } catch (BadLocationException e) {
            log(e);
            return;
        }
        CompletionState completionState = new CompletionState(suggestions, getSelectionOffset());
        // if it is single empty suggestion
        if (completionState.hasOnly1EmptySuggestion) {
            notifyUser();
            return;
        }
        IRewriteTarget target = getTextEditor().getAdapter(IRewriteTarget.class);
        if (target != null)
            target.beginCompoundChange();
        fLastCompletion = completionState;
    }
}
Also used : IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 9 with IRewriteTarget

use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.

the class MoveLinesAction method beginCompoundEdit.

/**
 * Ends the compound change.
 */
private void beginCompoundEdit() {
    ITextEditor editor = getTextEditor();
    if (fEditInProgress || fTextViewer == null || editor == null)
        return;
    fEditInProgress = true;
    fStrategy.arm(fTextViewer);
    IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
    if (target != null) {
        target.beginCompoundChange();
    }
}
Also used : IRewriteTarget(org.eclipse.jface.text.IRewriteTarget)

Example 10 with IRewriteTarget

use of org.eclipse.jface.text.IRewriteTarget in project eclipse.platform.text by eclipse.

the class QuickDiffRestoreAction method run.

@Override
public void run() {
    ITextEditor editor = getTextEditor();
    if (editor == null || !validateEditorInputState())
        return;
    IRewriteTarget target = editor.getAdapter(IRewriteTarget.class);
    if (target != null)
        target.beginCompoundChange();
    runCompoundChange();
    if (target != null)
        target.endCompoundChange();
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget)

Aggregations

IRewriteTarget (org.eclipse.jface.text.IRewriteTarget)13 IDocument (org.eclipse.jface.text.IDocument)5 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)4 BadLocationException (org.eclipse.jface.text.BadLocationException)3 Point (org.eclipse.swt.graphics.Point)3 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)3 IEditingSupportRegistry (org.eclipse.jface.text.IEditingSupportRegistry)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IEditingSupport (org.eclipse.jface.text.IEditingSupport)1 IRegion (org.eclipse.jface.text.IRegion)1 Position (org.eclipse.jface.text.Position)1 ICompletionProposalExtension (org.eclipse.jface.text.contentassist.ICompletionProposalExtension)1 ICompletionProposalExtension2 (org.eclipse.jface.text.contentassist.ICompletionProposalExtension2)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 ISelection (org.eclipse.jface.viewers.ISelection)1