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

The following examples show how to use org.eclipse.swt.custom.StyledText#addModifyListener() . 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: Comment.java    From Rel with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildControlPanel(Composite container) {
	container.setLayout(new GridLayout(1, false));

	Label label = new Label(container, SWT.None);
	label.setText("Comment:");

	StyledText expression = new StyledText(container, SWT.MULTI);
	expression.setText(operatorLabel.getText());
	expression.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	expression.addModifyListener(new ModifyListener() {
		@Override
		public void modifyText(ModifyEvent e) {
			operatorLabel.setText(expression.getText());
			Comment.this.pack();
			container.getShell().pack();
		}
	});
}
 
Example 2
Source File: CellEditorGlobalActionHanlder.java    From tmxeditor8 with GNU General Public License v2.0 6 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(CellEditorTextViewer viewer) {
	if (viewer == null) {
		return;
	}
	this.viewer = viewer;
	StyledText textControl = viewer.getTextWidget();

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

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

	updateActionsEnableState();
}
 
Example 3
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 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: HsMultiCellEditorControl.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 当文本处于正在编辑时,实时进行拼写检查,<div style='color:red'>该方法与{@link #tgtTextFirstRealTimeSpellCheck} 类似</div>
 */
private static void tgtTextRealTimeSpellCheck(final String tgtLang, final HsMultiCellEditor targetEditor) {
	final StyledTextCellEditor tgtEditor = targetEditor.getCellEditor();
	final StyledText text = tgtEditor.getSegmentViewer().getTextWidget();
	if (tgtLang == null) {
		return;
	}
	text.addModifyListener(new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			String tgtText = text.getText();

			if (tgtText.isEmpty()) {
				return;
			}

			String endStr = tgtText.substring(tgtText.length() - 1, tgtText.length());
			if (endStr.matches(ENDREGEX)) {
				List<SingleWord> errorWordList = new LinkedList<SingleWord>();
				errorWordList = spellTrigger.getErrorWords(tgtText, tgtLang);
				if (errorWordList != null && errorWordList.size() > 0) {
					targetEditor.highLightedErrorWord(tgtText, errorWordList);
				} else {
					targetEditor.refreshErrorWordsStyle(null);
				}
			}
		}
	});
}
 
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: HsMultiCellEditorControl.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 当文本处于正在编辑时,实时进行拼写检查,<div style='color:red'>该方法与{@link #tgtTextFirstRealTimeSpellCheck} 类似</div>
 */
private static void tgtTextRealTimeSpellCheck(final String tgtLang, final HsMultiCellEditor targetEditor){
	final StyledTextCellEditor tgtEditor = targetEditor.getCellEditor();
	final StyledText text = tgtEditor.getSegmentViewer().getTextWidget();
	if (tgtLang == null) {
		return;
	}
	text.addModifyListener(new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			String tgtText = text.getText();
			
			if(tgtText.isEmpty()){
				return;
			}

			String endStr = tgtText.substring(tgtText.length() - 1, tgtText.length());
			if (endStr.matches(ENDREGEX)) {
				List<SingleWord> errorWordList = new LinkedList<SingleWord>();
				errorWordList = spellTrigger.getErrorWords(tgtText, tgtLang);
				if (errorWordList != null && errorWordList.size() > 0) {
					targetEditor.highLightedErrorWord(tgtText, errorWordList);
				}else {
					targetEditor.refreshErrorWordsStyle(null);
				}
			}
		}
	});
}
 
Example 8
Source File: SqlEditor.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void createStatementSection(Composite body, FormToolkit toolkit) {
	Section section = UI.section(body, toolkit, "SQL Statement");
	Composite composite = UI.sectionClient(section, toolkit, 1);
	queryText = new StyledText(composite, SWT.BORDER);
	toolkit.adapt(queryText);
	UI.gridData(queryText, true, false).heightHint = 150;
	queryText.addModifyListener(new SyntaxStyler(queryText));
	Actions.bind(section, runAction = new RunAction());
}