public void update() { super.update(); if (!isEnabled()) return; if (!canModifyEditor()) { setEnabled(false); return; } ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor != null && fOperationCode != -1) fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); }
/** * 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 ShiftAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { super(bundle, prefix, editor); fOperationCode= operationCode; update(); }
/** * 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 (!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); } }); }
public boolean isEnabled(boolean isWritable) { if (!isWritable) return false; /* * Note that this implementation still honors the result returned by canDoOperation. * I.e. if the viewer is set to read-only, this method still returns false. * It covers the case in which the viewer is also writable. * */ ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor!= null && fOperationCode != -1) fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); return (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); } }
setAction(ITextEditorActionConstants.SELECT_ALL, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftRight.", this, ITextOperationTarget.SHIFT_RIGHT); //$NON-NLS-1$ action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_RIGHT_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_RIGHT); setAction(ITextEditorActionConstants.SHIFT_RIGHT, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftRight.", this, ITextOperationTarget.SHIFT_RIGHT) { //$NON-NLS-1$ @Override public void update() { setAction(ITextEditorActionConstants.SHIFT_RIGHT_TAB, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftLeft.", this, ITextOperationTarget.SHIFT_LEFT); //$NON-NLS-1$ action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_LEFT_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_LEFT);
/** * 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 (!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); } }); }
@Override public boolean isEnabled(boolean isWritable) { if (!isWritable) return false; /* * Note that this implementation still honors the result returned by canDoOperation. * I.e. if the viewer is set to read-only, this method still returns false. * It covers the case in which the viewer is also writable. * */ ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor!= null && fOperationCode != -1) fOperationTarget= editor.getAdapter(ITextOperationTarget.class); return (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); } }
setAction(ITextEditorActionConstants.SELECT_ALL, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftRight.", this, ITextOperationTarget.SHIFT_RIGHT); //$NON-NLS-1$ action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_RIGHT_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_RIGHT); setAction(ITextEditorActionConstants.SHIFT_RIGHT, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftRight.", this, ITextOperationTarget.SHIFT_RIGHT) { //$NON-NLS-1$ public void update() { updateForTab(); setAction(ITextEditorActionConstants.SHIFT_RIGHT_TAB, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftLeft.", this, ITextOperationTarget.SHIFT_LEFT); //$NON-NLS-1$ action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_LEFT_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_LEFT);
@Override public void update() { super.update(); if (!isEnabled()) return; if (!canModifyEditor()) { setEnabled(false); return; } ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor != null && fOperationCode != -1) fOperationTarget= editor.getAdapter(ITextOperationTarget.class); }
/** * 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 (!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)); }
@Override public boolean isEnabled(boolean isWritable) { if (!isWritable) return false; /* * Note that this implementation still honors the result returned by canDoOperation. * I.e. if the viewer is set to read-only, this method still returns false. * It covers the case in which the viewer is also writable. * */ ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor!= null && fOperationCode != -1) fOperationTarget= editor.getAdapter(ITextOperationTarget.class); return (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); } }
/** * 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 ShiftAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { super(bundle, prefix, editor); fOperationCode= operationCode; update(); }
setAction(ITextEditorActionConstants.SELECT_ALL, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftRight.", this, ITextOperationTarget.SHIFT_RIGHT); //$NON-NLS-1$ action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_RIGHT_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_RIGHT); setAction(ITextEditorActionConstants.SHIFT_RIGHT, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftRight.", this, ITextOperationTarget.SHIFT_RIGHT) { //$NON-NLS-1$ @Override public void update() { setAction(ITextEditorActionConstants.SHIFT_RIGHT_TAB, action); action= new ShiftAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShiftLeft.", this, ITextOperationTarget.SHIFT_LEFT); //$NON-NLS-1$ action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_LEFT_ACTION); action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_LEFT);
@Override public void update() { super.update(); if (!isEnabled()) return; if (!canModifyEditor()) { setEnabled(false); return; } ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor != null && fOperationCode != -1) fOperationTarget= editor.getAdapter(ITextOperationTarget.class); }
/** * 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 ShiftAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { super(bundle, prefix, editor); fOperationCode= operationCode; update(); }
/** * Enablement when tab key is pressed - the current selection has to be cover multiple lines. * * @since 3.0 */ protected void updateForTab() { super.update(); if (isEnabled()) { if (!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); } }
/** * Enablement when tab key is pressed - the current selection has to be cover multiple lines. * * @since 3.0 */ protected void updateForTab() { super.update(); if (isEnabled()) { if (!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); } }
/** * Enablement when tab key is pressed - the current selection has to be cover multiple lines. * * @since 3.0 */ protected void updateForTab() { super.update(); if (isEnabled()) { if (!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); } }