Java Code Examples for org.eclipse.ui.texteditor.ITextEditor#setHighlightRange()

The following examples show how to use org.eclipse.ui.texteditor.ITextEditor#setHighlightRange() . 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
@Override
public void run() {

	ITextEditor editor= getTextEditor();
	if (editor == null)
		return;

	IRegion remembered= editor.getHighlightRange();
	editor.resetHighlightRange();

	boolean showAll= !editor.showsHighlightRangeOnly();
	setChecked(showAll);

	editor.showHighlightRangeOnly(showAll);
	if (remembered != null)
		editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true);

	fStore.removePropertyChangeListener(this);
	fStore.setValue(PreferenceConstants.EDITOR_SHOW_SEGMENTS, showAll);
	fStore.addPropertyChangeListener(this);
}
 
Example 2
/**
 * Synchronizes the appearance of the editor with what the preference store tells him.
 *
 * @param editor the text editor
 */
private void synchronizeWithPreference(ITextEditor editor) {

	if (editor == null)
		return;

	boolean showSegments= fStore.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS);
	setChecked(showSegments);

	if (editor.showsHighlightRangeOnly() != showSegments) {
		IRegion remembered= editor.getHighlightRange();
		editor.resetHighlightRange();
		editor.showHighlightRangeOnly(showSegments);
		if (remembered != null)
			editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true);
	}
}
 
Example 3
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusNoEditHandler#transform(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection, org.eclipse.core.commands.ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection,
		ExecutionEvent event) throws BadLocationException {

	// because of issues with preferences -> java -> editor [] only show the selected Java element
	// always set the highlight range to false
	if (editor != null) {
		IRegion remembered= editor.getHighlightRange();
		editor.resetHighlightRange();
		editor.showHighlightRangeOnly(false);
		if (remembered != null) {
			editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), false);
		}
		// remove buffer local value
		BufferLocal.getInstance().kill(editor, BufferLocal.NARROW_REGION);
	} else {
		beep();
	}
	return currentSelection.getOffset();
}
 
Example 4
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusNoEditHandler#transform(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection, org.eclipse.core.commands.ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection,
		ExecutionEvent event) throws BadLocationException {

	if (editor != null) {
		// if nothing is selected, beep()
		if (currentSelection.getLength() == 0) {
			beep();
		} else {
			// narrow to selection
			editor.resetHighlightRange();
			editor.showHighlightRangeOnly(true);
			editor.setHighlightRange(currentSelection.getOffset(), currentSelection.getLength(), true);
			// Remember region to support narrow/widen in the face of Eclipse's bad behavior on activation:
			// org.eclipse.jdt.internal.ui.javaeditor.BasicJavaEditorActionContributor.setActiveEditor
			BufferLocal.getInstance().set(editor, BufferLocal.NARROW_REGION, editor.getHighlightRange());
			MarkUtils.setSelection(editor, getCursorOffset(editor), 0);
		}
	}
	return super.transform(editor, document, currentSelection, event);
}
 
Example 5
private void revealLocationInFile(String typeName, int line, int column, IEditorPart editorPart)
		throws CoreException {
	if (editorPart instanceof ITextEditor && line >= 0) {
		ITextEditor textEditor = (ITextEditor) editorPart;
		IDocumentProvider provider = textEditor.getDocumentProvider();
		IEditorInput editorInput = editorPart.getEditorInput();
		provider.connect(editorInput);
		IDocument document = provider.getDocument(editorInput);
		try {
			IRegion regionOfLine = document.getLineInformation(line);
			// only used to reveal the location
			textEditor.selectAndReveal(regionOfLine.getOffset(), regionOfLine.getLength());
			int startOffset = regionOfLine.getOffset() + column;
			int length = regionOfLine.getLength() - column;
			if (startOffset >= document.getLength()) {
				startOffset = document.getLength() - 1;
			}
			if (length + startOffset >= document.getLength()) {
				length = document.getLength() - startOffset - 1;
			}
			textEditor.setHighlightRange(startOffset, length, true);
		} catch (BadLocationException e) {
			MessageDialog.openInformation(N4JSGracefulActivator.getActiveWorkbenchShell(),
					ConsoleMessages.msgInvalidLineNumberTitle(),
					ConsoleMessages.msgInvalidLineNumberIn(
							(line + 1) + "",
							typeName));
		}
		provider.disconnect(editorInput);
	}
}
 
Example 6
private void revealLocationInFile(IEditorPart editorPart)
		throws CoreException {
	if (editorPart instanceof ITextEditor && locationText.line > 0) {
		ITextEditor textEditor = (ITextEditor) editorPart;
		IDocumentProvider provider = textEditor.getDocumentProvider();
		IEditorInput editorInput = editorPart.getEditorInput();
		provider.connect(editorInput);
		IDocument document = provider.getDocument(editorInput);
		try {
			IRegion regionOfLine = document.getLineInformation(locationText.line - 1);
			// only used to reveal the location
			textEditor.selectAndReveal(regionOfLine.getOffset(), regionOfLine.getLength());
			int startOffset = regionOfLine.getOffset() + locationText.column - 1;
			int length = regionOfLine.getLength() - locationText.column;
			if (startOffset >= document.getLength()) {
				startOffset = document.getLength() - 1;
			}
			if (length + startOffset >= document.getLength()) {
				length = document.getLength() - startOffset - 1;
			}
			textEditor.setHighlightRange(startOffset, length, true);
		} catch (BadLocationException e) {
			MessageDialog.openInformation(N4JSGracefulActivator.getActiveWorkbenchShell(),
					ConsoleMessages.msgInvalidLineNumberTitle(),
					ConsoleMessages.msgInvalidLineNumberIn(
							(locationText.line) + "",
							locationText.fileName));
		}
		provider.disconnect(editorInput);
	}
}
 
Example 7
Source Project: e4macs   File: BufferLocal.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void handleNarrowActivate(ITextEditor editor) {
	IRegion region = (IRegion)get(editor, NARROW_REGION);	
	if (region != null) {
		IRegion cregion = editor.getHighlightRange();
		if (!region.equals(cregion)) {
			// if (java) global flag is set, and used from outline
			// permit the new range to override the narrowed range
			region = cregion;
		}
		// narrow to selection
		editor.resetHighlightRange();
		editor.showHighlightRangeOnly(true);
		editor.setHighlightRange(region.getOffset(), region.getLength(), true);
	}
}