use of org.eclipse.jface.text.WhitespaceCharacterPainter in project egit by eclipse.
the class SpellcheckableMessageArea method configureContextMenu.
private void configureContextMenu() {
final boolean editable = isEditable(sourceViewer);
TextViewerAction cutAction;
TextViewerAction undoAction;
TextViewerAction redoAction;
TextViewerAction pasteAction;
IAction quickFixAction;
if (editable) {
cutAction = createFromActionFactory(ActionFactory.CUT, ITextOperationTarget.CUT);
undoAction = createFromActionFactory(ActionFactory.UNDO, ITextOperationTarget.UNDO);
redoAction = createFromActionFactory(ActionFactory.REDO, ITextOperationTarget.REDO);
pasteAction = createFromActionFactory(ActionFactory.PASTE, ITextOperationTarget.PASTE);
quickFixAction = new QuickfixAction(sourceViewer);
} else {
cutAction = null;
undoAction = null;
redoAction = null;
pasteAction = null;
quickFixAction = null;
}
TextViewerAction copyAction = createFromActionFactory(ActionFactory.COPY, ITextOperationTarget.COPY);
TextViewerAction selectAllAction = createFromActionFactory(ActionFactory.SELECT_ALL, ITextOperationTarget.SELECT_ALL);
final TextEditorPropertyAction showWhitespaceAction = new TextEditorPropertyAction(UIText.SpellcheckableMessageArea_showWhitespace, sourceViewer, AbstractTextEditor.PREFERENCE_SHOW_WHITESPACE_CHARACTERS) {
private IPainter whitespaceCharPainter;
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
if (property.equals(getPreferenceKey()) || AbstractTextEditor.PREFERENCE_SHOW_LEADING_SPACES.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_ENCLOSED_SPACES.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_TRAILING_SPACES.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_LEADING_IDEOGRAPHIC_SPACES.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_ENCLOSED_IDEOGRAPHIC_SPACES.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_TRAILING_IDEOGRAPHIC_SPACES.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_LEADING_TABS.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_ENCLOSED_TABS.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_TRAILING_TABS.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_CARRIAGE_RETURN.equals(property) || AbstractTextEditor.PREFERENCE_SHOW_LINE_FEED.equals(property) || AbstractTextEditor.PREFERENCE_WHITESPACE_CHARACTER_ALPHA_VALUE.equals(property)) {
synchronizeWithPreference();
}
}
@Override
protected void toggleState(boolean checked) {
if (checked)
installPainter();
else
uninstallPainter();
}
/**
* Installs the painter on the viewer.
*/
private void installPainter() {
Assert.isTrue(whitespaceCharPainter == null);
ITextViewer v = getTextViewer();
if (v instanceof ITextViewerExtension2) {
IPreferenceStore store = getStore();
whitespaceCharPainter = new WhitespaceCharacterPainter(v, store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_LEADING_SPACES), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_ENCLOSED_SPACES), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_TRAILING_SPACES), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_LEADING_IDEOGRAPHIC_SPACES), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_ENCLOSED_IDEOGRAPHIC_SPACES), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_TRAILING_IDEOGRAPHIC_SPACES), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_LEADING_TABS), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_ENCLOSED_TABS), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_TRAILING_TABS), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_CARRIAGE_RETURN), store.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_LINE_FEED), store.getInt(AbstractTextEditor.PREFERENCE_WHITESPACE_CHARACTER_ALPHA_VALUE));
((ITextViewerExtension2) v).addPainter(whitespaceCharPainter);
}
}
/**
* Remove the painter from the viewer.
*/
private void uninstallPainter() {
if (whitespaceCharPainter == null)
return;
ITextViewer v = getTextViewer();
if (v instanceof ITextViewerExtension2)
((ITextViewerExtension2) v).removePainter(whitespaceCharPainter);
whitespaceCharPainter.deactivate(true);
whitespaceCharPainter = null;
}
};
MenuManager contextMenu = new MenuManager();
if (cutAction != null) {
contextMenu.add(cutAction);
}
contextMenu.add(copyAction);
if (pasteAction != null) {
contextMenu.add(pasteAction);
}
contextMenu.add(selectAllAction);
if (undoAction != null) {
contextMenu.add(undoAction);
}
if (redoAction != null) {
contextMenu.add(redoAction);
}
contextMenu.add(new Separator());
contextMenu.add(showWhitespaceAction);
contextMenu.add(new Separator());
if (editable) {
final SubMenuManager quickFixMenu = new SubMenuManager(contextMenu);
quickFixMenu.setVisible(true);
quickFixMenu.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
quickFixMenu.removeAll();
addProposals(quickFixMenu);
}
});
}
final StyledText textWidget = getTextWidget();
List<IAction> globalActions = new ArrayList<>();
if (editable) {
globalActions.add(cutAction);
globalActions.add(pasteAction);
globalActions.add(undoAction);
globalActions.add(redoAction);
globalActions.add(quickFixAction);
}
globalActions.add(copyAction);
globalActions.add(selectAllAction);
if (contentAssistAction != null) {
globalActions.add(contentAssistAction);
}
ActionUtils.setGlobalActions(textWidget, globalActions, getHandlerService());
textWidget.setMenu(contextMenu.createContextMenu(textWidget));
sourceViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (cutAction != null)
cutAction.update();
copyAction.update();
}
});
if (editable) {
sourceViewer.addTextListener(new ITextListener() {
@Override
public void textChanged(TextEvent event) {
if (undoAction != null)
undoAction.update();
if (redoAction != null)
redoAction.update();
}
});
}
textWidget.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent disposeEvent) {
showWhitespaceAction.dispose();
}
});
}
use of org.eclipse.jface.text.WhitespaceCharacterPainter in project eclipse.platform.text by eclipse.
the class ShowWhitespaceCharactersAction method installPainter.
/**
* Installs the painter on the editor.
*/
private void installPainter() {
Assert.isTrue(fWhitespaceCharPainter == null);
ITextViewer viewer = getTextViewer();
if (viewer instanceof ITextViewerExtension2) {
if (fStore != null) {
fWhitespaceCharPainter = new WhitespaceCharacterPainter(viewer, fShowLeadingSpaces, fShowEnclosedSpaces, fShowTrailingSpaces, fShowLeadingIdeographicSpaces, fShowEnclosedIdeographicSpaces, fShowTrailingIdeographicSpace, fShowLeadingTabs, fShowEnclosedTabs, fShowTrailingTabs, fShowCarriageReturn, fShowLineFeed, fAlpha);
} else {
fWhitespaceCharPainter = new WhitespaceCharacterPainter(viewer);
}
((ITextViewerExtension2) viewer).addPainter(fWhitespaceCharPainter);
}
}
Aggregations