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

The following examples show how to use org.eclipse.swt.custom.StyledText#setSelection() . 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: CompositeTabFolder.java    From ldparteditor with MIT License 6 votes vote down vote up
public void cut() {
    CompositeTab selection = (CompositeTab) this.getSelection();
    if (selection != null && !selection.getState().getFileNameObj().isReadOnly()) {
        final StyledText ct = selection.getTextComposite();
        if (!selection.getState().getFileNameObj().getVertexManager().isUpdated()){
            ct.copy();
            return;
        }
        final int x = ct.getSelection().x;
        if (ct.getSelection().y == x) {
            final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x));
            ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length());
        }
        final int x2 = ct.getSelection().x;
        if (ct.getSelection().y == x2) {
            ct.forceFocus();
            return;
        }
        ct.cut();
        ct.forceFocus();
    }
}
 
Example 2
Source File: CompositeTabFolder.java    From ldparteditor with MIT License 6 votes vote down vote up
public void delete() {
    CompositeTab selection = (CompositeTab) this.getSelection();
    if (selection != null && !selection.getState().getFileNameObj().isReadOnly()) {
        if (!selection.getState().getFileNameObj().getVertexManager().isUpdated()){
            return;
        }
        final StyledText ct = selection.getTextComposite();
        final int x = ct.getSelection().x;
        if (ct.getSelection().y == x) {
            final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x));
            ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length());
        }
        final int x2 = ct.getSelection().x;
        if (ct.getSelection().y == x2) {
            ct.forceFocus();
            return;
        }
        ct.insert(""); //$NON-NLS-1$
        ct.setSelection(new Point(x, x));
        ct.forceFocus();
    }
}
 
Example 3
Source File: StyledTextCellEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private void selectText() {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}
	// viewer.setSelectedRange(selectionOffset, selectionLength)
	int textLength = text.getText().length();
	if (textLength > 0) {
		EditorSelectionEnum selectionMode = getSelectionMode();
		if (selectionMode == EditorSelectionEnum.ALL) {
			text.setSelection(0, textLength);
		} else if (selectionMode == EditorSelectionEnum.END) {
			text.setSelection(textLength, textLength);
		}
	}
	text.setCaretOffset(textLength);
}
 
Example 4
Source File: FindReplaceDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void processFindResult(FindReasult reasult, int rowIndex, int findCol, boolean isForward) {
	if (tmxEditorImpWithNattable == null || tmxEditorImpWithNattable.isDispose()) {
		return;
	}
	statusLabel.setText("");

	TeActiveCellEditor.commit();
	tmxEditorImpWithNattable.selectCell(findCol, rowIndex);
	tmxEditorImpWithNattable.editSelectedCell();

	CellEditor cellEditor = (CellEditor) TeActiveCellEditor.getCellEditor();
	if (cellEditor != null) {
		StyledText text = cellEditor.getTextViewer().getTextWidget();
		IRegion region = reasult.getRegin();
		if (isForward) {
			text.setSelection(region.getOffset(), region.getOffset() + region.getLength());
		} else {
			text.setSelection(region.getOffset() + region.getLength(), region.getOffset());
		}
	}
}
 
Example 5
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void selectText() {
	StyledText text = viewer.getTextWidget();
	if (text == null || text.isDisposed()) {
		return;
	}
	// viewer.setSelectedRange(selectionOffset, selectionLength)
	int textLength = text.getText().length();
	if (textLength > 0) {
		EditorSelectionEnum selectionMode = getSelectionMode();
		if (selectionMode == EditorSelectionEnum.ALL) {
			text.setSelection(0, textLength);
		} else if (selectionMode == EditorSelectionEnum.END) {
			text.setSelection(textLength, textLength);
		}
	}
	text.setCaretOffset(textLength);
}
 
Example 6
Source File: ExpressionBuilder.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Insert a text string into the text area
 * 
 * @param text
 */
protected void insertText( String text )
{
	StyledText textWidget = sourceViewer.getTextWidget( );
	if ( !textWidget.isEnabled( ) )
	{
		return;
	}
	int selectionStart = textWidget.getSelection( ).x;
	textWidget.insert( text );
	textWidget.setSelection( selectionStart + text.length( ) );
	textWidget.setFocus( );

	if ( text.endsWith( "()" ) ) //$NON-NLS-1$
	{
		textWidget.setCaretOffset( textWidget.getCaretOffset( ) - 1 ); // Move
	}
}
 
Example 7
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 8
Source File: XtextDirectEditManager.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method is used to set the cell editors text
 * 
 * @param toEdit
 *            String to be set in the cell editor
 */
public void setEditText(String toEdit) {

	// Get the cell editor
	CellEditor cellEditor = getCellEditor();

	// IF the cell editor doesn't exist yet...
	if (cellEditor == null) {
		// Do nothing
		return;
	}

	// Get the Text Compartment Edit Part
	IXtextAwareEditPart textEP = (IXtextAwareEditPart) getEditPart();

	// Get the Text control
	StyledText textControl = (StyledText) cellEditor.getControl();

	// Set the Figures text
	textEP.setLabelText(toEdit);

	// See RATLC00522324
	if (cellEditor instanceof TextCellEditorEx) {
		((TextCellEditorEx) cellEditor).setValueAndProcessEditOccured(toEdit);
	} else {
		cellEditor.setValue(toEdit);
	}

	// Set the controls text and position the caret at the end of the text
	textControl.setSelection(toEdit.length());
}
 
Example 9
Source File: YankPopHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 *  Simulate yank pop
 *  
 * @see com.mulgasoft.emacsplus.commands.BaseYankHandler#paste(org.eclipse.core.commands.ExecutionEvent, org.eclipse.swt.custom.StyledText)
 */
protected void paste(ExecutionEvent event, StyledText widget, boolean isProcess) {
	KillRing kb = KillRing.getInstance();
	if (kb.isYanked()) {
		String cacheText = KillRing.getInstance().getClipboardText();
		String prevText = convertDelimiters(kb.lastYank(),isProcess);
		String yankText = convertDelimiters(kb.yankPop(),isProcess);
		try {
			int offset = widget.getCaretOffset();
			if (prevText == null || !prevText.equals(widget.getText(offset-prevText.length(), offset-1))) {
				kb.setYanked(false);
				EmacsPlusUtils.showMessage(HandlerUtil.getActivePart(event), EmacsPlusActivator.getString(YP_DISABLED),false);
				return;
			}
			widget.setRedraw(false);
			widget.setSelection(offset - prevText.length(), offset);
			kb.setClipboardText(yankText);
			super.paste(event, widget);
		} finally {
			if (cacheText != null) {
				kb.setClipboardText(cacheText);
			}
			widget.setRedraw(true);
		}
	} else {
		EmacsPlusUtils.showMessage(HandlerUtil.getActivePart(event), EmacsPlusActivator.getString(YP_DISABLED),false);
	}
}
 
Example 10
Source File: KillLineHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * When called from a console context, will use ST.CUT
 * 
 * @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer,
 *      IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	if (viewer.isEditable()) {
		IDocument doc = viewer.getDocument();
		StyledText st = viewer.getTextWidget();
		int offset = st.getCaretOffset();
		try {
			IRegion info = doc.getLineInformationOfOffset(offset);
			int noffset = info.getOffset() + info.getLength();
			if (offset == noffset) {
				int line = doc.getLineOfOffset(offset);
				if (++line < doc.getNumberOfLines()) {
					noffset = doc.getLineOffset(line);
					if (noffset == doc.getLength()) {
						noffset = offset;
					}
				}
			}
			if (offset != noffset) {
				st.redraw();
				st.setSelection(offset, noffset);
				KillRing.getInstance().setKill(CUT_LINE_TO_END, false);
				return super.consoleDispatch(viewer, activePart, event);
			}
			viewer.refresh();
		} catch (BadLocationException e) {
		}
	}
	return null;
}
 
Example 11
Source File: MarkUtils.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Support simple clear mark/selection on TextConsole
 *
 * @param viewer
 */
public static void clearConsoleMark(TextConsoleViewer viewer) {
	if (viewer != null) {
		StyledText st = viewer.getTextWidget();
		st.setSelection(st.getCaretOffset());
		viewer.setMark(-1);
	}
}
 
Example 12
Source File: ExpressionTreeSupport.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Insert a text string into the text area
 * 
 * @param text
 */
protected void insertText( String text )
{
	StyledText textWidget = expressionViewer.getTextWidget( );
	if ( !textWidget.isEnabled( ) )
	{
		return;
	}
	int selectionStart = textWidget.getSelection( ).x;
	if ( text.equalsIgnoreCase( "x++" ) ) //$NON-NLS-1$
	{
		text = textWidget.getSelectionText( ) + "++";//$NON-NLS-1$
	}
	else if ( text.equalsIgnoreCase( "x--" ) )//$NON-NLS-1$
	{
		text = textWidget.getSelectionText( ) + "--";//$NON-NLS-1$
	}
	else if ( text.equalsIgnoreCase( "++x" ) )//$NON-NLS-1$
	{
		text = "++" + textWidget.getSelectionText( );//$NON-NLS-1$
	}
	else if ( text.equalsIgnoreCase( "--x" ) )//$NON-NLS-1$
	{
		text = "--" + textWidget.getSelectionText( );//$NON-NLS-1$
	}

	textWidget.insert( text );
	textWidget.setSelection( selectionStart + text.length( ) );
	textWidget.setFocus( );

	if ( text.endsWith( "()" ) ) //$NON-NLS-1$
	{
		textWidget.setCaretOffset( textWidget.getCaretOffset( ) - 1 ); // Move
	}
}
 
Example 13
Source File: SQLDataSetEditorPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Insert a text string into the text area
 * 
 * @param text
 */
private void insertText( String text )
{
	if ( text == null )
		return;

	StyledText textWidget = viewer.getTextWidget( );
	int selectionStart = textWidget.getSelection( ).x;
	textWidget.insert( text );
	textWidget.setSelection( selectionStart + text.length( ) );
	textWidget.setFocus( );
}
 
Example 14
Source File: FindReplaceDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void replace() {
	if (tmxEditorImpWithNattable == null || tmxEditorImpWithNattable.isDispose()) {
		return;
	}
	String findStr = findTextCombo.getText();
	if (findStr == null || findStr.length() == 0) {
		return;
	}
	String replaceStr = replaceTextCombo.getText();
	if (replaceStr == null || replaceStr.length() == 0) {
		return;
	}
	CellEditor cellEditor = (CellEditor) TeActiveCellEditor.getCellEditor();
	if (cellEditor != null) {
		StyledText text = cellEditor.getTextViewer().getTextWidget();
		String sleText = cellEditor.getTextViewer().getSelectionText();
		if (sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase()) && !sleText.equals(replaceStr)) {
			Matcher matcher = PlaceHolderEditModeBuilder.PATTERN.matcher(sleText);
			StringBuilder sb = new StringBuilder();
			while (matcher.find()) {
				sb.append(matcher.group());
			}
			sb.insert(0, replaceStr);
			Point p = text.getSelection();
			text.replaceTextRange(p.x, p.y - p.x, sb.toString());
			text.setSelection(p.x, p.x + replaceStr.length());
			TeActiveCellEditor.commitWithoutClose();
			updateCombHistory(replaceTextCombo);
		}
	}
}
 
Example 15
Source File: CompositeTabFolder.java    From ldparteditor with MIT License 5 votes vote down vote up
public void copy() {
    CompositeTab selection = (CompositeTab) this.getSelection();
    if (selection != null) {
        final StyledText ct = selection.getTextComposite();
        final int x = ct.getSelection().x;
        if (ct.getSelection().y == x) {
            final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x));
            ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length());
        }
        ct.copy();
        ct.forceFocus();
    }
}
 
Example 16
Source File: StyledTextContentAdapter.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
public void insertControlContents(Control control, String text,
		int cursorPosition) {
	StyledText styledText = (StyledText) control;
	Point selection = ((StyledText) control).getSelection();
	
	int position = selection.x;
	do {
		position--;
		} while (!ContentProposalProvider.isDot(
				styledText.getText(), position)&& position > 0);
	/** dot should not be replaced */
	if (position != 0) {
		position++;
		
	}
	

	styledText.setSelection(new Point(position, selection.x));
	((StyledText) control).insert(text);
	if (cursorPosition < text.length()) {
		((StyledText) control).setSelection(selection.x + cursorPosition,
				selection.x + cursorPosition);
	}else{

		setCursorPosition(control,position+text.length());
	}
	
}
 
Example 17
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected EmbeddedEditor createSpecificationEditor() {
	ContextScopeHandler.defineContext(EMBEDDED_TEXT_EDITOR_SCOPE, TEXT_EDITOR_SCOPE);
	EmbeddedEditor embeddedEditor = createEmbeddedEditor();
	embeddedEditor.createPartialEditor();
	GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(embeddedEditor.getViewer().getControl());
	StyledText text = embeddedEditor.getViewer().getTextWidget();
	text.setAlwaysShowScrollBars(false);
	text.setSelection(0);
	text.setKeyBinding(SWT.MOD1 | SWT.KEY_MASK & 'a', ST.SELECT_ALL);
	initXtextSelectionProvider(text);
	initContextMenu(text);
	text.addModifyListener((event) -> editorPart.firePropertyChange(IEditorPart.PROP_DIRTY));
	text.setEnabled(editorPart.isEditable());
	return embeddedEditor;
}
 
Example 18
Source File: HsMultiActiveCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public static void setSelectionText(StyledTextCellEditor editor, int start, int length) {
	if (editor != null && !editor.isClosed()) {
		StyledText text = editor.viewer.getTextWidget();
		text.setSelection(start, start + length);
	}
}
 
Example 19
Source File: HsMultiActiveCellEditor.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public static void setSelectionText(StyledTextCellEditor editor, int start, int length) {
	if (editor != null && !editor.isClosed()) {
		StyledText text = editor.viewer.getTextWidget();
		text.setSelection(start, start + length);
	}
}