Java Code Examples for org.eclipse.jface.text.IDocument#getDocumentPartitioner()
The following examples show how to use
org.eclipse.jface.text.IDocument#getDocumentPartitioner() .
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: CommonDocumentProvider.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
@Override public void disconnect(Object element) { FileInfo fileInfo = getFileInfo(element); if (fileInfo != null && fileInfo.fCount == 1) { IDocument document = getDocument(element); if (document != null) { IDocumentPartitioner partitioner = document.getDocumentPartitioner(); if (partitioner != null) { partitioner.disconnect(); document.setDocumentPartitioner(null); } } } super.disconnect(element); }
Example 2
Source File: PartitionCodeReader.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Note: this just gets the positions in the document. To cover for holes, use * StringUtils.sortAndMergePositions with the result of this call. */ public static Position[] getDocumentTypedPositions(IDocument document, String defaultContentType) { if (ALL_CONTENT_TYPES_AVAILABLE.equals(defaultContentType)) { //Consider the whole document return new Position[] { new TypedPosition(0, document.getLength(), defaultContentType) }; } Position[] positions; try { IDocumentPartitionerExtension2 partitioner = (IDocumentPartitionerExtension2) document .getDocumentPartitioner(); String[] managingPositionCategories = partitioner.getManagingPositionCategories(); Assert.isTrue(managingPositionCategories.length == 1); positions = document.getPositions(managingPositionCategories[0]); if (positions == null) { positions = new Position[] { new TypedPosition(0, document.getLength(), defaultContentType) }; } } catch (Exception e) { Log.log("Unable to get positions for: " + defaultContentType, e); //Shouldn't happen, but if it does, consider the whole doc. positions = new Position[] { new TypedPosition(0, document.getLength(), defaultContentType) }; } return positions; }
Example 3
Source File: PartitionUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Returns the partitioner for the given partitioning or <code>null</code> if * no partitioner is registered. * * @param document the document to be processed * @param partitioningType the partitioning for which to set the partitioner * @return the partitioner for the given partitioning * * @see org.eclipse.jface.text.IDocumentExtension3#getDocumentPartitioner(IDocument,String) */ public static IDocumentPartitioner getPartitioner( IDocument document , String partitioningType ) { IDocumentPartitioner result = null; if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension = (IDocumentExtension3) document; result = extension.getDocumentPartitioner(partitioningType); } else if (document != null){ result = document.getDocumentPartitioner(); } return result; }
Example 4
Source File: PatternExpressionModelBuilder.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private List<ITypedRegion> allGroovyPartitions(IDocument document) { final IDocumentPartitioner partitioner = document.getDocumentPartitioner(); final ITypedRegion[] regions = partitioner.computePartitioning(0, document.getLength()); final List<ITypedRegion> groovyPartions = new ArrayList<>(); for (int i = 0; i < regions.length; i++) { final ITypedRegion partition = regions[i]; if (PatternExpressionViewer.GROOVY_EXPRESSION_CONTENT_TYPE.equals(partition.getType())) { groovyPartions.add(partition); } } return groovyPartions; }
Example 5
Source File: BaseParsingUtils.java From Pydev with Eclipse Public License 1.0 | 4 votes |
public static String getContentType(IDocument document, int i) { IDocumentPartitionerExtension2 extension = (IDocumentPartitionerExtension2) document.getDocumentPartitioner(); return extension.getContentType(i, true); }
Example 6
Source File: ClipboardHandler.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * @return the text in the given range that's related to actual code / output (but not the prompt) */ public String getPlainText(IDocument doc, Point selectedRange) { StringBuffer plainText = new StringBuffer(); ScriptConsolePartitioner scriptConsolePartitioner = (ScriptConsolePartitioner) doc.getDocumentPartitioner(); ScriptStyleRange[] ranges = scriptConsolePartitioner.getStyleRanges(selectedRange.x, selectedRange.y); if (ranges.length == 0) { return ""; } try { int currentRange = 0; int minOffset = selectedRange.x; int maxOffset = selectedRange.x + selectedRange.y; //note: we must iterate through the document and not through the ranges because //new lines can have no range associated. for (int i = minOffset; i < maxOffset; i++) { char c = doc.getChar(i); if (c == '\r' || c == '\n') { //new lines should be added for any style. plainText.append(c); } else { ScriptStyleRange current = null; while (true) { if (currentRange >= ranges.length) { break; } current = ranges[currentRange]; if (current.start <= i && i < current.start + current.length) { break; } currentRange++; } if (current == null) { continue; } if (current.scriptType == ScriptStyleRange.PROMPT) { continue; } plainText.append(c); } } } catch (Exception e) { Log.log(e); } return plainText.toString(); }
Example 7
Source File: HandleLineStartAction.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * When going to the line start, we must actually go to: 1st char / prompt end / line start (depending * on where we are currently) * * @return true if it was done and false otherwise. */ public boolean execute(IDocument doc, int caretOffset, int commandLineOffset, IScriptConsoleViewer viewer) { try { TextSelectionUtils ps = new TextSelectionUtils(doc, caretOffset); int lineOffset = ps.getLineOffset(); int promptEndOffset = lineOffset; ScriptConsolePartitioner partitioner = (ScriptConsolePartitioner) doc.getDocumentPartitioner(); int docLen = doc.getLength(); for (; promptEndOffset < docLen; promptEndOffset++) { ScriptStyleRange[] range = partitioner.getStyleRanges(promptEndOffset, 1); if (range.length >= 1) { if (range[0].scriptType != ScriptStyleRange.PROMPT) { break; } } } int absoluteCursorOffset = ps.getAbsoluteCursorOffset(); IRegion lineInformation = doc.getLineInformationOfOffset(absoluteCursorOffset); String contentsFromPrompt = doc.get(promptEndOffset, lineInformation.getOffset() + lineInformation.getLength() - promptEndOffset); int firstCharPosition = TextSelectionUtils.getFirstCharPosition(contentsFromPrompt); int firstCharOffset = promptEndOffset + firstCharPosition; //1st see: if we're in the start of the line, go to the 1st char after the prompt if (lineOffset == absoluteCursorOffset || firstCharOffset < absoluteCursorOffset) { viewer.setCaretOffset(firstCharOffset, false); return true; } if (promptEndOffset < absoluteCursorOffset) { viewer.setCaretOffset(promptEndOffset, false); return true; } viewer.setCaretOffset(lineOffset, false); return true; } catch (BadLocationException e) { Log.log(e); } return false; }