use of org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy in project webtools.sourceediting by eclipse.
the class AddBlockCommentHandler method processAction.
/**
* @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(
* org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection)
*/
protected void processAction(ITextEditor textEditor, IStructuredDocument document, ITextSelection textSelection) {
IStructuredModel model = null;
boolean changed = false;
DocumentRewriteSession session = null;
try {
model = StructuredModelManager.getModelManager().getModelForEdit(document);
if (model != null) {
// makes it so one undo will undo all the edits to the document
model.beginRecording(this, SSEUIMessages.AddBlockComment_label, SSEUIMessages.AddBlockComment_description);
// keeps listeners from doing anything until updates are all done
model.aboutToChangeModel();
if (document instanceof IDocumentExtension4) {
session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
}
changed = true;
ITypedRegion[] typedRegions = document.computePartitioning(textSelection.getOffset(), textSelection.getLength());
CommentingStrategy commentType = CommentingStrategyRegistry.getDefault().getBlockCommentingStrategy(model.getContentTypeIdentifier(), typedRegions);
if (commentType != null) {
commentType.apply(document, textSelection.getOffset(), textSelection.getLength());
}
}
} catch (BadLocationException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Logger.logException("The given selection " + textSelection + " must be invalid", e);
} finally {
// clean everything up
if (session != null && document instanceof IDocumentExtension4) {
((IDocumentExtension4) document).stopRewriteSession(session);
}
if (model != null) {
model.endRecording(this);
if (changed) {
model.changedModel();
}
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy in project webtools.sourceediting by eclipse.
the class RemoveBlockCommentHandler method processAction.
/**
* @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection)
*/
protected void processAction(ITextEditor textEditor, IStructuredDocument document, ITextSelection textSelection) {
IStructuredModel model = null;
boolean changed = false;
DocumentRewriteSession session = null;
try {
model = StructuredModelManager.getModelManager().getModelForEdit(document);
if (model != null) {
// makes it so one undo will undo all the edits to the document
model.beginRecording(this, SSEUIMessages.RemoveBlockComment_label, SSEUIMessages.RemoveBlockComment_label);
// keeps listeners from doing anything until updates are all done
model.aboutToChangeModel();
if (document instanceof IDocumentExtension4) {
session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
}
changed = true;
ITypedRegion[] typedRegions = document.computePartitioning(textSelection.getOffset(), textSelection.getLength());
CommentingStrategy commentType = CommentingStrategyRegistry.getDefault().getBlockCommentingStrategy(model.getContentTypeIdentifier(), typedRegions);
if (commentType != null) {
commentType.remove(document, textSelection.getOffset(), textSelection.getLength(), true);
}
}
} catch (BadLocationException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Logger.logException("The given selection " + textSelection + " must be invalid", e);
} finally {
// clean everything up
if (session != null && document instanceof IDocumentExtension4) {
((IDocumentExtension4) document).stopRewriteSession(session);
}
if (model != null) {
model.endRecording(this);
if (changed) {
model.changedModel();
}
model.releaseFromEdit();
}
}
}
Aggregations