Java Code Examples for org.eclipse.jface.text.ITextSelection#equals()

The following examples show how to use org.eclipse.jface.text.ITextSelection#equals() . 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: ExecuteCommandHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Call execute on checkers with an additional listener for selection change during execution
 *  
 * @param editor
 * @param checkers
 */
protected void executeWithSelectionCheck(final ITextEditor editor, IWithSelectionCheck checkers) {

	ISelectionChangedListener listener = new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			ExecuteCommandHandler.this.showResultMessage(editor);
			removeListener(event.getSelectionProvider(),this);
		}
	};
	ITextSelection before = getCurrentSelection(editor);
	try {
		addListener(editor.getSelectionProvider(),listener);
		checkers.execute();
	} finally {
		if (before.equals(getCurrentSelection(editor))) {
			// remove it if the selection did not change
			removeListener(editor.getSelectionProvider(),listener);
		}
	}
}
 
Example 2
Source File: BackwardUpListHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find the next matching bracket
 * 
 * @param document
 * @param selection
 * @return The bracketed region or null
 * @throws BadLocationException
 */
private IRegion matchBracket(IDocument document, ITextSelection selection, int endList) throws BadLocationException {
	
	if (selection == null) {
		return null;
	}
	
	int offset = selection.getOffset();
	if (isOpen(document.getChar(offset))) {
		// go to the end and check that it is past the initial ending
		IRegion end = getBracketMatch(document,offset+1);

		if (end == null) {
			return null;
		} else {
			offset = end.getOffset();
			if (offset + end.getLength() < endList) {
				if (--offset > -1) {
					// back up and recurse 
					return matchBracket(document,new TextSelection(document,offset,0),endList);
				} else {
					return null;
				}
			} else {
				return end;
			}
		}
	} else if (offset - 1 > 0 && isClose(document.getChar(offset-1))) {
		// if at the end of a sub-list, jump to the beginning and recurse
		IRegion begin = getBracketMatch(document,offset);
		return matchBracket(document,new TextSelection(document,begin.getOffset(),0),endList);
	} 			
	ITextSelection nextSexp = getNextSexp(document, selection,false,UP);
	if (selection.equals(nextSexp)) { 
		return null;
	}
	// if neither begin or end, look backward for next one and recurse
	return matchBracket(document,nextSexp,endList);
}
 
Example 3
Source File: SexpHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ITextSelection getCmdSelection(ITextEditor editor,
		ITextSelection selection) throws ExecutionException {
	ITextSelection cSelection = getCurrentSelection(editor);
	if (!cSelection.equals(selection)) {
		return cSelection;
	} else {
		return super.getCmdSelection(editor, selection);
	}
}
 
Example 4
Source File: EmacsMovementHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ITextSelection getCmdSelection(ITextEditor editor,
		ITextSelection selection) throws ExecutionException {
	ITextSelection cSelection = getCurrentSelection(editor);
	if (!cSelection.equals(selection)) {
		return cSelection;
	} else {
		return super.getCmdSelection(editor, selection);
	}
}