org.eclipse.jface.text.ITextOperationTarget Java Examples
The following examples show how to use
org.eclipse.jface.text.ITextOperationTarget.
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: TestSnippetContentAssistProcessor.java From corrosion with Eclipse Public License 2.0 | 6 votes |
private void validateCompletionProposals(String text, String[] expectedProposalTexts) throws IOException, CoreException { IProject project = getProject(BASIC_PROJECT_NAME); IFile file = project.getFolder("src").getFile("main.rs"); IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); ((ITextEditor) editor).getDocumentProvider().getDocument(editor.getEditorInput()).set(text); ICompletionProposal[] proposals = (new SnippetContentAssistProcessor()).computeCompletionProposals( (ITextViewer) editor.getAdapter(ITextOperationTarget.class), text.length() - 1); if (expectedProposalTexts == null) { assertTrue(proposals == null || proposals.length == 0); return; } assertNotNull(proposals); for (int i = 0; i < proposals.length; i++) { assertEquals(((LSCompletionProposal) proposals[i]).getItem().getTextEdit().getNewText(), expectedProposalTexts[i]); } }
Example #2
Source File: ClipboardOperationAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates the action. * @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 */ public ClipboardOperationAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { super(bundle, prefix, editor); fOperationCode= operationCode; if (operationCode == ITextOperationTarget.CUT) { setHelpContextId(IAbstractTextEditorHelpContextIds.CUT_ACTION); setActionDefinitionId(IWorkbenchCommandConstants.EDIT_CUT); } else if (operationCode == ITextOperationTarget.COPY) { setHelpContextId(IAbstractTextEditorHelpContextIds.COPY_ACTION); setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY); } else if (operationCode == ITextOperationTarget.PASTE) { setHelpContextId(IAbstractTextEditorHelpContextIds.PASTE_ACTION); setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE); } else { Assert.isTrue(false, "Invalid operation code"); //$NON-NLS-1$ } update(); }
Example #3
Source File: MacroModeStateHandler.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Resets the state of the editor to what it was before macro record or playback * started. */ public void leaveMacroMode() { if (fEditorPart != null) { ITextOperationTarget textOperationTarget = fEditorPart.getAdapter(ITextOperationTarget.class); if (textOperationTarget instanceof ITextOperationTargetExtension) { ITextOperationTargetExtension targetExtension = (ITextOperationTargetExtension) textOperationTarget; if (textOperationTarget instanceof ITextOperationTargetExtension) { restore(targetExtension, ISourceViewer.CONTENTASSIST_PROPOSALS, CONTENT_ASSIST_ENABLED); restore(targetExtension, ISourceViewer.QUICK_ASSIST, QUICK_ASSIST_ENABLED); } } if (fEditorPart instanceof ITextEditor) { ITextEditor textEditor = (ITextEditor) fEditorPart; restore(textEditor, ITextEditorActionConstants.CONTENT_ASSIST); restore(textEditor, ITextEditorActionConstants.QUICK_ASSIST); restore(textEditor, ITextEditorActionConstants.BLOCK_SELECTION_MODE); } } }
Example #4
Source File: JavaSelectAnnotationRulerAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@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 #5
Source File: CellEditorTextViewer.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ; */ private void copy() { super.doOperation(ITextOperationTarget.COPY); TextTransfer plainTextTransfer = TextTransfer.getInstance(); HSTextTransfer hsTextTransfer = HSTextTransfer.getInstance(); Clipboard clipboard = new Clipboard(getTextWidget().getDisplay()); String plainText = (String) clipboard.getContents(plainTextTransfer); if (plainText == null || plainText.length() == 0) { return; } plainText = plainText.replaceAll(System.getProperty("line.separator"), "\n"); plainText = plainText.replaceAll(TmxEditorConstanst.LINE_SEPARATOR_CHARACTER + "", ""); plainText = plainText.replaceAll(TmxEditorConstanst.TAB_CHARACTER + "", "\t"); plainText = plainText.replaceAll(TmxEditorConstanst.SPACE_CHARACTER + "", " "); plainText = plainText.replaceAll("\u200B", ""); clipboard.clearContents(); Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText }; Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer }; clipboard.setContents(data, types); clipboard.dispose(); }
Example #6
Source File: EditTemplateDialog.java From typescript.java with MIT License | 6 votes |
private void handleVerifyKeyPressed(VerifyEvent event) { if (!event.doit) return; if (event.stateMask != SWT.MOD1) return; switch (event.character) { case ' ': fPatternEditor.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); event.doit = false; break; // CTRL-Z case 'z' - 'a' + 1: fPatternEditor.doOperation(ITextOperationTarget.UNDO); event.doit = false; break; } }
Example #7
Source File: SARLSourceViewer.java From sarl with Apache License 2.0 | 6 votes |
@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 #8
Source File: ImportsAwareClipboardAction.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * Creates the action. * * @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. May not be <code>null</code>. * @param operationCode * the operation code */ public ImportsAwareClipboardAction(ResourceBundle bundle, String prefix, ITextEditor editor, final int operationCode) { super(bundle, prefix, editor); this.operationCode = operationCode; if (operationCode == ITextOperationTarget.CUT) { setHelpContextId(IAbstractTextEditorHelpContextIds.CUT_ACTION); setActionDefinitionId(IWorkbenchCommandConstants.EDIT_CUT); } else if (operationCode == ITextOperationTarget.COPY) { setHelpContextId(IAbstractTextEditorHelpContextIds.COPY_ACTION); setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY); } else if (operationCode == ITextOperationTarget.PASTE) { setHelpContextId(IAbstractTextEditorHelpContextIds.PASTE_ACTION); setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE); } else { Assert.isTrue(false, "Invalid operation code"); //$NON-NLS-1$ } update(); }
Example #9
Source File: SegmentViewer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ; */ private void copy() { super.doOperation(ITextOperationTarget.COPY); TextTransfer plainTextTransfer = TextTransfer.getInstance(); XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance(); Clipboard clipboard = new Clipboard(getTextWidget().getDisplay()); String plainText = (String) clipboard.getContents(plainTextTransfer); if (plainText == null || plainText.length() == 0) { return; } plainText = plainText.replaceAll(Utils.getLineSeparator(), "\n"); plainText = plainText.replaceAll(Constants.LINE_SEPARATOR_CHARACTER + "", ""); plainText = plainText.replaceAll(Constants.TAB_CHARACTER + "", "\t"); plainText = plainText.replaceAll(Constants.SPACE_CHARACTER + "", " "); plainText = plainText.replaceAll("\u200B", ""); clipboard.clearContents(); Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText }; Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer }; clipboard.setContents(data, types, DND.CLIPBOARD); clipboard.dispose(); }
Example #10
Source File: ToggleSLCommentAction.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * Implementation of the <code>IUpdate</code> prototype method discovers * the operation through the current editor's * <code>ITextOperationTarget</code> adapter, and sets the enabled state * accordingly. */ @Override public void update() { super.update(); if (!canModifyEditor()) { setEnabled(false); return; } ITextEditor editor= getTextEditor(); if (fOperationTarget == null && editor != null) fOperationTarget= Adapters.adapt(editor, ITextOperationTarget.class); boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(ITextOperationTarget.PREFIX) && fOperationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX)); setEnabled(isEnabled); }
Example #11
Source File: XtextMarkerRulerAction.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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 #12
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Update the state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.REDO)); return; } if (undoAction != null) { setEnabled(redoAction.isEnabled()); return; } setEnabled(false); }
Example #13
Source File: XLIFFEditorActionHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Update state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.CUT)); return; } if (cutAction != null) { setEnabled(cutAction.isEnabled()); return; } setEnabled(false); }
Example #14
Source File: XLIFFEditorActionHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Update the state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.UNDO)); return; } if (undoAction != null) { setEnabled(undoAction.isEnabled()); return; } setEnabled(false); }
Example #15
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { // 使用TextViewer提供的重做功能 viewer.doOperation(ITextOperationTarget.REDO); updateActionsEnableState(); return; } if (redoAction != null) { redoAction.runWithEvent(event); return; } }
Example #16
Source File: XLIFFEditorActionHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { // 使用TextViewer组件的撤销功能 viewer.doOperation(ITextOperationTarget.UNDO); updateActionsEnableState(); return; } if (undoAction != null) { undoAction.runWithEvent(event); return; } }
Example #17
Source File: XLIFFEditorActionHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { viewer.doOperation(ITextOperationTarget.SELECT_ALL); updateActionsEnableState(); return; } if (selectAllAction != null) { selectAllAction.runWithEvent(event); return; } }
Example #18
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Update the state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.UNDO)); return; } if (undoAction != null) { setEnabled(undoAction.isEnabled()); return; } setEnabled(false); }
Example #19
Source File: XLIFFEditorActionHandler.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { // 使用TextViewer提供的重做功能 viewer.doOperation(ITextOperationTarget.REDO); updateActionsEnableState(); return; } if (redoAction != null) { redoAction.runWithEvent(event); return; } }
Example #20
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { // 使用TextViewer组件的撤销功能 viewer.doOperation(ITextOperationTarget.UNDO); updateActionsEnableState(); return; } if (undoAction != null) { undoAction.runWithEvent(event); return; } }
Example #21
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Update state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.CUT)); return; } if (cutAction != null) { setEnabled(cutAction.isEnabled()); return; } setEnabled(false); }
Example #22
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { viewer.doOperation(ITextOperationTarget.CUT); updateActionsEnableState(); return; } if (cutAction != null) { cutAction.runWithEvent(event); return; } }
Example #23
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Update the state */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.PASTE)); return; } if (pasteAction != null) { setEnabled(pasteAction.isEnabled()); return; } setEnabled(false); }
Example #24
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { viewer.doOperation(ITextOperationTarget.PASTE); updateActionsEnableState(); return; } }
Example #25
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Update the state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.COPY)); return; } if (copyAction != null) { setEnabled(copyAction.isEnabled()); return; } setEnabled(false); }
Example #26
Source File: TmMatchEditorBodyMenu.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { viewer.doOperation(ITextOperationTarget.COPY); updateActionsEnableState(); return; } if (copyAction != null) { copyAction.runWithEvent(event); return; } }
Example #27
Source File: XLIFFEditorActionHandler.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Update the state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.SELECT_ALL)); return; } if (selectAllAction != null) { setEnabled(selectAllAction.isEnabled()); return; } setEnabled(false); }
Example #28
Source File: ToggleCommentAction.java From goclipse with Eclipse Public License 1.0 | 5 votes |
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); }
Example #29
Source File: XLIFFEditorActionHandler.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void runWithEvent(Event event) { if (viewer != null && !viewer.getTextWidget().isDisposed()) { StyledTextCellEditor editor = HsMultiActiveCellEditor.getFocusCellEditor(); boolean isSrc = false; if (editor != null && editor.getCellType().equals(NatTableConstant.SOURCE)) { isSrc = true; } StyledText styledText = viewer.getTextWidget(); String text = styledText.getText(); String selectionText = styledText.getSelectionText(); // 当选择源文时,要判断是否是删除所有源文 if (isSrc) { if (selectionText != null && text != null && text.equals(selectionText)) { MessageDialog.openInformation(viewer.getTextWidget().getShell(), Messages.getString("editor.XLIFFEditorActionHandler.msgTitle"), Messages.getString("editor.XLIFFEditorActionHandler.msg")); return; } } viewer.doOperation(ITextOperationTarget.DELETE); updateActionsEnableState(); return; } if (deleteAction != null) { deleteAction.runWithEvent(event); return; } }
Example #30
Source File: TmMatchEditorBodyMenu.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Update state. */ public void updateEnabledState() { if (viewer != null && !viewer.getTextWidget().isDisposed()) { setEnabled(viewer.canDoOperation(ITextOperationTarget.CUT)); return; } if (cutAction != null) { setEnabled(cutAction.isEnabled()); return; } setEnabled(false); }