org.eclipse.swt.custom.ST Java Examples

The following examples show how to use org.eclipse.swt.custom.ST. 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: CommentLineAction.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void run()
{
    int caretOffset = text.getCaretOffset();
    int lineIndex = text.getLineAtOffset(caretOffset);
    int lineStart = getLineStart(lineIndex);
    String lineText = text.getLine(lineIndex);

    // Move caret to next line
    if (lineIndex+1 < text.getLineCount())
    {
        text.invokeAction(ST.LINE_DOWN);
    }

    if (lineText.startsWith("--"))
    {
        // Uncomment
        text.replaceTextRange(lineStart, 2, "");
    }
    else
    {
        // Comment
        text.replaceTextRange(lineStart, 0, "--");
    }
}
 
Example #2
Source File: StyledTextWithoutVerticalBar.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void replaceStyleRanges(int start, int length, StyleRange[] styles) {
    checkWidget();
    if (isListening(ST.LineGetStyle)) {
        return;
    }
    if (styles == null) {
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
    }
    RangesInfo rangesInfo = createRanges(styles, this.getCharCount());
    int[] newRanges = rangesInfo.newRanges;
    styles = rangesInfo.styles;
    try {
        setStyleRanges(start, length, newRanges, styles);
    } catch (Exception e) {
        Log.log(e);
    }
}
 
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: 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
        }
    }
}
 
Example #5
Source File: GridCopyEnable.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void doAction(int action) {
	switch (action) {
	case ST.COPY:
		copy();
		break;
	default:
		break;
	}
}
 
Example #6
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 #7
Source File: GridCopyEnable.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the selection based on the caret position
 */
void doMouseSelection() {
	if (caretOffset <= selection.x
			|| (caretOffset > selection.x && caretOffset < selection.y && selectionAnchor == selection.x)) {
		doSelection(ST.COLUMN_PREVIOUS);// left
	} else {
		doSelection(ST.COLUMN_NEXT); // right
	}
}
 
Example #8
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 #9
Source File: GridCopyEnable.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void doAction(int action) {
	switch (action) {
	case ST.COPY:
		copy();
		break;
	default:
		break;
	}
}
 
Example #10
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 #11
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 #12
Source File: GridCopyEnable.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the selection based on the caret position
 */
void doMouseSelection() {
	if (caretOffset <= selection.x
			|| (caretOffset > selection.x && caretOffset < selection.y && selectionAnchor == selection.x)) {
		doSelection(ST.COLUMN_PREVIOUS);// left
	} else {
		doSelection(ST.COLUMN_NEXT); // right
	}
}
 
Example #13
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 #14
Source File: MatchViewerBodyMenu.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
	view.copyEnable.doAction(ST.COPY);
}
 
Example #15
Source File: ScriptConsoleViewer.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Execute some action.
 */
@Override
public void invokeAction(int action) {
    //some actions have a different scope (not in selected range / out of selected range)
    switch (action) {
        case ST.LINE_START:
            if (handleLineStartAction.execute(getDocument(), getCaretOffset(), getCommandLineOffset(),
                    ScriptConsoleViewer.this)) {
                return;
            } else {
                super.invokeAction(action);
            }

    }

    if (isSelectedRangeEditable()) {
        try {
            int historyChange = 0;
            switch (action) {
                case ST.LINE_UP:
                    historyChange = 1;
                    break;

                case ST.LINE_DOWN:
                    historyChange = 2;
                    break;

                case ST.DELETE_PREVIOUS:
                    handleBackspaceAction.execute(getDocument(),
                            (ITextSelection) ScriptConsoleViewer.this.getSelection(), getCommandLineOffset());
                    return;

                case ST.DELETE_WORD_PREVIOUS:
                    handleDeletePreviousWord.execute(getDocument(), getCaretOffset(), getCommandLineOffset());
                    return;
            }

            if (historyChange != 0) {
                if (changedAfterLastHistoryRequest) {
                    //only set a new match if it didn't change since the last time we did an UP/DOWN
                    history.setMatchStart(getCommandLine());
                }
                boolean didChange;
                if (historyChange == 1) {
                    didChange = history.prev();
                } else {
                    didChange = history.next();
                }

                if (didChange) {
                    inHistoryRequests += 1;
                    try {
                        listener.setCommandLine(history.get());
                        setCaretOffset(getDocument().getLength());
                    } finally {
                        inHistoryRequests -= 1;
                    }
                }
                changedAfterLastHistoryRequest = false;
                return;
            }

        } catch (BadLocationException e) {
            Log.log(e);
            return;
        }

        super.invokeAction(action);

    } else {
        //we're not in the editable range (so, as the command was already checked to be valid,
        //let's just let it keep its way)
        super.invokeAction(action);
    }
}
 
Example #16
Source File: GridCopyEnable.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
void doSelection(int direction) {
	int redrawStart = -1;
	int redrawEnd = -1;
	if (selectionAnchor == -1) {
		selectionAnchor = selection.x;
	}
	if (direction == ST.COLUMN_PREVIOUS) {
		if (caretOffset < selection.x) {
			// grow selection
			redrawEnd = selection.x;
			redrawStart = selection.x = caretOffset;
			if (selectionAnchor != selection.y) {
				redrawEnd = selection.y;
				selection.y = selectionAnchor;
			}
		} else if (selectionAnchor == selection.x && caretOffset < selection.y) {
			// caret moved towards selection anchor (left side of selection).
			// shrink selection
			redrawEnd = selection.y;
			redrawStart = selection.y = caretOffset;
		}
	} else {
		if (caretOffset > selection.y) {
			// grow selection
			redrawStart = selection.y;
			redrawEnd = selection.y = caretOffset;
			if (selection.x != selectionAnchor) {
				redrawStart = selection.x;
				selection.x = selectionAnchor;
			}
		} else if (selectionAnchor == selection.y && caretOffset > selection.x) {
			// caret moved towards selection anchor (right side of selection).
			// shrink selection
			redrawStart = selection.x;
			redrawEnd = selection.x = caretOffset;
		}
	}

	if (redrawStart != -1 && redrawEnd != -1) {
		Rectangle rect = layout.getBounds(redrawStart, redrawEnd);
		gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
	}
}
 
Example #17
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new navigate next sub-word action.
 */
public NavigateNextSubWordAction() {
    super(ST.WORD_NEXT);
}
 
Example #18
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new delete next sub-word action.
 */
public DeleteNextSubWordAction() {
    super(ST.DELETE_WORD_NEXT);
}
 
Example #19
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new select next sub-word action.
 */
public SelectNextSubWordAction() {
    super(ST.SELECT_WORD_NEXT);
}
 
Example #20
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new navigate previous sub-word action.
 */
public NavigatePreviousSubWordAction() {
    super(ST.WORD_PREVIOUS);
}
 
Example #21
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new delete previous sub-word action.
 */
public DeletePreviousSubWordAction() {
    super(ST.DELETE_WORD_PREVIOUS);
}
 
Example #22
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new select previous sub-word action.
 */
public SelectPreviousSubWordAction() {
    super(ST.SELECT_WORD_PREVIOUS);
}
 
Example #23
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates a new navigate next sub-word action.
 */
public NavigateNextSubWordAction() {
	super(ST.WORD_NEXT);
}
 
Example #24
Source File: CmdPanelInput.java    From Rel with Apache License 2.0 4 votes vote down vote up
public void delete() {
	inputText.invokeAction(ST.DELETE_NEXT);
}
 
Example #25
Source File: GridCopyEnable.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
void doSelection(int direction) {
	int redrawStart = -1;
	int redrawEnd = -1;
	if (selectionAnchor == -1) {
		selectionAnchor = selection.x;
	}
	if (direction == ST.COLUMN_PREVIOUS) {
		if (caretOffset < selection.x) {
			// grow selection
			redrawEnd = selection.x;
			redrawStart = selection.x = caretOffset;
			if (selectionAnchor != selection.y) {
				redrawEnd = selection.y;
				selection.y = selectionAnchor;
			}
		} else if (selectionAnchor == selection.x && caretOffset < selection.y) {
			// caret moved towards selection anchor (left side of selection).
			// shrink selection
			redrawEnd = selection.y;
			redrawStart = selection.y = caretOffset;
		}
	} else {
		if (caretOffset > selection.y) {
			// grow selection
			redrawStart = selection.y;
			redrawEnd = selection.y = caretOffset;
			if (selection.x != selectionAnchor) {
				redrawStart = selection.x;
				selection.x = selectionAnchor;
			}
		} else if (selectionAnchor == selection.y && caretOffset > selection.x) {
			// caret moved towards selection anchor (right side of selection).
			// shrink selection
			redrawStart = selection.x;
			redrawEnd = selection.x = caretOffset;
		}
	}

	if (redrawStart != -1 && redrawEnd != -1) {
		Rectangle rect = layout.getBounds(redrawStart, redrawEnd);
		gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
	}
}
 
Example #26
Source File: MatchViewerBodyMenu.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
	view.copyEnable.doAction(ST.COPY);
}
 
Example #27
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new select previous sub-word action.
 */
public SelectPreviousSubWordAction() {
	super(ST.SELECT_WORD_PREVIOUS);
}
 
Example #28
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new delete previous sub-word action.
 */
public DeletePreviousSubWordAction() {
	super(ST.DELETE_WORD_PREVIOUS);
}
 
Example #29
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new navigate previous sub-word action.
 */
public NavigatePreviousSubWordAction() {
	super(ST.WORD_PREVIOUS);
}
 
Example #30
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new select next sub-word action.
 */
public SelectNextSubWordAction() {
	super(ST.SELECT_WORD_NEXT);
}