Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.IDocument


                template.getContextTypeId(), pattern, template.isAutoInsertable());
    }

    private String getWhiteSpacePrefix() {
        final int start = getStart();
        final IDocument document = getDocument();
        int line;
        try {
            line = document.getLineOfOffset(start);
            final int lineStart = document.getLineOffset(line);
            for (int i = 0; lineStart + i <= start; ++i) {
                final char c = document.getChar(lineStart + i);
                if (c != ' ' && c != '\t') {
                    return document.get(lineStart, i);
                }
            }
        } catch (final BadLocationException e) {
            ErlLogger.error(e);
        }
View Full Code Here


                return;
            }

            sourceViewer.addTextInputListener(this);

            final IDocument document = sourceViewer.getDocument();
            if (document != null) {
                document.addDocumentListener(this);
            }
        }
View Full Code Here

                sourceViewer.removeTextInputListener(this);
            }

            final IDocumentProvider documentProvider = editor.getDocumentProvider();
            if (documentProvider != null) {
                final IDocument document = documentProvider.getDocument(editor
                        .getEditorInput());
                if (document != null) {
                    document.removeDocumentListener(this);
                }
            }
        }
View Full Code Here

     * Jumps to the matching bracket.
     */
    public void gotoMatchingBracket() {

        final ISourceViewer sourceViewer = getSourceViewer();
        final IDocument document = sourceViewer.getDocument();
        if (document == null) {
            return;
        }

        final IRegion selection = getSignedSelection(sourceViewer);
View Full Code Here

            resetReconciler();
        }

        super.doSetInput(input);

        final IDocument document = provider.getDocument(input);
        if (!(input instanceof IPathEditorInput) && document != null) {
            final ErlangDocumentSetupParticipant setupParticipant = new ErlangDocumentSetupParticipant();
            setupParticipant.setup(document);
        }

        if (myOutlinePage != null) {
            // TODO should we use model events here?
            myOutlinePage.setInput(input);
        }
        final IErlModule module = getModule();
        if (module != null) {
            fErlangEditorErrorTickUpdater.updateEditorImage(module);
        }

        if (document != null) {
            // scannerListener = new ScannerListener();
            // document.addDocumentListener(scannerListener);
            // scannerListener.documentOpened();
            if (document.getLength() > 0) {
                // fake a change if the document already has content
                // scannerListener.documentChanged(new DocumentEvent(document,
                // 0,
                // document.getLength(), document.get()));
            }
View Full Code Here

public class IndentHandler extends ErlangAbstractHandler {

    @Override
    protected void doAction(final ISelection sel, final ITextEditor textEditor) {
        final IDocument document = textEditor.getDocumentProvider().getDocument(
                textEditor.getEditorInput());
        final ITextSelection selection = extendSelectionToWholeLines(document,
                (ITextSelection) sel);
        final ITextSelection getSelection = getTextSelection(document, selection,
                textEditor);
        String text;
        OtpErlangObject r1 = null;
        try {
            text = document.get(getSelection.getOffset(), getSelection.getLength());
            // call erlang, with selection within text
            r1 = callErlang(selection.getOffset() - getSelection.getOffset(),
                    selection.getLength(), text);
        } catch (final Exception e) {
            ErlLogger.error(e);
        }
        final String newText = Util.stringValue(r1);
        if (newText == null) {
            final String msg = "call to " + getClass().getSimpleName()
                    + " timed out; try a smaller selection.";
            final Status status = new Status(IStatus.ERROR, ErlangCore.PLUGIN_ID,
                    ErlangStatus.INTERNAL_ERROR.getValue(), msg, null);
            ErlLogger.error("INTERNAL ERROR: " + msg);

            ErrorDialog.openError(textEditor.getSite().getShell(),
                    ActionMessages.IndentAction_error_message, "Internal error", status);
            return;
        }
        final Display display = textEditor.getEditorSite().getShell().getDisplay();
        display.syncExec(new Runnable() {
            @Override
            public void run() {
                final IRewriteTarget target = (IRewriteTarget) textEditor
                        .getAdapter(IRewriteTarget.class);
                if (target != null) {
                    target.beginCompoundChange();
                    target.setRedraw(false);
                }
                try {
                    if (!document.get(selection.getOffset(), selection.getLength())
                            .equals(newText)) {
                        document.replace(selection.getOffset(), selection.getLength(),
                                newText);
                    }
                } catch (final BadLocationException e) {
                    ErlLogger.warn(e);
                }
View Full Code Here

            break;
        default:
            return;
        }

        final IDocument document = sourceViewer.getDocument();

        final Point selection = sourceViewer.getSelectedRange();
        final int offset = selection.x;
        final int length = selection.y;
        try {
            final char prev = document.get(offset - 1, 1).charAt(0);
            final String selStr = fEmbraceSelection ? document.get(offset, length) : "";
            final int kind = getKindOfBracket(document, offset, length);

            if (kind == '(' || kind == '{' || kind == '[') {
                return;
            }
View Full Code Here

        if (flags != ILinkedModeListener.EXTERNAL_MODIFICATION) {
            return;
        }

        // remove brackets
        final IDocument document = sourceViewer.getDocument();
        if (document instanceof IDocumentExtension) {
            final IDocumentExtension extension = (IDocumentExtension) document;
            extension.registerPostNotificationReplace(null,
                    new IDocumentExtension.IReplace() {

                        @Override
                        public void perform(final IDocument d,
                                final IDocumentListener owner) {
                            if ((level.fFirstPosition.isDeleted || level.fFirstPosition.length == 0)
                                    && !level.fSecondPosition.isDeleted
                                    && level.fSecondPosition.offset == level.fFirstPosition.offset) {
                                try {
                                    document.replace(level.fSecondPosition.offset,
                                            level.fSecondPosition.length, ""); //$NON-NLS-1$
                                } catch (final BadLocationException e) {
                                    ErlLogger.error(e);
                                }
                            }

                            if (fBracketLevelStack.size() == 0) {
                                document.removePositionUpdater(fUpdater);
                                try {
                                    document.removePositionCategory(CATEGORY);
                                } catch (final BadPositionCategoryException e) {
                                    ErlLogger.error(e);
                                }
                            }
                        }
View Full Code Here

        // document
        // (e.g. when reusing editors), we force the listener to register
        // itself as document listener, because there will be no input change
        // on the viewer.
        // In order to do that, we simulate an input change.
        final IDocument document = textViewer.getDocument();
        if (document != null) {
            fListener.inputDocumentAboutToBeChanged(fDocument, document);
            fListener.inputDocumentChanged(fDocument, document);
        }
    }
View Full Code Here

    protected void process(final ErlDirtyRegion dirtyRegion) {
        if (dirtyRegion != null) {
            fStrategy.reconcile(dirtyRegion);
        } else {
            final IDocument document = getDocument();
            if (document != null) {
                fStrategy.reconcile(new Region(0, document.getLength()));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.IDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.