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;
}
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();
}
}
}
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();
}
}
}
Aggregations