Java Code Examples for org.eclipse.jface.text.link.LinkedModeUI#enter()
The following examples show how to use
org.eclipse.jface.text.link.LinkedModeUI#enter() .
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: ConfigurableCompletionProposal.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will * exit the mode when <code>closingCharacter</code> is typed and an exit position at * <code>getCursorPosition() + 1</code>. * * @param document the document */ protected void setUpLinkedMode(IDocument document) { try { LinkedPositionGroup group= new LinkedPositionGroup(); group.addPosition(new LinkedPosition(document, getSelectionStart(), getSelectionLength(), LinkedPositionGroup.NO_STOP)); LinkedModeModel model= new LinkedModeModel(); model.addGroup(group); model.forceInstall(); LinkedModeUI ui= new LinkedModeUI(model, viewer); // ui.setSimpleMode(true); ui.setExitPolicy(new ExitPolicy(exitChars)); ui.setExitPosition(viewer, getCursorPosition() + getReplacementOffset(), 0, Integer.MAX_VALUE); ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER); ui.enter(); } catch (BadLocationException e) { log.info(e.getMessage(), e); } }
Example 2
Source File: AbstractJavaCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will * exit the mode when <code>closingCharacter</code> is typed and an exit position at * <code>getCursorPosition() + 1</code>. * * @param document the document * @param closingCharacter the exit character */ protected void setUpLinkedMode(IDocument document, char closingCharacter) { if (getTextViewer() != null && autocloseBrackets()) { int offset= getReplacementOffset() + getCursorPosition(); int exit= getReplacementOffset() + getReplacementString().length(); try { LinkedPositionGroup group= new LinkedPositionGroup(); group.addPosition(new LinkedPosition(document, offset, 0, LinkedPositionGroup.NO_STOP)); LinkedModeModel model= new LinkedModeModel(); model.addGroup(group); model.forceInstall(); LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer()); ui.setSimpleMode(true); ui.setExitPolicy(new ExitPolicy(closingCharacter, document)); ui.setExitPosition(getTextViewer(), exit, 0, Integer.MAX_VALUE); ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER); ui.enter(); } catch (BadLocationException x) { JavaPlugin.log(x); } } }
Example 3
Source File: SelectNextOccurrenceHandler.java From eclipse-multicursor with Eclipse Public License 1.0 | 6 votes |
private void startLinkedEdit(List<IRegion> selections, ITextViewer viewer, Point originalSelection) throws BadLocationException { final LinkedPositionGroup linkedPositionGroup = new LinkedPositionGroup(); for (IRegion selection : selections) { linkedPositionGroup.addPosition(new LinkedPosition(viewer.getDocument(), selection.getOffset(), selection .getLength())); } LinkedModeModel model = new LinkedModeModel(); model.addGroup(linkedPositionGroup); model.forceInstall(); //FIXME can add a listener here to listen for the end of linked mode //model.addLinkingListener(null); LinkedModeUI ui = new EditorLinkedModeUI(model, viewer); ui.setExitPolicy(new DeleteBlockingExitPolicy(viewer.getDocument())); ui.enter(); // by default the text being edited is selected so restore original selection viewer.setSelectedRange(originalSelection.x, originalSelection.y); }
Example 4
Source File: LangCompletionProposal.java From goclipse with Eclipse Public License 1.0 | 6 votes |
protected void applyLinkedMode(ITextViewer viewer) throws BadLocationException { LinkedModeModel model = getLinkedModeModel(viewer); if(model == null) { return; } model.forceInstall(); LinkedModeUI ui = new EditorLinkedModeUI(model, viewer); ui.setExitPolicy(new CompletionProposalExitPolicy()); ui.setExitPosition(viewer, endPositionAfterApply, 0, Integer.MAX_VALUE); if(firstLinkedModeGroupPosition != -1) { positionAfterApply = null; } ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT); ui.setDoContextInfo(true); ui.enableColoredLabels(true); ui.enter(); }
Example 5
Source File: RenameLinkedMode.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public boolean start(IRenameElementContext renameElementContext, Provider<LinkedPositionGroup> provider, IProgressMonitor monitor) { if (renameElementContext == null) throw new IllegalArgumentException("RenameElementContext is null"); this.linkedPositionGroup = provider.get(); if (linkedPositionGroup == null || linkedPositionGroup.isEmpty()) return false; this.editor = (XtextEditor) renameElementContext.getTriggeringEditor(); this.focusEditingSupport = new FocusEditingSupport(); ISourceViewer viewer = editor.getInternalSourceViewer(); IDocument document = viewer.getDocument(); originalSelection = viewer.getSelectedRange(); currentPosition = linkedPositionGroup.getPositions()[0]; originalName = getCurrentName(); try { linkedModeModel = new LinkedModeModel(); linkedModeModel.addGroup(linkedPositionGroup); linkedModeModel.forceInstall(); linkedModeModel.addLinkingListener(new EditorSynchronizer()); LinkedModeUI ui = new EditorLinkedModeUI(linkedModeModel, viewer); ui.setExitPolicy(new ExitPolicy(document)); if (currentPosition.includes(originalSelection.x)) ui.setExitPosition(viewer, originalSelection.x, 0, Integer.MAX_VALUE); ui.enter(); if (currentPosition.includes(originalSelection.x) && currentPosition.includes(originalSelection.x + originalSelection.y)) viewer.setSelectedRange(originalSelection.x, originalSelection.y); if (viewer instanceof IEditingSupportRegistry) { IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer; registry.register(focusEditingSupport); } openPopup(); return true; } catch (BadLocationException e) { throw new WrappedException(e); } }
Example 6
Source File: TexCompletionProposal.java From texlipse with Eclipse Public License 1.0 | 5 votes |
public void apply(IDocument document) { try { if (fentry.arguments > 0) { StringBuffer displayKey = new StringBuffer(fentry.key); for (int j=0; j < fentry.arguments; j++) displayKey.append("{}"); document.replace(fReplacementOffset, fReplacementLength, displayKey.toString()); if (TexlipsePlugin.getDefault().getPreferenceStore() .getBoolean(TexlipseProperties.SMART_PARENS)){ LinkedModeModel model= new LinkedModeModel(); for (int j=0; j < fentry.arguments; j++){ int newOffset = fReplacementOffset + fentry.key.length() + j*2 + 1; LinkedPositionGroup group = new LinkedPositionGroup(); group.addPosition(new LinkedPosition(document, newOffset, 0, LinkedPositionGroup.NO_STOP)); model.addGroup(group); } model.forceInstall(); LinkedModeUI ui = new EditorLinkedModeUI(model, fviewer); ui.setSimpleMode(false); ui.setExitPolicy(new ExitPolicy('}', fviewer)); ui.setExitPosition(fviewer, fReplacementOffset + displayKey.length(), 0, Integer.MAX_VALUE); ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER); ui.enter(); } } else { document.replace(fReplacementOffset, fReplacementLength, fentry.key); } } catch (BadLocationException x) { } }
Example 7
Source File: XMLAttributeProposal.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Special code added to allow tabstop positions so we can easily tab past the quotes for Events/Attributes. */ @Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { super.apply(viewer, trigger, stateMask, offset); // See if there are any positions that should be linked. Last is always exit, first is cursor position if (_positions != null && _positions.length > 0) { IDocument document = viewer.getDocument(); boolean validPrefix = isValidPrefix(getPrefix(document, offset), getDisplayString()); int shift = (validPrefix) ? offset - this._replacementOffset : 0; try { LinkedModeModel.closeAllModels(document); // Exit out of any existing linked mode LinkedModeModel model = new LinkedModeModel(); int i = 0; for (int pos : _positions) { LinkedPositionGroup group = new LinkedPositionGroup(); group.addPosition(new LinkedPosition(document, (offset - shift) + pos, 0, i++)); model.addGroup(group); } model.forceInstall(); LinkedModeUI ui = new LinkedModeUI(model, viewer); ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS); ui.setExitPosition(viewer, (offset - shift) + _positions[_positions.length - 1], 0, Integer.MAX_VALUE); ui.enter(); } catch (BadLocationException e) { IdeLog.logError(XMLPlugin.getDefault(), e); } } }
Example 8
Source File: AttributeOrEventProposal.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Special code added to allow tabstop positions so we can easily tab past the quotes for Events/Attributes. */ @Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { super.apply(viewer, trigger, stateMask, offset); // See if there are any positions that should be linked. Last is always exit, first is cursor position if (_positions != null && _positions.length > 0) { IDocument document = viewer.getDocument(); boolean validPrefix = isValidPrefix(getPrefix(document, offset), getDisplayString()); int shift = (validPrefix) ? offset - this._replacementOffset : 0; try { LinkedModeModel.closeAllModels(document); // Exit out of any existing linked mode LinkedModeModel model = new LinkedModeModel(); int i = 0; for (int pos : _positions) { LinkedPositionGroup group = new LinkedPositionGroup(); group.addPosition(new LinkedPosition(document, (offset - shift) + pos, 0, i++)); model.addGroup(group); } model.forceInstall(); LinkedModeUI ui = new LinkedModeUI(model, viewer); ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS); ui.setExitPosition(viewer, (offset - shift) + _positions[_positions.length - 1], 0, Integer.MAX_VALUE); ui.enter(); } catch (BadLocationException e) { IdeLog.logError(HTMLPlugin.getDefault(), e); } } }
Example 9
Source File: RenameLinkedMode.java From typescript.java with MIT License | 4 votes |
public void start() { if (getActiveLinkedMode() != null) { // for safety; should already be handled in RenameJavaElementAction fgActiveLinkedMode.startFullDialog(); return; } ISourceViewer viewer = fEditor.getViewer(); IDocument document = viewer.getDocument(); ITypeScriptFile tsFile = fEditor.getTypeScriptFile(); tsFile.setDisableChanged(true); fOriginalSelection = viewer.getSelectedRange(); int offset = fOriginalSelection.x; try { fLinkedPositionGroup = new LinkedPositionGroup(); if (viewer instanceof ITextViewerExtension6) { IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager(); if (undoManager instanceof IUndoManagerExtension) { IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager; IUndoContext undoContext = undoManagerExtension.getUndoContext(); IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory(); fStartingUndoOperation = operationHistory.getUndoOperation(undoContext); } } // Find occurrences List<OccurrencesResponseItem> occurrences = tsFile.occurrences(offset).get(1000, TimeUnit.MILLISECONDS); // Create Eclipse linked position from the occurrences list. int start, length; for (int i = 0; i < occurrences.size(); i++) { OccurrencesResponseItem item = occurrences.get(i); start = tsFile.getPosition(item.getStart()); length = tsFile.getPosition(item.getEnd()) - start; LinkedPosition linkedPosition = new LinkedPosition(document, start, length, i); if (i == 0) { fOriginalName = document.get(start, length); fNamePosition = linkedPosition; } fLinkedPositionGroup.addPosition(linkedPosition); } fLinkedModeModel = new LinkedModeModel(); fLinkedModeModel.addGroup(fLinkedPositionGroup); fLinkedModeModel.forceInstall(); fLinkedModeModel.addLinkingListener(new EditorHighlightingSynchronizer(fEditor)); fLinkedModeModel.addLinkingListener(new EditorSynchronizer()); LinkedModeUI ui = new EditorLinkedModeUI(fLinkedModeModel, viewer); ui.setExitPosition(viewer, offset, 0, Integer.MAX_VALUE); ui.setExitPolicy(new ExitPolicy(document)); ui.enter(); viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y); // by // default, // full // word // is // selected; // restore // original // selection if (viewer instanceof IEditingSupportRegistry) { IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer; registry.register(fFocusEditingSupport); } openSecondaryPopup(); // startAnimation(); fgActiveLinkedMode = this; } catch (Exception e) { JSDTTypeScriptUIPlugin.log(e); } }
Example 10
Source File: WidgetProposalComputer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
/** * Enters the linked mode for editing the namespace prefix we generated. */ private void enterLinkedModeForPrefix(IDocument document, ITextViewer viewer, IDOMElement rootElement, String prefix) throws BadLocationException { int linkedPosSequence = 0; // The prefix is the first thing entered at the start position LinkedPosition pos1 = new LinkedPosition(document, startPosition, prefix.length(), linkedPosSequence++); // The prefix is also at the cursor position + 2 (those two following // characters are '<' and '/') LinkedPosition pos2 = new LinkedPosition(document, cursorPosition + 2, prefix.length(), linkedPosSequence++); IDOMElement rootDomElement = (IDOMElement) rootElement; // TODO: use UiBinderConstants.XMLNS_PREFIX, but that has been modified in // a parallel CL. Will switch to using that constant in the latter of this // and that other CL. final String xmlnsPrefix = "xmlns:"; String fullPrefixName = xmlnsPrefix + prefix; IDOMAttr domAttribute = (IDOMAttr) rootDomElement.getAttributeNode(fullPrefixName); LinkedPosition pos3 = new LinkedPosition(document, domAttribute.getStartOffset() + xmlnsPrefix.length(), prefix.length(), linkedPosSequence++); LinkedPositionGroup group = new LinkedPositionGroup(); group.addPosition(pos1); group.addPosition(pos2); group.addPosition(pos3); // Boilerplate stuff below LinkedModeModel model = new LinkedModeModel(); model.addGroup(group); model.forceInstall(); LinkedModeUI ui = new LinkedModeUI(model, viewer); ui.enter(); wasLinkedModeEntered = true; }
Example 11
Source File: RenameLinkedMode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void start() { if (getActiveLinkedMode() != null) { // for safety; should already be handled in RenameJavaElementAction fgActiveLinkedMode.startFullDialog(); return; } ISourceViewer viewer= fEditor.getViewer(); IDocument document= viewer.getDocument(); fOriginalSelection= viewer.getSelectedRange(); int offset= fOriginalSelection.x; try { CompilationUnit root= SharedASTProvider.getAST(getCompilationUnit(), SharedASTProvider.WAIT_YES, null); fLinkedPositionGroup= new LinkedPositionGroup(); ASTNode selectedNode= NodeFinder.perform(root, fOriginalSelection.x, fOriginalSelection.y); if (! (selectedNode instanceof SimpleName)) { return; // TODO: show dialog } SimpleName nameNode= (SimpleName) selectedNode; if (viewer instanceof ITextViewerExtension6) { IUndoManager undoManager= ((ITextViewerExtension6)viewer).getUndoManager(); if (undoManager instanceof IUndoManagerExtension) { IUndoManagerExtension undoManagerExtension= (IUndoManagerExtension)undoManager; IUndoContext undoContext= undoManagerExtension.getUndoContext(); IOperationHistory operationHistory= OperationHistoryFactory.getOperationHistory(); fStartingUndoOperation= operationHistory.getUndoOperation(undoContext); } } fOriginalName= nameNode.getIdentifier(); final int pos= nameNode.getStartPosition(); ASTNode[] sameNodes= LinkedNodeFinder.findByNode(root, nameNode); //TODO: copied from LinkedNamesAssistProposal#apply(..): // sort for iteration order, starting with the node @ offset Arrays.sort(sameNodes, new Comparator<ASTNode>() { public int compare(ASTNode o1, ASTNode o2) { return rank(o1) - rank(o2); } /** * Returns the absolute rank of an <code>ASTNode</code>. Nodes * preceding <code>pos</code> are ranked last. * * @param node the node to compute the rank for * @return the rank of the node with respect to the invocation offset */ private int rank(ASTNode node) { int relativeRank= node.getStartPosition() + node.getLength() - pos; if (relativeRank < 0) return Integer.MAX_VALUE + relativeRank; else return relativeRank; } }); for (int i= 0; i < sameNodes.length; i++) { ASTNode elem= sameNodes[i]; LinkedPosition linkedPosition= new LinkedPosition(document, elem.getStartPosition(), elem.getLength(), i); if (i == 0) fNamePosition= linkedPosition; fLinkedPositionGroup.addPosition(linkedPosition); } fLinkedModeModel= new LinkedModeModel(); fLinkedModeModel.addGroup(fLinkedPositionGroup); fLinkedModeModel.forceInstall(); fLinkedModeModel.addLinkingListener(new EditorHighlightingSynchronizer(fEditor)); fLinkedModeModel.addLinkingListener(new EditorSynchronizer()); LinkedModeUI ui= new EditorLinkedModeUI(fLinkedModeModel, viewer); ui.setExitPosition(viewer, offset, 0, Integer.MAX_VALUE); ui.setExitPolicy(new ExitPolicy(document)); ui.enter(); viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y); // by default, full word is selected; restore original selection if (viewer instanceof IEditingSupportRegistry) { IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer; registry.register(fFocusEditingSupport); } openSecondaryPopup(); // startAnimation(); fgActiveLinkedMode= this; } catch (BadLocationException e) { JavaPlugin.log(e); } }
Example 12
Source File: AssistAssignCompletionProposal.java From Pydev with Eclipse Public License 1.0 | 4 votes |
@Override public void apply(IDocument document) { try { //default apply int lineOfOffset = document.getLineOfOffset(fReplacementOffset); document.replace(fReplacementOffset, fReplacementLength, fReplacementString); if (SharedCorePlugin.inTestMode()) { return; } int lineOffset = document.getLineOffset(lineOfOffset); int lineLength = document.getLineLength(lineOfOffset); String lineDelimiter = document.getLineDelimiter(lineOfOffset); int lineDelimiterLen = lineDelimiter != null ? lineDelimiter.length() : 0; ISourceViewer viewer = sourceViewer; LinkedModeModel model = new LinkedModeModel(); LinkedPositionGroup group = new LinkedPositionGroup(); //the len-3 is because of the end of the string: " = " because the replacement string is //something like "xxx = " ProposalPosition proposalPosition = new ProposalPosition(document, fReplacementOffset, fReplacementString.length() - 3, 0, new ICompletionProposal[0]); group.addPosition(proposalPosition); model.addGroup(group); model.forceInstall(); final LinkedModeUI ui = new EditorLinkedModeUI(model, viewer); ui.setExitPosition(viewer, lineOffset + lineLength - lineDelimiterLen, 0, Integer.MAX_VALUE); Runnable r = new Runnable() { @Override public void run() { ui.enter(); } }; RunInUiThread.async(r); } catch (Throwable x) { // ignore Log.log(x); } }
Example 13
Source File: SelectAllOccurrencesHandler.java From eclipse-multicursor with Eclipse Public License 1.0 | 4 votes |
/** * Mostly based on code from {@link org.eclipse.jdt.internal.ui.text.correction.proposals.LinkedNamesAssistProposal} */ private void startEditing(ISourceViewer viewer) throws ExecutionException { Point selOffsetAndLen = viewer.getSelectedRange(); int selStart = CoordinatesUtil.fromOffsetAndLengthToStartAndEnd(selOffsetAndLen).x; IDocument document = viewer.getDocument(); try { String selectedText; if (selOffsetAndLen.y == 0) { // no characters selected String documentText = document.get(); Point wordOffsetAndLen = TextUtil.findWordSurrounding(documentText, selStart); if (wordOffsetAndLen != null) { selectedText = document.get(wordOffsetAndLen.x, wordOffsetAndLen.y); } else { IRegion selectedLine = document.getLineInformationOfOffset(selStart); selectedText = document.get(selectedLine.getOffset(), selectedLine.getLength()); } } else { selectedText = document.get(selOffsetAndLen.x, selOffsetAndLen.y); } LinkedPositionGroup linkedPositionGroup = new LinkedPositionGroup(); FindReplaceDocumentAdapter findReplaceAdaptor = new FindReplaceDocumentAdapter(document); IRegion matchingRegion = findReplaceAdaptor.find(0, selectedText, true, true, false, false); while (matchingRegion != null) { linkedPositionGroup.addPosition(new LinkedPosition(document, matchingRegion.getOffset(), matchingRegion .getLength())); matchingRegion = findReplaceAdaptor.find(matchingRegion.getOffset() + matchingRegion.getLength(), selectedText, true, true, false, false); } LinkedModeModel model = new LinkedModeModel(); model.addGroup(linkedPositionGroup); model.forceInstall(); LinkedModeUI ui = new EditorLinkedModeUI(model, viewer); ui.setExitPolicy(new DeleteBlockingExitPolicy(document)); ui.enter(); // by default the text being edited is selected so restore original selection viewer.setSelectedRange(selOffsetAndLen.x, selOffsetAndLen.y); } catch (BadLocationException e) { throw new ExecutionException("Editing failed", e); } }