Java Code Examples for org.eclipse.jface.text.IDocument#removePositionCategory()

The following examples show how to use org.eclipse.jface.text.IDocument#removePositionCategory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TecoRegister.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
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));
		}
	}
}
 
Example 2
Source File: HighlightingPresenter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 3
Source File: XtextReconciler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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();
}
 
Example 4
Source File: TexDocumentModel.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: TypeScriptCompletionProposal.java    From typescript.java with MIT License 5 votes vote down vote up
private void ensurePositionCategoryRemoved(IDocument document) {
	if (document.containsPositionCategory(getCategory())) {
		try {
			document.removePositionCategory(getCategory());
		} catch (BadPositionCategoryException e) {
			// ignore
		}
		document.removePositionUpdater(fUpdater);
	}
}
 
Example 6
Source File: SnippetTemplateProposal.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void ensurePositionCategoryRemoved(IDocument document)
{
	if (document.containsPositionCategory(getCategory()))
	{
		try
		{
			document.removePositionCategory(getCategory());
		}
		catch (BadPositionCategoryException e)
		{
			// ignore
		}
		document.removePositionUpdater(fUpdater);
	}
}
 
Example 7
Source File: SemanticHighlightingPresenter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 8
Source File: ParameterGuessingProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void ensurePositionCategoryRemoved(IDocument document) {
	if (document.containsPositionCategory(getCategory())) {
		try {
			document.removePositionCategory(getCategory());
		} catch (BadPositionCategoryException e) {
			// ignore
		}
		document.removePositionUpdater(fUpdater);
	}
}
 
Example 9
Source File: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 10
Source File: TemplateProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void ensurePositionCategoryRemoved(IDocument document) {
	if (document.containsPositionCategory(getCategory())) {
		try {
			document.removePositionCategory(getCategory());
		} catch (BadPositionCategoryException e) {
			// ignore
		}
		document.removePositionUpdater(fUpdater);
	}
}
 
Example 11
Source File: MarkRing.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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) {
		}
	}
}