Java Code Examples for org.eclipse.swt.custom.StyledText#showSelection()

The following examples show how to use org.eclipse.swt.custom.StyledText#showSelection() . 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: SearchMinibuffer.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
public void restoreState(StyledText text) {
	// WIDGET OFFSET 
	text.setSelectionRange(selection, length);
	text.showSelection();

	// relies on the contents of the StringBuilder
	if (mb != null) {
		getMB().init(mb);
	}
	if (rx != null) {
		getRX().init(rx);
	}			
	setMBLength(findLength);
	setRXLength(regLength);
	setSearchOffset(index);
	found= sfound;
	forward= sforward;

	// Recalculate the indices
	if (findLength <= currentCasePos)
		currentCasePos= -1;
	
	if (getSearchStates().size() < wrapPosition)
		setWrapPosition();
}
 
Example 2
Source File: TextViewerMoveLinesAction.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Performs similar to AbstractTextEditor.selectAndReveal, but does not update
 * the viewers highlight area.
 *
 * @param viewer the viewer that we want to select on
 * @param offset the offset of the selection
 * @param length the length of the selection
 */
private void selectAndReveal(ITextViewer viewer, int offset, int length) {
	// invert selection to avoid jumping to the end of the selection in st.showSelection()
	viewer.setSelectedRange(offset + length, -length);
	//viewer.revealRange(offset, length); // will trigger jumping
	StyledText st= viewer.getTextWidget();
	if (st != null)
		st.showSelection(); // only minimal scrolling
}
 
Example 3
Source File: JavaMoveLinesAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Performs similar to AbstractTextEditor.selectAndReveal, but does not update
 * the viewers highlight area.
 *
 * @param viewer the viewer that we want to select on
 * @param offset the offset of the selection
 * @param length the length of the selection
 */
private void selectAndReveal(ITextViewer viewer, int offset, int length) {
	// invert selection to avoid jumping to the end of the selection in st.showSelection()
	viewer.setSelectedRange(offset + length, -length);
	//viewer.revealRange(offset, length); // will trigger jumping
	StyledText st= viewer.getTextWidget();
	if (st != null)
		st.showSelection(); // only minimal scrolling
}
 
Example 4
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 5 votes vote down vote up
private void openFileGotoLine(SymitarFile file, int line){
	Object o;
	o = openFile(file);
	
	EditorComposite editor = null;
	if (o instanceof EditorComposite)
		editor = (EditorComposite) o;

	try {
		if(editor == null)
			return;
		StyledText newTxt = editor.getStyledText();
		//newTxt.setCaretOffset(newTxt.getText().length());
		newTxt.showSelection();


		int offset = newTxt.getOffsetAtLine(line);
		newTxt.setSelection(offset,offset);
		
		editor.handleCaretChange();
		// Drop Navigation Position
		newTxt.showSelection();
		editor.lineHighlight();
	} catch (IllegalArgumentException ex) {
		// Just ignore it
	}
}
 
Example 5
Source File: EditorComposite.java    From RepDev with GNU General Public License v3.0 5 votes vote down vote up
private Boolean matchVarAndGoto(Variable var, String varToMatch){
		Object o;
		if(var.getName().equals(varToMatch)){
			if( file.isLocal() )
				o = RepDevMain.mainShell.openFile(new SymitarFile(file.getDir(), var.getFilename(), file.getType()));
			else	
				o = RepDevMain.mainShell.openFile(new SymitarFile(sym, var.getFilename(), FileType.REPGEN));
			
			EditorComposite editor = null;

			if (o instanceof EditorComposite)
				editor = (EditorComposite) o;
//					if (token.getStart() >= 0 && editor != null) {
//						editor.getStyledText().setTopIndex(Math.max(0, task.getLine() - 10));
				try {
					StyledText newTxt = editor.getStyledText();
					newTxt.setCaretOffset(newTxt.getText().length());
					newTxt.showSelection();
					newTxt.setCaretOffset(var.getPos());
					editor.handleCaretChange();
					// Drop Navigation Position
					RepDevMain.mainShell.addToNavHistory(file, txt.getLineAtOffset(txt.getCaretOffset()));
					newTxt.showSelection();
					editor.lineHighlight();
				} catch (IllegalArgumentException ex) {
					// Just ignore it
				}
				editor.getStyledText().setFocus();
			return true;
		}
		return false;
	}
 
Example 6
Source File: EditorComposite.java    From RepDev with GNU General Public License v3.0 5 votes vote down vote up
private Boolean matchTokenAndGoto(Token token, String key, String nameToMAtch){
		Object o;
		int i = 0;
		if(token.getTokenType() != null && token.getTokenType().equals(TokenType.DEFINED_VARIABLE)){
			i = 1;
		}
				
		if(token.getTokenType() != null &&
			(token.getTokenType().equals(TokenType.PROCEDURE) || 
				token.getTokenType().equals(TokenType.DEFINED_VARIABLE)) &&
			token.getStr().equalsIgnoreCase(nameToMAtch)){
			if( file.isLocal() )
				o = RepDevMain.mainShell.openFile(new SymitarFile(file.getDir(), key, file.getType()));
			else	
				o = RepDevMain.mainShell.openFile(new SymitarFile(sym, key, FileType.REPGEN));
			
			EditorComposite editor = null;

			if (o instanceof EditorComposite)
				editor = (EditorComposite) o;
//			if (token.getStart() >= 0 && editor != null) {
//				editor.getStyledText().setTopIndex(Math.max(0, task.getLine() - 10));
				try {
					StyledText newTxt = editor.getStyledText();
					newTxt.setCaretOffset(newTxt.getText().length());
					newTxt.showSelection();
					newTxt.setCaretOffset(token.getBefore().getStart());
					editor.handleCaretChange();
					// Drop Navigation Position
					RepDevMain.mainShell.addToNavHistory(file, txt.getLineAtOffset(txt.getCaretOffset()));
					newTxt.showSelection();
					editor.lineHighlight();
				} catch (IllegalArgumentException ex) {
					// Just ignore it
				}
				editor.getStyledText().setFocus();
			return true;
		}
		return false;
	}
 
Example 7
Source File: PyMoveLineAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Performs similar to AbstractTextEditor.selectAndReveal, but does not update
 * the viewers highlight area.
 *
 * @param viewer the viewer that we want to select on
 * @param offset the offset of the selection
 * @param length the length of the selection
 */
private void selectAndReveal(ITextViewer viewer, int offset, int length) {
    if (viewer == null) {
        return; // in tests
    }
    // invert selection to avoid jumping to the end of the selection in st.showSelection()
    viewer.setSelectedRange(offset + length, -length);
    //viewer.revealRange(offset, length); // will trigger jumping
    StyledText st = viewer.getTextWidget();
    if (st != null) {
        st.showSelection(); // only minimal scrolling
    }
}