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

The following examples show how to use org.eclipse.swt.custom.StyledText#invokeAction() . 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: EmacsMovementHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	
	StyledText st = viewer.getTextWidget(); 
	String id = event.getCommand().getId(); 
	boolean isSelect =  isMarkEnabled(viewer,(ITextSelection)viewer.getSelection());
	int action = getDispatchId(id,isSelect);
	if (action > -1) {
		st.invokeAction(action);
	} else if ((id = getId(isSelect)) != null) {
		// support sexps 
		try {
			EmacsPlusUtils.executeCommand(id, null, activePart);
		} catch (Exception e) {
			e.printStackTrace();
		}			
	}
	return null;
}
 
Example 2
Source File: ConsoleCmdHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
	 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(org.eclipse.ui.console.TextConsoleViewer, IConsoleView, ExecutionEvent)
	 */
	public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
		IDocument doc = viewer.getDocument();
		int action = -1;
		try {
			StyledText st = viewer.getTextWidget();
			action = getDispatchId(getId(event, viewer));
			if (action > -1) {
				// set up for kill ring
				doc.addDocumentListener(KillRing.getInstance());
//  			setUpUndo(viewer);
				st.invokeAction(action);
			}
		} finally {
			// remove kill ring behavior
			if (action > -1) {
				doc.removeDocumentListener(KillRing.getInstance());
			}
			KillRing.getInstance().setKill(null, false);
		}
		return null;
	}
 
Example 3
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
	if (!validateEditorInputState())
		return;

	final ISourceViewer viewer = getSourceViewer();
	StyledText text = viewer.getTextWidget();
	Point widgetSelection = text.getSelection();
	if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) {
		final int caret = text.getCaretOffset();
		final int offset = modelOffset2WidgetOffset(viewer, position);

		if (caret == widgetSelection.x)
			text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y);
		else
			text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x);
		text.invokeAction(ST.DELETE_NEXT);
	} else {
		Point selection = viewer.getSelectedRange();
		final int caret, length;
		if (selection.y != 0) {
			caret = selection.x;
			length = selection.y;
		} else {
			caret = widgetOffset2ModelOffset(viewer, text.getCaretOffset());
			length = position - caret;
		}

		try {
			viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$
		} catch (BadLocationException exception) {
			// Should not happen
		}
	}
}
 
Example 4
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void setCaretPosition(int position) {
	if (!validateEditorInputState())
		return;

	final int length;
	final ISourceViewer viewer = getSourceViewer();
	StyledText text = viewer.getTextWidget();
	Point widgetSelection = text.getSelection();
	if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) {
		final int caret = text.getCaretOffset();
		final int offset = modelOffset2WidgetOffset(viewer, position);

		if (caret == widgetSelection.x)
			text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y);
		else
			text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x);
		text.invokeAction(ST.DELETE_PREVIOUS);
	} else {
		Point selection = viewer.getSelectedRange();
		if (selection.y != 0) {
			position = selection.x;
			length = selection.y;
		} else {
			length = widgetOffset2ModelOffset(viewer, text.getCaretOffset()) - position;
		}

		try {
			viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$
		} catch (BadLocationException exception) {
			// Should not happen
		}
	}
}
 
Example 5
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
	if (!validateEditorInputState())
		return;

	final ISourceViewer viewer= getSourceViewer();
	StyledText text= viewer.getTextWidget();
	Point widgetSelection= text.getSelection();
	if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) {
		final int caret= text.getCaretOffset();
		final int offset= modelOffset2WidgetOffset(viewer, position);

		if (caret == widgetSelection.x)
			text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y);
		else
			text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x);
		text.invokeAction(ST.DELETE_NEXT);
	} else {
		Point selection= viewer.getSelectedRange();
		final int caret, length;
		if (selection.y != 0) {
			caret= selection.x;
			length= selection.y;
		} else {
			caret= widgetOffset2ModelOffset(viewer, text.getCaretOffset());
			length= position - caret;
		}

		try {
			viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$
		} catch (BadLocationException exception) {
			// Should not happen
		}
	}
}
 
Example 6
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setCaretPosition(int position) {
	if (!validateEditorInputState())
		return;

	final int length;
	final ISourceViewer viewer= getSourceViewer();
	StyledText text= viewer.getTextWidget();
	Point widgetSelection= text.getSelection();
	if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) {
		final int caret= text.getCaretOffset();
		final int offset= modelOffset2WidgetOffset(viewer, position);

		if (caret == widgetSelection.x)
			text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y);
		else
			text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x);
		text.invokeAction(ST.DELETE_PREVIOUS);
	} else {
		Point selection= viewer.getSelectedRange();
		if (selection.y != 0) {
			position= selection.x;
			length= selection.y;
		} else {
			length= widgetOffset2ModelOffset(viewer, text.getCaretOffset()) - position;
		}

		try {
			viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$
		} catch (BadLocationException exception) {
			// Should not happen
		}
	}
}
 
Example 7
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setCaretPosition(final int position) {
    if (!validateEditorInputState()) {
        return;
    }

    final ISourceViewer viewer = getSourceViewer();
    StyledText text = viewer.getTextWidget();
    Point widgetSelection = text.getSelection();
    if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) {
        final int caret = text.getCaretOffset();
        final int offset = modelOffset2WidgetOffset(viewer, position);

        if (caret == widgetSelection.x) {
            text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y);
        } else {
            text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x);
        }
        text.invokeAction(ST.DELETE_NEXT);
    } else {
        Point selection = viewer.getSelectedRange();
        final int caret, length;
        if (selection.y != 0) {
            caret = selection.x;
            length = selection.y;
        } else {
            caret = widgetOffset2ModelOffset(viewer, text.getCaretOffset());
            length = position - caret;
        }

        try {
            viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$
        } catch (BadLocationException exception) {
            // Should not happen
        }
    }
}
 
Example 8
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setCaretPosition(int position) {
    if (!validateEditorInputState()) {
        return;
    }

    final int length;
    final ISourceViewer viewer = getSourceViewer();
    StyledText text = viewer.getTextWidget();
    Point widgetSelection = text.getSelection();
    if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) {
        final int caret = text.getCaretOffset();
        final int offset = modelOffset2WidgetOffset(viewer, position);

        if (caret == widgetSelection.x) {
            text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y);
        } else {
            text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x);
        }
        text.invokeAction(ST.DELETE_PREVIOUS);
    } else {
        Point selection = viewer.getSelectedRange();
        if (selection.y != 0) {
            position = selection.x;
            length = selection.y;
        } else {
            length = widgetOffset2ModelOffset(viewer, text.getCaretOffset()) - position;
        }

        try {
            viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$
        } catch (BadLocationException exception) {
            // Should not happen
        }
    }
}