@Override protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { fTextEditor = editor; fAction = new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$ fAction.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE); return fAction; }
/** * Creates and initializes the action for the given text editor and operation * code. The action configures its visual representation from the given resource * bundle. The action works by asking the text editor at the time for its * text operation target adapter (using * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that * operation with the given opcode. * * @param bundle the resource bundle * @param prefix a prefix to be prepended to the various resource keys * (described in <code>ResourceAction</code> constructor), or * <code>null</code> if none * @param editor the text editor * @param operationCode the operation code * @see TextEditorAction#TextEditorAction(ResourceBundle, String, ITextEditor) */ public TextOperationAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { super(bundle, prefix, editor); fOperationCode= operationCode; fAllowUpdate= true; update(); }
/** * Updates the actions. */ protected void update() { if (isEnabled()) { fToggle.update(); fToggle.setChecked(fViewer.getProjectionAnnotationModel() != null); fExpand.update(); fExpandAll.update(); fCollapse.update(); } }
/** * The <code>TextOperationAction</code> implementation of this * <code>IUpdate</code> method discovers the operation through the current * editor's <code>ITextOperationTarget</code> adapter, and sets the * enabled state accordingly. */ public void update() { if (!fAllowUpdate) return; super.update(); if (!fRunsOnReadOnly && !canModifyEditor()) { setEnabled(false); return; } ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor!= null && fOperationCode != -1) fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); setEnabled(isEnabled); }
public RutaGenerateActionGroup(RutaEditor editor, String groupName) { super(editor, groupName); Action action = new TextOperationAction(DLTKEditorMessages.getBundleForConstructedKeys(), "Format.", editor, ISourceViewer.FORMAT); //$NON-NLS-1$ action.setActionDefinitionId(IScriptEditorActionDefinitionIds.FORMAT); editor.setAction(DLTKActionConstants.FORMAT, action); editor.markAsStateDependentAction(DLTKActionConstants.FORMAT, true); editor.markAsSelectionDependentAction(DLTKActionConstants.FORMAT, true); } }
fToggle = new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$ fToggle.setChecked(true); fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE); editor.setAction("FoldingToggle", fToggle); //$NON-NLS-1$ fExpandAll = new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$ fExpandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL); editor.setAction("FoldingExpandAll", fExpandAll); //$NON-NLS-1$ fExpand = new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$ fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND); editor.setAction("FoldingExpand", fExpand); //$NON-NLS-1$ fCollapse = new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$ fCollapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE); editor.setAction("FoldingCollapse", fCollapse); //$NON-NLS-1$
/** * The <code>TextOperationAction</code> implementation of this * <code>IAction</code> method runs the operation with the current * operation code. */ public void run() { if (fOperationCode == -1 || fOperationTarget == null) return; ITextEditor editor= getTextEditor(); if (editor == null) return; if (!fRunsOnReadOnly && !validateEditorInputState()) return; Display display= null; IWorkbenchPartSite site= editor.getSite(); Shell shell= site.getShell(); if (shell != null && !shell.isDisposed()) display= shell.getDisplay(); BusyIndicator.showWhile(display, new Runnable() { public void run() { fOperationTarget.doOperation(fOperationCode); } }); }
@Override protected void createActions() { super.createActions(); ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ant.internal.ui.editor.AntEditorMessages"); //$NON-NLS-1$ IAction action = new TextOperationAction(bundle, "ContentFormat.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ action.setActionDefinitionId(IJavaEditorActionDefinitionIds.FORMAT); setAction("ContentFormat", action); //$NON-NLS-1$ fFoldingGroup = new FoldingActionGroup(this, getViewer()); action = new RenameInFileAction(this); action.setActionDefinitionId("org.eclipse.ant.ui.renameInFile"); //$NON-NLS-1$ setAction("renameInFile", action); //$NON-NLS-1$ }
toggle = new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$ toggle.setChecked(true); toggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE); editor.setAction("FoldingToggle", toggle); //$NON-NLS-1$ expandAll = new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$ expandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL); editor.setAction("FoldingExpandAll", expandAll); //$NON-NLS-1$ collapseAll = new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.CollapseAll.", editor, ProjectionViewer.COLLAPSE_ALL, true); //$NON-NLS-1$ collapseAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE_ALL); editor.setAction("FoldingCollapseAll", collapseAll); //$NON-NLS-1$ expand = new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$ expand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND); editor.setAction("FoldingExpand", expand); //$NON-NLS-1$ collapse = new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$ collapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE); editor.setAction("FoldingCollapse", collapse); //$NON-NLS-1$
/** * The <code>TextOperationAction</code> implementation of this * <code>IUpdate</code> method discovers the operation through the current * editor's <code>ITextOperationTarget</code> adapter, and sets the * enabled state accordingly. */ @Override public void update() { if (!fAllowUpdate) return; super.update(); if (!fRunsOnReadOnly && !canModifyEditor()) { setEnabled(false); return; } ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor!= null && fOperationCode != -1) fOperationTarget= editor.getAdapter(ITextOperationTarget.class); boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); setEnabled(isEnabled); }
/** * The <code>TextOperationAction</code> implementation of this * <code>IAction</code> method runs the operation with the current * operation code. */ @Override public void run() { if (fOperationCode == -1 || fOperationTarget == null) return; ITextEditor editor= getTextEditor(); if (editor == null) return; if (!fRunsOnReadOnly && !validateEditorInputState()) return; Display display= null; IWorkbenchPartSite site= editor.getSite(); Shell shell= site.getShell(); if (shell != null && !shell.isDisposed()) display= shell.getDisplay(); BusyIndicator.showWhile(display, new Runnable() { @Override public void run() { fOperationTarget.doOperation(fOperationCode); } }); }
/** * */ private void createQuickOutlineAction() { // Quick Outline Action ResourceAction action = new TextOperationAction(getBundleForConstructedKeys(), "QuickOutline.", this, //$NON-NLS-1$ PDEProjectionViewer.QUICK_OUTLINE, true); action.setActionDefinitionId(PDEActionConstants.COMMAND_ID_QUICK_OUTLINE); action.setText(PDEUIMessages.PDESourcePage_actionTextQuickOutline); action.setId(PDEActionConstants.COMMAND_ID_QUICK_OUTLINE); action.setImageDescriptor(PDEPluginImages.DESC_OVERVIEW_OBJ); setAction(PDEActionConstants.COMMAND_ID_QUICK_OUTLINE, action); }
@Override protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { TextOperationAction action = new TextOperationAction(AntEditorActionMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$ action.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL); return action; } }
/** * Creates and initializes the action for the given text editor and operation * code. The action configures its visual representation from the given resource * bundle. The action works by asking the text editor at the time for its * text operation target adapter (using * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that * operation with the given opcode. * * @param bundle the resource bundle * @param prefix a prefix to be prepended to the various resource keys * (described in <code>ResourceAction</code> constructor), or * <code>null</code> if none * @param editor the text editor * @param operationCode the operation code * @see TextEditorAction#TextEditorAction(ResourceBundle, String, ITextEditor) */ public TextOperationAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { super(bundle, prefix, editor); fOperationCode= operationCode; fAllowUpdate= true; update(); }
public void run() { ISourceViewer sourceViewer= getSourceViewer(); if (sourceViewer == null) { if (fTextOperationAction.isEnabled()) fTextOperationAction.run(); return; } if (sourceViewer instanceof ITextViewerExtension4) { ITextViewerExtension4 extension4= (ITextViewerExtension4) sourceViewer; if (extension4.moveFocusToWidgetToken()) return; } if (sourceViewer instanceof ITextViewerExtension2) { // does a text hover exist? ITextHover textHover= ((ITextViewerExtension2) sourceViewer).getCurrentTextHover(); if (textHover != null && makeTextHoverFocusable(sourceViewer, textHover)) return; } if (sourceViewer instanceof ISourceViewerExtension3) { // does an annotation hover exist? IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover(); if (annotationHover != null && makeAnnotationHoverFocusable(sourceViewer, annotationHover)) return; } // otherwise, just run the action if (fTextOperationAction.isEnabled()) fTextOperationAction.run(); }
/** * The <code>TextOperationAction</code> implementation of this * <code>IUpdate</code> method discovers the operation through the current * editor's <code>ITextOperationTarget</code> adapter, and sets the * enabled state accordingly. */ @Override public void update() { if (!fAllowUpdate) return; super.update(); if (!fRunsOnReadOnly && !canModifyEditor()) { setEnabled(false); return; } ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor!= null && fOperationCode != -1) fOperationTarget= editor.getAdapter(ITextOperationTarget.class); boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); setEnabled(isEnabled); }
/** * The <code>TextOperationAction</code> implementation of this * <code>IAction</code> method runs the operation with the current * operation code. */ @Override public void run() { if (fOperationCode == -1 || fOperationTarget == null) return; ITextEditor editor= getTextEditor(); if (editor == null) return; if (!fRunsOnReadOnly && !validateEditorInputState()) return; Display display= null; IWorkbenchPartSite site= editor.getSite(); Shell shell= site.getShell(); if (shell != null && !shell.isDisposed()) display= shell.getDisplay(); BusyIndicator.showWhile(display, () -> fOperationTarget.doOperation(fOperationCode)); }
action = new TextOperationAction( b, "", textEditor, ITextOperationTarget.PREFIX ); } else { action = new TextOperationAction( b, "", textEditor, ITextOperationTarget.STRIP_PREFIX );