Search in sources :

Example 1 with CommentImpl

use of org.eclipse.wst.xml.core.internal.document.CommentImpl in project webtools.sourceediting by eclipse.

the class XMLFoldingStrategy method calcNewFoldPosition.

/**
 * @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#calcNewFoldPosition(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)
 */
protected Position calcNewFoldPosition(IndexedRegion indexedRegion) {
    Position retPos = null;
    // only want to fold regions of the valid type and with a valid range
    if (indexedRegion.getStartOffset() >= 0 && indexedRegion.getLength() >= 0) {
        IDOMNode node = (IDOMNode) indexedRegion;
        IStructuredDocumentRegion startRegion = node.getStartStructuredDocumentRegion();
        IStructuredDocumentRegion endRegion = node.getEndStructuredDocumentRegion();
        // else if the region is only an open tag or an open/close tag then don't fold it
        if (startRegion != null && endRegion != null) {
            if (endRegion.getEndOffset() >= startRegion.getStartOffset())
                retPos = new XMLElementFoldingPosition(startRegion, endRegion);
        } else if (startRegion != null && indexedRegion instanceof CommentImpl) {
            retPos = new XMLCommentFoldingPosition(startRegion);
        }
    }
    return retPos;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Position(org.eclipse.jface.text.Position) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CommentImpl(org.eclipse.wst.xml.core.internal.document.CommentImpl)

Example 2 with CommentImpl

use of org.eclipse.wst.xml.core.internal.document.CommentImpl in project webtools.sourceediting by eclipse.

the class RemoveBlockCommentActionXMLDelegate method processAction.

void processAction(IDocument document, ITextSelection textSelection) {
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
    if (model != null) {
        try {
            IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset());
            IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength());
            if ((selectionStartIndexedRegion == null) || (selectionEndIndexedRegion == null)) {
                return;
            }
            int openCommentOffset = selectionStartIndexedRegion.getStartOffset();
            int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length();
            model.beginRecording(this, XMLUIMessages.RemoveBlockComment_tooltip);
            model.aboutToChangeModel();
            try {
                if (textSelection.getLength() == 0) {
                    if (selectionStartIndexedRegion instanceof CommentImpl) {
                        // $NON-NLS-1$
                        document.replace(openCommentOffset, OPEN_COMMENT.length(), "");
                        // $NON-NLS-1$
                        document.replace(closeCommentOffset, CLOSE_COMMENT.length(), "");
                    }
                } else {
                    if (selectionStartIndexedRegion instanceof CommentImpl) {
                        // $NON-NLS-1$
                        document.replace(openCommentOffset, OPEN_COMMENT.length(), "");
                    }
                    if (selectionEndIndexedRegion instanceof CommentImpl) {
                        // $NON-NLS-1$
                        document.replace(closeCommentOffset, CLOSE_COMMENT.length(), "");
                    }
                }
                removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
            } catch (BadLocationException e) {
                Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
            } finally {
                model.changedModel();
                model.endRecording(this);
            }
        } finally {
            model.releaseFromEdit();
        }
    }
}
Also used : CommentImpl(org.eclipse.wst.xml.core.internal.document.CommentImpl) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with CommentImpl

use of org.eclipse.wst.xml.core.internal.document.CommentImpl in project webtools.sourceediting by eclipse.

the class AddBlockCommentActionXMLDelegate method processAction.

void processAction(IDocument document, ITextSelection textSelection) {
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
    if (model != null) {
        try {
            IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset());
            IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength());
            if (selectionStartIndexedRegion == null) {
                return;
            }
            if ((selectionEndIndexedRegion == null) && (textSelection.getLength() > 0)) {
                selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength() - 1);
            }
            if (selectionEndIndexedRegion == null) {
                return;
            }
            int openCommentOffset = selectionStartIndexedRegion.getStartOffset();
            int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length();
            if ((textSelection.getLength() == 0) && (selectionStartIndexedRegion instanceof CommentImpl)) {
                return;
            }
            model.beginRecording(this, XMLUIMessages.AddBlockComment_tooltip);
            model.aboutToChangeModel();
            try {
                document.replace(openCommentOffset, 0, OPEN_COMMENT);
                document.replace(closeCommentOffset, 0, CLOSE_COMMENT);
                removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
            } catch (BadLocationException e) {
                Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
            } finally {
                model.changedModel();
                model.endRecording(this);
            }
        } finally {
            model.releaseFromEdit();
        }
    }
}
Also used : CommentImpl(org.eclipse.wst.xml.core.internal.document.CommentImpl) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

CommentImpl (org.eclipse.wst.xml.core.internal.document.CommentImpl)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 Position (org.eclipse.jface.text.Position)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1