use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method updateInsertModeAction.
private void updateInsertModeAction() {
// drop out in this case.
if (getSite() == null)
return;
IAction action = getAction(ITextEditorActionConstants.TOGGLE_INSERT_MODE);
if (action != null) {
action.setEnabled(!fIsOverwriting);
action.setChecked(fInsertMode == SMART_INSERT);
}
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method handlePreferenceStoreChanged.
/**
* Handles a property change event describing a change of the editor's
* preference store and updates the preference related editor properties.
* <p>
* Subclasses may extend.
* </p>
*
* @param event the property change event
*/
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
if (fSourceViewer == null)
return;
String property = event.getProperty();
if (getFontPropertyPreferenceKey().equals(property))
// There is a separate handler for font preference changes
return;
if (PREFERENCE_COLOR_FOREGROUND.equals(property) || PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_SELECTION_FOREGROUND.equals(property) || PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_SELECTION_BACKGROUND.equals(property) || PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT.equals(property)) {
initializeViewerColors(fSourceViewer);
} else if (PREFERENCE_COLOR_FIND_SCOPE.equals(property)) {
initializeFindScopeColor(fSourceViewer);
} else if (PREFERENCE_USE_CUSTOM_CARETS.equals(property)) {
updateCaret();
} else if (PREFERENCE_WIDE_CARET.equals(property)) {
updateCaret();
}
if (affectsTextPresentation(event))
fSourceViewer.invalidateTextPresentation();
if (PREFERENCE_HYPERLINKS_ENABLED.equals(property)) {
if (fSourceViewer instanceof ITextViewerExtension6) {
IHyperlinkDetector[] detectors = getSourceViewerConfiguration().getHyperlinkDetectors(fSourceViewer);
int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(fSourceViewer);
ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) fSourceViewer;
textViewer6.setHyperlinkDetectors(detectors, stateMask);
}
return;
}
if (PREFERENCE_HYPERLINK_KEY_MODIFIER.equals(property)) {
if (fSourceViewer instanceof ITextViewerExtension6) {
ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) fSourceViewer;
IHyperlinkDetector[] detectors = getSourceViewerConfiguration().getHyperlinkDetectors(fSourceViewer);
int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(fSourceViewer);
textViewer6.setHyperlinkDetectors(detectors, stateMask);
}
return;
}
if (PREFERENCE_RULER_CONTRIBUTIONS.equals(property)) {
String[] difference = StringSetSerializer.getDifference((String) event.getOldValue(), (String) event.getNewValue());
IColumnSupport support = getAdapter(IColumnSupport.class);
for (int i = 0; i < difference.length; i++) {
RulerColumnDescriptor desc = RulerColumnRegistry.getDefault().getColumnDescriptor(difference[i]);
if (desc != null && support.isColumnSupported(desc)) {
boolean newState = !support.isColumnVisible(desc);
support.setColumnVisible(desc, newState);
}
}
return;
}
if (PREFERENCE_SHOW_WHITESPACE_CHARACTERS.equals(property) || PREFERENCE_SHOW_LEADING_SPACES.equals(property) || PREFERENCE_SHOW_ENCLOSED_SPACES.equals(property) || PREFERENCE_SHOW_TRAILING_SPACES.equals(property) || PREFERENCE_SHOW_LEADING_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_ENCLOSED_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_TRAILING_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_LEADING_TABS.equals(property) || PREFERENCE_SHOW_ENCLOSED_TABS.equals(property) || PREFERENCE_SHOW_TRAILING_TABS.equals(property) || PREFERENCE_SHOW_CARRIAGE_RETURN.equals(property) || PREFERENCE_SHOW_LINE_FEED.equals(property) || PREFERENCE_WHITESPACE_CHARACTER_ALPHA_VALUE.equals(property)) {
IAction action = getAction(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS);
if (action instanceof IUpdate)
((IUpdate) action).update();
return;
}
if (PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED.equals(property)) {
IPreferenceStore store = getPreferenceStore();
if (store != null && store.getBoolean(PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED))
installTextDragAndDrop(getSourceViewer());
else
uninstallTextDragAndDrop(getSourceViewer());
return;
}
if (PREFERENCE_HOVER_ENRICH_MODE.equals(property)) {
if (fSourceViewer instanceof ITextViewerExtension8) {
IPreferenceStore store = getPreferenceStore();
if (store != null) {
((ITextViewerExtension8) fSourceViewer).setHoverEnrichMode(convertEnrichModePreference(store.getInt(PREFERENCE_HOVER_ENRICH_MODE)));
}
}
return;
}
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method doSetInput.
/**
* Called directly from <code>setInput</code> and from within a workspace
* runnable from <code>init</code>, this method does the actual setting
* of the editor input. Closes the editor if <code>input</code> is
* <code>null</code>. Disconnects from any previous editor input and its
* document provider and connects to the new one.
* <p>
* Subclasses may extend.
* </p>
*
* @param input the input to be set
* @exception CoreException if input cannot be connected to the document
* provider
*/
protected void doSetInput(IEditorInput input) throws CoreException {
ISaveablesLifecycleListener listener = getSite().getService(ISaveablesLifecycleListener.class);
if (listener == null)
fSavable = null;
if (input == null) {
close(isSaveOnCloseNeeded());
if (fSavable != null) {
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
fSavable.disconnectEditor();
fSavable = null;
}
} else {
boolean mustSendLifeCycleEvent = false;
if (fSavable != null) {
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
fSavable.disconnectEditor();
fSavable = null;
mustSendLifeCycleEvent = true;
}
IEditorInput oldInput = getEditorInput();
if (oldInput != null)
getDocumentProvider().disconnect(oldInput);
super.setInput(input);
updateDocumentProvider(input);
IDocumentProvider provider = getDocumentProvider();
if (provider == null) {
IStatus s = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, EditorMessages.Editor_error_no_provider, null);
throw new CoreException(s);
}
provider.connect(input);
initializeTitle(input);
if (fSourceViewer != null) {
initializeSourceViewer(input);
// Reset the undo context for the undo and redo action handlers
IAction undoAction = getAction(ITextEditorActionConstants.UNDO);
IAction redoAction = getAction(ITextEditorActionConstants.REDO);
boolean areOperationActionHandlersInstalled = undoAction instanceof OperationHistoryActionHandler && redoAction instanceof OperationHistoryActionHandler;
IUndoContext undoContext = getUndoContext();
if (undoContext != null && areOperationActionHandlersInstalled) {
((OperationHistoryActionHandler) undoAction).setContext(undoContext);
((OperationHistoryActionHandler) redoAction).setContext(undoContext);
} else {
createUndoRedoActions();
}
}
if (fIsOverwriting)
toggleOverwriteMode();
setInsertMode(getLegalInsertModes().get(0));
updateCaret();
updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE);
if (fSelectionListener != null)
fSelectionListener.setDocument(getDocumentProvider().getDocument(input));
IVerticalRuler ruler = getVerticalRuler();
if (ruler instanceof CompositeRuler)
updateContributedRulerColumns((CompositeRuler) ruler);
// Send savable life-cycle if needed.
if (mustSendLifeCycleEvent && listener != null)
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false));
}
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method createNavigationActions.
/**
* Creates action entries for all SWT StyledText actions as defined in
* <code>org.eclipse.swt.custom.ST</code>. Overwrites and
* extends the list of these actions afterwards.
* <p>
* Subclasses may extend.
* </p>
* @since 2.0
*/
protected void createNavigationActions() {
IAction action;
StyledText textWidget = fSourceViewer.getTextWidget();
for (int i = 0; i < ACTION_MAP.length; i++) {
IdMapEntry entry = ACTION_MAP[i];
action = new TextNavigationAction(textWidget, entry.getAction());
action.setActionDefinitionId(entry.getActionId());
setAction(entry.getActionId(), action);
}
// $NON-NLS-1$
action = new ToggleOverwriteModeAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ToggleOverwriteMode.");
action.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_OVERWRITE);
setAction(ITextEditorActionDefinitionIds.TOGGLE_OVERWRITE, action);
textWidget.setKeyBinding(SWT.INSERT, SWT.NULL);
action = new ScrollLinesAction(-1);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SCROLL_LINE_UP);
setAction(ITextEditorActionDefinitionIds.SCROLL_LINE_UP, action);
action = new ScrollLinesAction(1);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SCROLL_LINE_DOWN);
setAction(ITextEditorActionDefinitionIds.SCROLL_LINE_DOWN, action);
action = new LineEndAction(textWidget, false);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_END);
setAction(ITextEditorActionDefinitionIds.LINE_END, action);
action = new LineStartAction(textWidget, false);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
setAction(ITextEditorActionDefinitionIds.LINE_START, action);
action = new LineEndAction(textWidget, true);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_END);
setAction(ITextEditorActionDefinitionIds.SELECT_LINE_END, action);
action = new LineStartAction(textWidget, true);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);
// to accommodate https://bugs.eclipse.org/bugs/show_bug.cgi?id=51516
// nullify handling of DELETE key by StyledText
textWidget.setKeyBinding(SWT.DEL, SWT.NULL);
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method createAccessibilityActions.
/**
* Creates this editor's accessibility actions.
* @since 2.0
*/
private void createAccessibilityActions() {
IAction action = new ShowRulerContextMenuAction();
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_RULER_CONTEXT_MENU);
setAction(ITextEditorActionDefinitionIds.SHOW_RULER_CONTEXT_MENU, action);
}
Aggregations