org.eclipse.jface.text.IRewriteTarget Java Examples

The following examples show how to use org.eclipse.jface.text.IRewriteTarget. 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: ImportsAwareClipboardAction.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void doPasteXbaseCode(XbaseClipboardData xbaseClipboardData, boolean withImports) {
	IRewriteTarget target = Adapters.adapt(getTextEditor(), IRewriteTarget.class);
	if (target != null) {
		target.beginCompoundChange();
	}
	try {
		textOperationTarget.doOperation(operationCode);
		if (withImports) {
			importsUtil.addImports(xbaseClipboardData.getImports(), xbaseClipboardData.getStaticImports(),
					xbaseClipboardData.getExtensionImports(), getXtextDocument());
		}
	} catch (Exception e) {
		XbaseActivator.getInstance().getLog().log(new Status(IStatus.ERROR,
				XbaseActivator.getInstance().getBundle().getSymbolicName(), "Unexpected internal error: ", e));
	} finally {
		if (target != null) {
			target.endCompoundChange();
		}
	}
}
 
Example #2
Source File: ImportsAwareClipboardAction.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void doPasteJavaCode(String textFromClipboard, JavaImportData javaImportsContent, boolean withImports) {
	IRewriteTarget target = Adapters.adapt(getTextEditor(), IRewriteTarget.class);
	if (target != null) {
		target.beginCompoundChange();
	}
	try {
		textOperationTarget.doOperation(operationCode);
		if (withImports) {
			importsUtil.addImports(javaImportsContent.getImports(), javaImportsContent.getStaticImports(),
					new String[] {}, getXtextDocument());
		}
	} catch (Exception e) {
		XbaseActivator.getInstance().getLog().log(new Status(IStatus.ERROR,
				XbaseActivator.getInstance().getBundle().getSymbolicName(), "Unexpected internal error: ", e));
	} finally {
		if (target != null) {
			target.endCompoundChange();
		}
	}
}
 
Example #3
Source File: SARLSourceViewer.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void doOperation(int operation) {
	if (operation == ITextOperationTarget.PASTE && isAutoFormattingEnable()) {
		final IRewriteTarget target = getRewriteTarget();
		target.beginCompoundChange();
		final IDocumentAutoFormatter formatter = getDocumentAutoFormatter();
		formatter.beginAutoFormat();
		try {
			super.doOperation(operation);
		} finally {
			formatter.endAutoFormat();
			target.endCompoundChange();
		}
	} else {
		super.doOperation(operation);
	}
}
 
Example #4
Source File: RectangleExecHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean doExecuteResult(ITextEditor editor, Object minibufferResult) {
	// use widget to avoid unpleasant scrolling side effects of IRewriteTarget
	Control widget = getTextWidget(editor);
	// wrap in compound change and no redraw
	IRewriteTarget rt = (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);
	try {
		if (rt != null) {
			rt.beginCompoundChange();
		}
		widget.setRedraw(false);
		int offset = rs.updateRectangle(editor, document, selection, (String)minibufferResult, isReplace(),false);
		if (offset > 0) {
			selectAndReveal(editor, offset, offset);
		}
	} finally  {
		if (rt != null) {
			rt.endCompoundChange();
		}
		widget.setRedraw(true);
	}
	return true;
}
 
Example #5
Source File: TextViewerMoveLinesAction.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Ends the compound change.
 */
private void beginCompoundEdit() {
	ITextViewer viewer= getTextViewer();
	if (fEditInProgress || viewer == null || !(viewer instanceof ITextViewerExtension))
		return;

	fEditInProgress= true;

	fStrategy.arm(viewer);

	IRewriteTarget target= ((ITextViewerExtension) viewer).getRewriteTarget();
	if (target != null) {
		target.beginCompoundChange();
	}
}
 
Example #6
Source File: TextViewerMoveLinesAction.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Ends the compound change.
 */
private void endCompoundEdit() {
	ITextViewer viewer= getTextViewer();
	if (!fEditInProgress || viewer == null || !(viewer instanceof ITextViewerExtension))
		return;

	IRewriteTarget target= ((ITextViewerExtension) viewer).getRewriteTarget();
	if (target != null) {
		target.endCompoundChange();
	}

	fEditInProgress= false;
}
 
Example #7
Source File: XbaseEditorOpenClassFileTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public String getEditorContents(final IJavaElement javaElement) {
  try {
    final IEditorPart editor = JavaUI.openInEditor(javaElement);
    final Object adapter = editor.<IRewriteTarget>getAdapter(IRewriteTarget.class);
    final String text = ((IRewriteTarget) adapter).getDocument().get();
    this.helper.closeEditor(editor, false);
    return text;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #8
Source File: JavaMoveLinesAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Ends the compound change.
 */
public void beginCompoundEdit() {
	if (fEditInProgress || fEditor == null)
		return;

	fEditInProgress= true;

	fExitStrategy.arm(fEditor.getViewer());

	IRewriteTarget target= (IRewriteTarget)fEditor.getAdapter(IRewriteTarget.class);
	if (target != null) {
		target.beginCompoundChange();
	}
}
 
Example #9
Source File: JavaMoveLinesAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Ends the compound change.
 */
public void endCompoundEdit() {
	if (!fEditInProgress || fEditor == null)
		return;

	fExitStrategy.disarm();

	IRewriteTarget target= (IRewriteTarget)fEditor.getAdapter(IRewriteTarget.class);
	if (target != null) {
		target.endCompoundChange();
	}

	fResult= null;
	fEditInProgress= false;
}
 
Example #10
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void doPasteWithImportsOperation() {
	ITextEditor editor= getTextEditor();
	IJavaElement inputElement= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());

	Clipboard clipboard= new Clipboard(getDisplay());
	try {
		ClipboardData importsData= (ClipboardData)clipboard.getContents(fgTransferInstance);
		if (importsData != null && inputElement instanceof ICompilationUnit && !importsData.isFromSame(inputElement)) {
			// combine operation and adding of imports
			IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class);
			if (target != null) {
				target.beginCompoundChange();
			}
			try {
				fOperationTarget.doOperation(fOperationCode);
				addImports((ICompilationUnit)inputElement, importsData);
			} catch (CoreException e) {
				JavaPlugin.log(e);
			} finally {
				if (target != null) {
					target.endCompoundChange();
				}
			}
		} else {
			fOperationTarget.doOperation(fOperationCode);
		}
	} finally {
		clipboard.dispose();
	}
}
 
Example #11
Source File: TemplateProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void endCompoundChange(ITextViewer viewer) {
	if (viewer instanceof ITextViewerExtension) {
		ITextViewerExtension extension= (ITextViewerExtension) viewer;
		IRewriteTarget target= extension.getRewriteTarget();
		target.endCompoundChange();
	}
}
 
Example #12
Source File: TemplateProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void beginCompoundChange(ITextViewer viewer) {
	if (viewer instanceof ITextViewerExtension) {
		ITextViewerExtension extension= (ITextViewerExtension) viewer;
		IRewriteTarget target= extension.getRewriteTarget();
		target.beginCompoundChange();
	}
}
 
Example #13
Source File: SurroundWithTemplateProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void setRedraw(ITextViewer viewer, boolean redraw) {
if (viewer instanceof ITextViewerExtension) {
	ITextViewerExtension extension= (ITextViewerExtension) viewer;
	IRewriteTarget target= extension.getRewriteTarget();
	target.setRedraw(redraw);
}
  }
 
Example #14
Source File: KbdMacroExecuteHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the undo Runnable wrappers
 * 
 * @param editor
 * @return begin and end undoProtect wrappers
 */
protected Runnable[] undoProtect(ITextEditor editor, final MacroCount keepCount) {
	Runnable[] result = new Runnable[2];
	// use widget to avoid unpleasant scrolling side effects of IRewriteTarget
	final Control widget = getTextWidget(editor);;
	final IRewriteTarget rt = (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);;
	result[0] = new Runnable() {
		public void run() {
			if (rt != null) {
				rt.beginCompoundChange();
			}
			setRedraw(widget,false);
		}
	};
	result[1] = new Runnable() {
		public void run() {
			setRedraw(widget, true);
			if (rt != null) {
				rt.endCompoundChange();
			}
			if (!isInterrupted() && keepCount != null) {
				// we've finished one more loop of the main macro
				keepCount.addCounter();
			}
		}
	};
	return result;
}
 
Example #15
Source File: RegisterRectangleHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
 */
public boolean doExecuteResult(ITextEditor editor, Object minibufferResult) {
	
	if (minibufferResult != null && ((String)minibufferResult).length() > 0) {
		String key = (String)minibufferResult;
		ITextSelection selection = getImpliedSelection(editor, getCurrentSelection(editor));
		IDocument document = getThisDocument(editor);
		// if called with ^U, then delete text as well
		boolean delete = isEditable() && getCallCount() > 1;
		String[] rect;
		// use widget to avoid unpleasant scrolling side effects of IRewriteTarget			
		Control widget = getTextWidget(editor);
		IRewriteTarget rt = (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);
		try {
			if (delete) {
				// wrap in compound change and no redraw
				widget.setRedraw(false);
				if (rt != null) {
					rt.beginCompoundChange();
				}
			}
			rect = new RectangleSupport(document,editor).copyRectangle(editor, document, selection, delete);
			if (rect != null && rect.length > 0) {
				TecoRegister.getInstance().put(key,rect);
				showResultMessage(editor, String.format(COPIED, key), false);
			}
		} catch (BadLocationException e) {
			showResultMessage(editor, BAD_INSERT_LOCATION, true);
		} finally  {
			if (rt != null) {
				rt.endCompoundChange();
			}
			widget.setRedraw(true);
		}
	} else {
		showResultMessage(editor, NO_REGISTER, true);
	}
	return true;
}
 
Example #16
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public IRewriteTarget getRewriteTarget() {
    return viewer.getRewriteTarget();
}