org.eclipse.swt.custom.ExtendedModifyListener Java Examples

The following examples show how to use org.eclipse.swt.custom.ExtendedModifyListener. 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: ScriptConsoleViewer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param parent parent for the styled text
 * @param style style to be used
 */
public ScriptConsoleStyledText(Composite parent, int style) {
    super(parent, style);

    /**
     * The StyledText will change the caretOffset that we've updated during the modifications,
     * so, the verify and the extended modify listener will keep track if it actually does
     * that and will reset the caret to the position we actually added it.
     *
     * Feels like a hack but I couldn't find a better way to do it.
     */
    addVerifyListener(new VerifyListener() {

        @Override
        public void verifyText(VerifyEvent e) {
            internalCaretSet = -1;
        }
    });

    /**
     * Set it to the location we've set it to be.
     */
    addExtendedModifyListener(new ExtendedModifyListener() {

        @Override
        public void modifyText(ExtendedModifyEvent event) {
            if (internalCaretSet != -1) {
                if (internalCaretSet != getCaretOffset()) {
                    setCaretOffset(internalCaretSet);
                }
                internalCaretSet = -1;
            }
        }
    });

    initDragDrop();

    handleDeletePreviousWord = new HandleDeletePreviousWord();
    handleLineStartAction = new HandleLineStartAction();
}