下面列出了怎么用org.eclipse.ui.texteditor.TextEditorAction的API类实例代码及写法,或者点击链接到github查看源代码。
private static void initializeHighlightRange(IEditorPart editorPart) {
if (editorPart instanceof ITextEditor) {
IAction toggleAction= editorPart.getEditorSite().getActionBars().getGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY);
boolean enable= toggleAction != null;
if (enable && editorPart instanceof JavaEditor)
enable= JavaPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS);
else
enable= enable && toggleAction.isEnabled() && toggleAction.isChecked();
if (enable) {
if (toggleAction instanceof TextEditorAction) {
// Reset the action
((TextEditorAction)toggleAction).setEditor(null);
// Restore the action
((TextEditorAction)toggleAction).setEditor((ITextEditor)editorPart);
} else {
// Uncheck
toggleAction.run();
// Check
toggleAction.run();
}
}
}
}
@Override
public void contributeActions(XtextEditor xtextEditor) {
foldingActionGroup = new FoldingActionGroup(xtextEditor, xtextEditor.getInternalSourceViewer()) {
@Override
protected TextEditorAction createToggleFoldingAction(ITextEditor editor) {
TextEditorAction toggle = new ResourceActionExtension(FoldingMessages.getResourceBundle(),
"Projection.Toggle.", editor, ProjectionViewer.TOGGLE);
toggle.setChecked(true);
toggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
return toggle;
}
};
}
/**
* replace default cut/copy/paste actions with a version that provided by the factory, if one is injected
*/
protected void createClipboardActions() {
IClipboardActionFactory actionsFactory = getClipboardActionFactory();
if (actionsFactory != null) {
ResourceBundle bundle = XbaseEditorMessages.getBundleForConstructedKeys();
TextEditorAction action = actionsFactory.create(bundle, "Editor.Cut.", this, ITextOperationTarget.CUT); //$NON-NLS-1$
setAction(ITextEditorActionConstants.CUT, action);
action = actionsFactory.create(bundle, "Editor.Copy.", this, ITextOperationTarget.COPY); //$NON-NLS-1$
setAction(ITextEditorActionConstants.COPY, action);
action = actionsFactory.create(bundle, "Editor.Paste.", this, ITextOperationTarget.PASTE); //$NON-NLS-1$
setAction(ITextEditorActionConstants.PASTE, action);
}
}
private void restore(ITextEditor textEditor, String actionId) {
Boolean b = fMemento.get(actionId);
if (b != null && b) {
Control control = textEditor.getAdapter(Control.class);
if (control != null && !control.isDisposed()) {
// Do nothing if already disposed.
IAction action = textEditor.getAction(actionId);
if (action instanceof TextEditorAction) {
TextEditorAction textEditorAction = (TextEditorAction) action;
textEditorAction.setEditor(textEditor);
textEditorAction.update();
}
}
}
}
private void disable(ITextEditor textEditor, String actionId) {
IAction action = textEditor.getAction(actionId);
if (action != null && action instanceof TextEditorAction) {
TextEditorAction textEditorAction = (TextEditorAction) action;
fMemento.put(actionId, true);
textEditorAction.setEditor(null);
textEditorAction.update();
}
}
/**
* @since 2.8
*/
protected TextEditorAction createToggleFoldingAction(ITextEditor editor) {
return new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Toggle.", editor,
ProjectionViewer.TOGGLE, true);
}
@Override
public TextEditorAction create(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) {
ImportsAwareClipboardAction action = new ImportsAwareClipboardAction(bundle, prefix, editor, operationCode);
injector.injectMembers(action);
return action;
}
public TextEditorAction create(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode);