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

The following examples show how to use org.eclipse.swt.custom.StyledText#setKeyBinding() . 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: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void createNavigationActions() {
	super.createNavigationActions();

	final StyledText textWidget= getSourceViewer().getTextWidget();

	IAction action= new DeletePreviousSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD);
	setAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.BS, SWT.NULL);
	markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, true);

	action= new DeleteNextSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD);
	setAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.DEL, SWT.NULL);
	markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, true);
}
 
Example 2
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 3
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void createNavigationActions() {
	super.createNavigationActions();

	final StyledText textWidget= getSourceViewer().getTextWidget();

	IAction action= new SmartLineStartAction(textWidget, false);
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
	setAction(ITextEditorActionDefinitionIds.LINE_START, action);

	action= new SmartLineStartAction(textWidget, true);
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
	setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);

	action= new NavigatePreviousSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
	setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL);

	action= new NavigateNextSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
	setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL);

	action= new SelectPreviousSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
	setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL);

	action= new SelectNextSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
	setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL);
}
 
Example 4
Source File: XLIFFEditorActionHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a <code>Text</code> control to the handler so that the Cut, Copy, Paste, Delete, Undo, Redo and Select All
 * actions are redirected to it when active.
 * @param viewer
 *            the inline <code>Text</code> control
 */
public void addTextViewer(SegmentViewer viewer) {
	if (viewer == null) {
		return;
	}
	this.viewer = viewer;
	StyledText textControl = viewer.getTextWidget();

	// 移除 StyledText 默认绑定的 Delete 键。解决“按下 Delete 键后会删除两次”的 Bug。
	textControl.setKeyBinding(SWT.DEL, SWT.NULL);

	viewer.addSelectionChangedListener(new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			updateActionsEnableState();
		}
	});

	textControl.addModifyListener(new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			updateActionsEnableState();
		}
	});

	actionBar.setGlobalActionHandler(ActionFactory.CUT.getId(), textCutAction);
	actionBar.setGlobalActionHandler(ActionFactory.COPY.getId(), textCopyAction);
	actionBar.setGlobalActionHandler(ActionFactory.PASTE.getId(), textPasteAction);
	actionBar.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), textSelectAllAction);
	actionBar.setGlobalActionHandler(ActionFactory.DELETE.getId(), textDeleteAction);
	actionBar.setGlobalActionHandler(ActionFactory.UNDO.getId(), textUndoAction);
	actionBar.setGlobalActionHandler(ActionFactory.REDO.getId(), textRedoAction);

	if (textControl.isFocusControl()) {
		updateActionsEnableState();
	} else {
		actionBar.updateActionBars();
	}
}
 
Example 5
Source File: StyledTextCellEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
protected Control activateCell(final Composite parent, HsMultiCellEditor hsCellEditor) {
	this.hsCellEditor = hsCellEditor;
	StyledText text = createTextControl(parent);
	text.setBounds(hsCellEditor.getEditorBounds());
	// analyzeCellType(); // 分析单元格类型。
	this.cellType = hsCellEditor.getType();
	if (cellType == NatTableConstant.TARGET) {
		this.source = HsMultiActiveCellEditor.getSourceEditor().getOriginalCanonicalValue().toString();
		viewer.setSource(source); // 设置原文本,用来解析内部标记
	}

	editableManager.judgeEditable(); // 判断“可编辑”状态;

	// If we have an initial value, then
	Object originalCanonicalValue = this.hsCellEditor.getOriginalCanonicalValue();
	if (originalCanonicalValue != null) {
		setCanonicalValue(new UpdateDataBean(originalCanonicalValue.toString(), null, null));
	} else {
		setCanonicalValue(new UpdateDataBean());
	}

	// 改变关闭状态标识
	close = false;
	xliffEditor.getTable().addDisposeListener(this);

	// text.forceFocus();

	// 初始化撤销/重做管理器,设置步长为 50。
	viewer.initUndoManager(50);
	// 绑定全局 Edit 菜单
	actionHandler.addTextViewer(viewer);
	text.addKeyListener(movedKeyListener);

	// 移除向上和向下键默认事件处理,将此部分实现放到upAndDownKeyListener监听中
	text.setKeyBinding(SWT.ARROW_DOWN, SWT.NULL);
	text.setKeyBinding(SWT.ARROW_UP, SWT.NULL);
	addMouselistener(text);
	return text;
}
 
Example 6
Source File: XLIFFEditorActionHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a <code>Text</code> control to the handler so that the Cut, Copy, Paste, Delete, Undo, Redo and Select All
 * actions are redirected to it when active.
 * @param viewer
 *            the inline <code>Text</code> control
 */
public void addTextViewer(SegmentViewer viewer) {
	if (viewer == null) {
		return;
	}
	this.viewer = viewer;
	StyledText textControl = viewer.getTextWidget();

	// 移除 StyledText 默认绑定的 Delete 键。解决“按下 Delete 键后会删除两次”的 Bug。
	textControl.setKeyBinding(SWT.DEL, SWT.NULL);

	viewer.addSelectionChangedListener(new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			updateActionsEnableState();
		}
	});

	textControl.addModifyListener(new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			updateActionsEnableState();
		}
	});

	actionBar.setGlobalActionHandler(ActionFactory.CUT.getId(), textCutAction);
	actionBar.setGlobalActionHandler(ActionFactory.COPY.getId(), textCopyAction);
	actionBar.setGlobalActionHandler(ActionFactory.PASTE.getId(), textPasteAction);
	actionBar.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), textSelectAllAction);
	actionBar.setGlobalActionHandler(ActionFactory.DELETE.getId(), textDeleteAction);
	actionBar.setGlobalActionHandler(ActionFactory.UNDO.getId(), textUndoAction);
	actionBar.setGlobalActionHandler(ActionFactory.REDO.getId(), textRedoAction);

	if (textControl.isFocusControl()) {
		updateActionsEnableState();
	} else {
		actionBar.updateActionBars();
	}
}
 
Example 7
Source File: StyledTextCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected Control activateCell(final Composite parent, HsMultiCellEditor hsCellEditor) {
	this.hsCellEditor = hsCellEditor;
	StyledText text = createTextControl(parent);
	text.setBounds(hsCellEditor.getEditorBounds());
	// analyzeCellType(); // 分析单元格类型。
	this.cellType = hsCellEditor.getType();
	if (cellType == NatTableConstant.TARGET) {
		this.source = HsMultiActiveCellEditor.getSourceEditor().getOriginalCanonicalValue().toString();
		viewer.setSource(source); // 设置原文本,用来解析内部标记
	}

	editableManager.judgeEditable(); // 判断“可编辑”状态;

	// If we have an initial value, then
	Object originalCanonicalValue = this.hsCellEditor.getOriginalCanonicalValue();
	if (originalCanonicalValue != null) {
		setCanonicalValue(new UpdateDataBean(originalCanonicalValue.toString(), null, null));
	} else {
		setCanonicalValue(new UpdateDataBean());
	}

	// 改变关闭状态标识
	close = false;
	xliffEditor.getTable().addDisposeListener(this);

	text.forceFocus();

	// 初始化撤销/重做管理器,设置步长为 50。
	viewer.initUndoManager(50);
	// 绑定全局 Edit 菜单
	actionHandler.addTextViewer(viewer);
	text.addKeyListener(movedKeyListener);

	// 移除向上和向下键默认事件处理,将此部分实现放到upAndDownKeyListener监听中
	text.setKeyBinding(SWT.ARROW_DOWN, SWT.NULL);
	text.setKeyBinding(SWT.ARROW_UP, SWT.NULL);
	return text;
}
 
Example 8
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void createNavigationActions() {
	super.createNavigationActions();

	final StyledText textWidget = getSourceViewer().getTextWidget();

	IAction action = createSmartLineStartAction(textWidget, false);
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
	setAction(ITextEditorActionDefinitionIds.LINE_START, action);

	action = createSmartLineStartAction(textWidget, true);
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
	setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);

	action = createNavigatePreviousSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS);
	setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL);

	action = createNavigateNextSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT);
	setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL);

	action = createSelectPreviousSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS);
	setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL);

	action = createSelectNextSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT);
	setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL);

	action = createDeletePreviousSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD);
	setAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.BS, SWT.NULL);
	markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_PREVIOUS_WORD, true);

	action = createDeleteNextSubWordAction();
	action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD);
	setAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, action);
	textWidget.setKeyBinding(SWT.CTRL | SWT.DEL, SWT.NULL);
	markAsStateDependentAction(ITextEditorActionDefinitionIds.DELETE_NEXT_WORD, true);
}