@Override protected void configureSourceViewer(ISourceViewer sourceViewer) { sourceViewer.setEditable(false); sourceViewer.configure(sourceViewerConfiguration); if (sourceViewer instanceof ITextViewerExtension6) { ITextViewerExtension6 textViewerExtension6 = (ITextViewerExtension6) sourceViewer; textViewerExtension6.setHyperlinkDetectors(null, sourceViewerConfiguration.getHyperlinkStateMask(sourceViewer)); } if (sourceViewer instanceof ITextViewerExtension2) { ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer; String[] configuredContentTypes = sourceViewerConfiguration.getConfiguredContentTypes(sourceViewer); for (String contentType : configuredContentTypes) { textViewerExtension2.removeTextHovers(contentType); } } }
public void undoDocumentChanges() { final ISourceViewer viewer = editor.getInternalSourceViewer(); try { editor.getSite().getWorkbenchWindow().run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { 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(); while (undoManager.undoable()) { if (startingUndoOperation != null && startingUndoOperation.equals(operationHistory.getUndoOperation(undoContext))) return; undoManager.undo(); } } } } }); syncUtil.waitForReconciler(editor); } catch (Exception e) { LOG.error(e.getMessage(), e); } }
private IUndoContext getUndoContext() { if (getSourceViewer() instanceof ITextViewerExtension6) { IUndoManager undoManager = ((ITextViewerExtension6) getSourceViewer()).getUndoManager(); if (undoManager instanceof IUndoManagerExtension) return ((IUndoManagerExtension) undoManager).getUndoContext(); } return null; }
@Override public void perform(AbstractDocumentCommand command) throws CoreException { disableSelResponse = true; try { command.execute(((ITextViewerExtension6) getViewer()).getUndoManager(), getViewer().getDocument()); } finally { disableSelResponse = false; } selectionChanged(); }
public void startRecording(XtextEditor editor) { this.editor = editor; ISourceViewer viewer = editor.getInternalSourceViewer(); 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(); startingUndoOperation = operationHistory.getUndoOperation(undoContext); } } }
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); } }