Java Code Examples for org.eclipse.jface.text.ITextOperationTarget#canDoOperation()

The following examples show how to use org.eclipse.jface.text.ITextOperationTarget#canDoOperation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XtextMarkerRulerAction.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	try {
		// Move offset to the line of the annotation, if necessary
		IDocument document = getDocument();
		int annotationLine = ruler.getLineOfLastMouseButtonActivity();
		int annotationLineOffet = document.getLineOffset(annotationLine);
		Point currentSelection = textEditor.getInternalSourceViewer().getSelectedRange();
		int currentLine = document.getLineOfOffset(currentSelection.x);
		if (currentLine != annotationLine)
			textEditor.getInternalSourceViewer().setSelectedRange(annotationLineOffet, 0);
	
		// show QuickFix dialog
		ITextOperationTarget operation = textEditor.getAdapter(ITextOperationTarget.class);
		final int opCode = ISourceViewer.QUICK_ASSIST;
		if (operation != null && operation.canDoOperation(opCode))
			operation.doOperation(opCode);
	} catch (BadLocationException e) {
		// Ignore -> do nothing
	}
}
 
Example 2
Source File: JavaSelectAnnotationRulerAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void runWithEvent(Event event) {
	if (fAnnotation instanceof OverrideIndicatorManager.OverrideIndicator) {
		((OverrideIndicatorManager.OverrideIndicator)fAnnotation).open();
		return;
	}

	if (fHasCorrection) {
		ITextOperationTarget operation= (ITextOperationTarget) fTextEditor.getAdapter(ITextOperationTarget.class);
		final int opCode= ISourceViewer.QUICK_ASSIST;
		if (operation != null && operation.canDoOperation(opCode)) {
			fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength());
			operation.doOperation(opCode);
		}
		return;
	}

	super.run();
}
 
Example 3
Source File: ToggleCommentHandler.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ITextSelection selection = WorkbenchUtils.getActiveTextSelection();
    IDocument      document  = WorkbenchUtils.getActiveDocument();
    IEditorInput   input     = WorkbenchUtils.getActiveInput();
    IEditorPart    editor    = WorkbenchUtils.getActiveEditor(false);

    boolean isTextOperationAllowed = (selection != null) && (document != null) 
                                  && (input != null)     && (editor != null) 
                                  && (editor instanceof SourceCodeTextEditor);

    if (isTextOperationAllowed) {
        final ITextOperationTarget operationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
        String commentPrefix = ((SourceCodeTextEditor)editor).getEOLCommentPrefix();
        isTextOperationAllowed = (operationTarget != null)
                              && (operationTarget instanceof TextViewer)
                              && (validateEditorInputState((ITextEditor)editor))
                              && (commentPrefix != null);
        
        if ((isTextOperationAllowed)) {
            final int operation = isSelectionCommented(document, selection, commentPrefix) 
                                ? ITextOperationTarget.STRIP_PREFIX 
                                : ITextOperationTarget.PREFIX;

            if (operationTarget.canDoOperation(operation)) {
                BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
                    public void run() {
                        // Really processed in TextViewer.doOperation:
                        operationTarget.doOperation(operation);
                    }
                });
            }
        }
    }

    return null;
}
 
Example 4
Source File: JavaSelectMarkerRulerAction2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void annotationDefaultSelected(VerticalRulerEvent event) {
	Annotation annotation= event.getSelectedAnnotation();
	IAnnotationModel model= getAnnotationModel();

	if (isOverrideIndicator(annotation)) {
		((OverrideIndicatorManager.OverrideIndicator)annotation).open();
		return;
	}

	if (isBreakpoint(annotation))
		triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK, event.getEvent());

	Position position= model.getPosition(annotation);
	if (position == null)
		return;

	if (isQuickFixTarget(annotation)) {
		ITextOperationTarget operation= (ITextOperationTarget) getTextEditor().getAdapter(ITextOperationTarget.class);
		final int opCode= ISourceViewer.QUICK_ASSIST;
		if (operation != null && operation.canDoOperation(opCode)) {
			getTextEditor().selectAndReveal(position.getOffset(), position.getLength());
			operation.doOperation(opCode);
			return;
		}
	}

	// default:
	super.annotationDefaultSelected(event);
}
 
Example 5
Source File: SpecificContentAssistAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean computeEnablement(ITextEditor editor) {
	if (editor == null)
		return false;
	
	ITextOperationTarget target= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
	if (target == null || ! target.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS))
		return false;
	
	IJavaProject javaProject = EditorUtility.getJavaProject(editor.getEditorInput());
	if (! fCategory.matches(javaProject))
		return false;
	
	ISelection selection= editor.getSelectionProvider().getSelection();
	return isValidSelection(selection);
}
 
Example 6
Source File: MacroModeStateHandler.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void disable(ITextOperationTarget textOperationTarget, ITextOperationTargetExtension targetExtension,
        int operation, String preference) {
    if (textOperationTarget.canDoOperation(operation)) {
        fMemento.put(preference, true);
        targetExtension.enableOperation(operation, false);
    }
}
 
Example 7
Source File: ToggleCommentAction.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean isTargetOperationEnabled() {
	ITextEditor editor = getTextEditor();
	if(editor != null) {
		fOperationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
	}
	
	return fOperationTarget != null && 
		fOperationTarget.canDoOperation(ITextOperationTarget.PREFIX) && 
		fOperationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX);
}