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

The following examples show how to use org.eclipse.ui.texteditor.ITextEditor#showsHighlightRangeOnly() . 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: TogglePresentationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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
Source File: TogglePresentationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void update() {
	ITextEditor editor= getTextEditor();
	boolean checked= (editor != null && editor.showsHighlightRangeOnly());
	setChecked(checked);
	if (editor instanceof CompilationUnitEditor) {
		IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager();
		setEnabled(manager.getWorkingCopy(editor.getEditorInput()) != null);
	} else if (editor instanceof ClassFileEditor) {
		IEditorInput input= editor.getEditorInput();
		IClassFile cf= null;
		if (input instanceof IClassFileEditorInput) {
			IClassFileEditorInput cfi= (IClassFileEditorInput)input;
			cf= cfi.getClassFile();
		}
		setEnabled(cf != null && cf.exists());
	} else
		setEnabled(editor != null);
}
 
Example 3
Source File: TogglePresentationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 4
Source File: MarkUtils.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Wrap selection provider setSelection within a block disabling highlight
 * range to protect against the JavaEditor from changing the narrow focus in
 * - org.eclipse.jdt.internal.ui.javaeditor.TogglePresentationAction -
 * 
 * @param editor
 * @param selection
 *            in model coords
 */
public static ITextSelection setSelection(ITextEditor editor, ITextSelection selection) {
	boolean isNarrow = editor.showsHighlightRangeOnly();
	// Use the text widget, as the IRewriteTarget has unpleasant scrolling side effects 
	Control text = getTextWidget(editor);
	try {
		text.setRedraw(false);
		if (isNarrow) {
			editor.showHighlightRangeOnly(false);
		}
		editor.getSelectionProvider().setSelection(selection);
	} finally {
		if (isNarrow) {
			editor.showHighlightRangeOnly(isNarrow);
		}
		text.setRedraw(true);
	}
	return selection;
}
 
Example 5
Source File: KeyboardQuitHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event) 
throws BadLocationException {

	// clear status area
	EmacsPlusUtils.clearMessage(editor);
	EmacsMovementHandler.clearShifted(); // set mark always removes shift select flag
	beep();
	int offset = NO_OFFSET;
	if (currentSelection.getLength() > 0) {
		// when region is narrowed, avoid provoking a range update in eclipse code 
		if (editor.showsHighlightRangeOnly()) {
			MarkUtils.setSelection(editor, getCursorOffset(editor), 0);
		} else {
			offset = getCursorOffset(editor);	
		}
	}
	return offset;
}
 
Example 6
Source File: WhatLine.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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 {
	
	int nLine = document.getLineOfOffset(getCursorOffset(editor,currentSelection));
	String msg = String.format(LINE, nLine+1);
	if (editor.showsHighlightRangeOnly()) {
		int nhLine = nLine - document.getLineOfOffset(editor.getHighlightRange().getOffset());
		msg += String.format(H_LINE, nhLine+1); 
	}
	asyncShowMessage(editor, msg, false);
	return super.transform(editor, document, currentSelection, event);
}
 
Example 7
Source File: DeleteWhitespaceHandler.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Determine the correct set of lines and delete the whitespace at the end of each of them.
 * 
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection,
		ExecutionEvent event) throws BadLocationException {
	int result = NO_OFFSET;
	int lastLine = 0;
	int firstLine = 0;
	int maxOffset = Integer.MAX_VALUE;		
	if (editor.showsHighlightRangeOnly()) {
		// if the buffer is narrowed, then operate on precise region
		IRegion narrow = editor.getHighlightRange();
		int lastOffset = narrow.getOffset() + narrow.getLength();
		firstLine = document.getLineOfOffset(narrow.getOffset()); 
		lastLine = document.getLineOfOffset(lastOffset);
		IRegion endInfo = document.getLineInformationOfOffset(lastOffset);
		if (endInfo.getOffset() != lastOffset) {
			// point maxOffset at the last character in the narrowed region
			maxOffset = lastOffset -1;
		} else {
			// back up if we're at the first offset of the last line
			lastLine--;
		}
	} else {
		lastLine = document.getNumberOfLines() -1;
	}
	if (firstLine <= lastLine) {
		Position coff = new Position(getCursorOffset(editor,currentSelection),0);
		try {
			// record the position so we can restore it after any whitespace deletions
			document.addPosition(coff);
			deleteWhitepace(lastLine,firstLine,maxOffset,document);
		} catch (BadLocationException e) {
			// shouldn't happen, but alert user if it does
			asyncShowMessage(editor,BAD_LOCATION_ERROR,true);
		} finally {
			result = coff.getOffset();
			document.removePosition(coff);
		}
	}
	return result;
}
 
Example 8
Source File: ParagraphHandler.java    From e4macs with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Check if we're at buffer top (or top of narrowed region)
 * 
 * @param editor
 * @param selection
 * @return true is condition satisfied, else false
 */
boolean isAtTop(ITextEditor editor, ITextSelection selection) {
	// if we're not at buffer top (or top of narrowed region)
	return (selection.getOffset() == 0 || 
			(editor.showsHighlightRangeOnly() && selection.getOffset() == editor.getHighlightRange().getOffset()));
}