org.eclipse.jface.text.IEditingSupportRegistry Java Examples

The following examples show how to use org.eclipse.jface.text.IEditingSupportRegistry. 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: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * PopUp gets closed and the focus goes back to the editor. Linked mode stays active and can be reenabled, i.e. by
 * putting the caret back into a linked editing position.
 */
public void linkedModeLeft() {
	if (linkedModeModel != null) {
		linkedModeModel.exit(ILinkedModeListener.NONE);
	}
	if (popup != null) {
		popup.close();
	}

	if (editor != null) {
		ISourceViewer viewer = editor.getInternalSourceViewer();
		if (viewer instanceof IEditingSupportRegistry) {
			IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer;
			registry.unregister(focusEditingSupport);
		}
	}
}
 
Example #2
Source File: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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 #3
Source File: CompletionProposalPopup.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Hides this popup.
 */
public void hide()
{
	bufferString = "";
	selectedProposal = null;
	fLastKeyPressed = '\0';
	unregister();

	if (fViewer instanceof IEditingSupportRegistry)
	{
		IEditingSupportRegistry registry = (IEditingSupportRegistry) fViewer;
		registry.unregister(fFocusHelper);
	}

	if (Helper.okToUse(fProposalShell))
	{
		fContentAssistant.removeContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR);
		// TISTUD-913: moved the 'fPopupCloser.uninstall();' to disposePopup()
		if (fAdditionalInfoController != null)
		{
			fAdditionalInfoController.disposeInformationControl();
		}

		if (Helper.okToUse(fProposalTable))
		{
			fProposalTable.removeAll();
			fProposalTable.update();
		}
                       // TISTUD-1550: Call to dispose, instead of fProposalShell.setVisible(false);
		fProposalShell.setVisible(false);
	}
	}
 
Example #4
Source File: RenameLinkedMode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void linkedModeLeft() {
	fgActiveLinkedMode= null;
	if (fInfoPopup != null) {
		fInfoPopup.close();
	}

	ISourceViewer viewer= fEditor.getViewer();
	if (viewer instanceof IEditingSupportRegistry) {
		IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer;
		registry.unregister(fFocusEditingSupport);
	}
}
 
Example #5
Source File: OrganizeImportsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void registerHelper(IEditingSupport helper, JavaEditor editor) {
	ISourceViewer viewer= editor.getViewer();
	if (viewer instanceof IEditingSupportRegistry) {
		IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer;
		registry.register(helper);
	}
}
 
Example #6
Source File: OrganizeImportsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void deregisterHelper(IEditingSupport helper, JavaEditor editor) {
	ISourceViewer viewer= editor.getViewer();
	if (viewer instanceof IEditingSupportRegistry) {
		IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer;
		registry.unregister(helper);
	}
}
 
Example #7
Source File: AddImportOnSelectionAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void registerHelper(IEditingSupport helper) {
	ISourceViewer viewer= fEditor.getViewer();
	if (viewer instanceof IEditingSupportRegistry) {
		IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer;
		registry.register(helper);
	}
}
 
Example #8
Source File: AddImportOnSelectionAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void deregisterHelper(IEditingSupport helper) {
	ISourceViewer viewer= fEditor.getViewer();
	if (viewer instanceof IEditingSupportRegistry) {
		IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer;
		registry.unregister(helper);
	}
}
 
Example #9
Source File: RenameLinkedMode.java    From typescript.java with MIT License 4 votes vote down vote up
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: RenameLinkedMode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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);
		}
	}