下面列出了org.eclipse.jface.text.IDocument#removePositionCategory ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void partClosed(IWorkbenchPartReference partRef) {
if (partRef instanceof IEditorReference) {
IEditorPart epart = ((IEditorReference) partRef).getEditor(false);
ITextEditor editor = (location != null ? location.getEditor() : null);
if (editor == EmacsPlusUtils.getTextEditor(epart, false)) {
RegisterLocation loc = location;
// we're out of here
removeListener(this);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
// remove position category, if still present
if (document.containsPositionCategory(MarkRing.MARK_CATEGORY)) {
try {
document.removePositionUpdater(MarkRing.updater);
document.removePositionCategory(MarkRing.MARK_CATEGORY);
} catch (BadPositionCategoryException e) {
}
}
// convert to path
loc.setPath(convertToPath(editor));
}
}
}
/**
* Stop managing the given document.
*
* @param document
* The document
*/
private void releaseDocument(IDocument document) {
if (document != null) {
document.removeDocumentListener(this);
document.removePositionUpdater(fPositionUpdater);
try {
document.removePositionCategory(getPositionCategory());
} catch (BadPositionCategoryException e) {
// Should not happen
log.debug(e.getMessage(), e);
}
}
}
@Override
public void assistSessionEnded(ContentAssistEvent event) {
sessionStarted = false;
IDocument document = textViewer.getDocument();
document.removePositionUpdater(templatePositionUpdater);
try {
document.removePositionCategory(XTEXT_TEMPLATE_POS_CATEGORY);
} catch (BadPositionCategoryException e) {
log.debug(e.getMessage(), e);
}
resume();
}
/**
* Traverses the OutlineNode tree and adds a Position for each
* node to Document.
*
* Also adds the nodes to type lists of the OutlineInput and
* calculates the tree depth.
*
* Old Positions are removed before adding new ones.
*
* @param rootNodes
* @param monitor monitor for the job calling this method
*/
private void updateDocumentPositions(List<OutlineNode> rootNodes, IProgressMonitor monitor) {
TexOutlineInput newOutlineInput = new TexOutlineInput(rootNodes);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
// remove previous positions
try {
document.removePositionCategory("__outline");
} catch (BadPositionCategoryException bpce) {
// do nothing, the category will be added again next, it does not exists the first time
}
document.addPositionCategory("__outline");
pollCancel(monitor);
// add new positions for nodes and their children
int maxDepth = 0;
for (Iterator<OutlineNode> iter = rootNodes.iterator(); iter.hasNext(); ) {
OutlineNode node = iter.next();
int localDepth = addNodePosition(node, document, 0, newOutlineInput);
if (localDepth > maxDepth) {
maxDepth = localDepth;
}
pollCancel(monitor);
}
pollCancel(monitor);
// set the new outline input
newOutlineInput.setTreeDepth(maxDepth);
this.outlineInput = newOutlineInput;
}
private void ensurePositionCategoryRemoved(IDocument document) {
if (document.containsPositionCategory(getCategory())) {
try {
document.removePositionCategory(getCategory());
} catch (BadPositionCategoryException e) {
// ignore
}
document.removePositionUpdater(fUpdater);
}
}
private void ensurePositionCategoryRemoved(IDocument document)
{
if (document.containsPositionCategory(getCategory()))
{
try
{
document.removePositionCategory(getCategory());
}
catch (BadPositionCategoryException e)
{
// ignore
}
document.removePositionUpdater(fUpdater);
}
}
/**
* Stop managing the given document.
*
* @param document The document
*/
private void releaseDocument(IDocument document) {
if (document != null) {
document.removeDocumentListener(this);
document.removePositionUpdater(fPositionUpdater);
try {
document.removePositionCategory(getPositionCategory());
} catch (BadPositionCategoryException e) {
// Should not happen
JavaPlugin.log(e);
}
}
}
private void ensurePositionCategoryRemoved(IDocument document) {
if (document.containsPositionCategory(getCategory())) {
try {
document.removePositionCategory(getCategory());
} catch (BadPositionCategoryException e) {
// ignore
}
document.removePositionUpdater(fUpdater);
}
}
/**
* Called after the document changed occurred. It must be preceded by a call to preReplace().
*
* @param document the document on which to track the reference position.
* @return offset after the replace
*/
public int postReplace(IDocument document) {
try {
document.removePosition(CATEGORY, fPosition);
document.removePositionUpdater(fPositionUpdater);
document.removePositionCategory(CATEGORY);
} catch (BadPositionCategoryException e) {
// should not happen
JavaPlugin.log(e);
}
return fPosition.getOffset();
}
private void ensurePositionCategoryRemoved(IDocument document) {
if (document.containsPositionCategory(getCategory())) {
try {
document.removePositionCategory(getCategory());
} catch (BadPositionCategoryException e) {
// ignore
}
document.removePositionUpdater(fUpdater);
}
}
/**
* Remove the document's mark buffer from the local Mark list
* Also, remove the position updating information from the document
*
* @param document
*/
static void removeMarks(IDocument document) {
MarkList local = localMarks.remove(document);
if (local != null || document.containsPositionCategory(MARK_CATEGORY)) {
document.removePositionUpdater(updater);
try {
// this also removes all the positions
document.removePositionCategory(MARK_CATEGORY);
} catch (BadPositionCategoryException e) {
}
}
}