Java Code Examples for org.eclipse.jface.text.ITextViewer#getSelectedRange()

The following examples show how to use org.eclipse.jface.text.ITextViewer#getSelectedRange() . 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: CommonDoubleClickStrategy.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void doubleClicked(ITextViewer part)
{
	int pos = part.getSelectedRange().x;
	if (pos < 0)
		return;
	fText = part;
	if (fCtrlDown)
	{
		if (!selectComment(pos))
		{
			selectWord(pos);
		}
	}
	else
	{
		selectWord(pos);
	}
}
 
Example 2
Source File: ModulaAssistProcessor2.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
		int offset) {
	CompletionContext context = computeContext(viewer, offset);
	List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>();
	doComputeCompletionProposals(context, completionProposals);
	
	if (completionProposals.isEmpty() /*&& !isAstUpToDate()*/) {
		IModuleSymbol moduleSymbol = context.getModuleSymbol();
		if (moduleSymbol == null) {
			EmptyCompletionProposal emptyCompletionProposal = new EmptyCompletionProposal(Messages.XdsOutlinePage_Loading, 
					LOADING_IMAGE, viewer.getSelectedRange().x);
			return new ICompletionProposal[]{emptyCompletionProposal, emptyCompletionProposal};
		}
		else {
			return null;
		}
	}
	return completionProposals.toArray(new ICompletionProposal[0]);
}
 
Example 3
Source File: TypeScriptCompletionProposal.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
	initIfNeeded();
	IDocument document = viewer.getDocument();
	if (fTextViewer == null) {
		fTextViewer = viewer;
	}
	// don't eat if not in preferences, XOR with modifier key 1 (Ctrl)
	// but: if there is a selection, replace it!
	Point selection = viewer.getSelectedRange();
	fToggleEating = (stateMask & SWT.MOD1) != 0;
	int newLength = selection.x + selection.y - getReplacementOffset();
	if ((insertCompletion() ^ fToggleEating) && newLength >= 0) {
		setReplacementLength(newLength);
	}
	apply(document, trigger, offset);
	fToggleEating = false;
}
 
Example 4
Source File: HDoubleClickStrategy.java    From http4e with Apache License 2.0 5 votes vote down vote up
public void doubleClicked( ITextViewer part){
   int pos = part.getSelectedRange().x;

   if (pos < 0)
      return;

   fText = part;

   if (!selectComment(pos)) {
      selectWord(pos);
   }
}
 
Example 5
Source File: PostfixTemplateEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void complete(ITextViewer viewer, int completionPosition, ICompilationUnit compilationUnit) {
	IDocument document = viewer.getDocument();

	if (!(getContextType() instanceof JavaStatementPostfixContextType))
		return;

	Point selection = viewer.getSelectedRange();

	String selectedText = null;
	if (selection.y != 0) {
		return;
	}

	JavaStatementPostfixContext context = ((JavaStatementPostfixContextType) getContextType()).createContext(document, completionPosition, selection.y, compilationUnit, currentNode, parentNode);
	context.setVariable("selection", selectedText); //$NON-NLS-1$
	int start = context.getStart();
	int end = context.getEnd();
	IRegion region = new Region(start, end - start);

	Template[] templates = JavaPlugin.getDefault().getTemplateStore().getTemplates(getContextType().getId());

	for (int i = 0; i != templates.length; i++) {
		Template template = templates[i];
		if (context.canEvaluate(template)) {
			getProposals().add(new PostfixTemplateProposal(template, context, region, getImage()));
		}
	}
}
 
Example 6
Source File: LazyJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void selected(ITextViewer viewer, boolean smartToggle) {
	Point selection= viewer.getSelectedRange();
	if (!(insertCompletion() ^ smartToggle) && selection.y > 0)
		fReplacementLengthComputed= false;
	super.selected(viewer, smartToggle);
}
 
Example 7
Source File: LazyJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
	Point selection= viewer.getSelectedRange();
	boolean smartToggle= (stateMask & SWT.CTRL) != 0;
	if (!(insertCompletion() ^ smartToggle) && selection.y > 0)
		fReplacementLengthComputed= false;
	super.apply(viewer, trigger, stateMask, offset);
}
 
Example 8
Source File: CommandExecutionUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static IRegion getSelectedLinesRegion(ITextViewer textWidget) throws BadLocationException
{
	Point selectionRange = textWidget.getSelectedRange();
	int startLine = textWidget.getDocument().getLineOfOffset(selectionRange.x);
	int endLine = textWidget.getDocument().getLineOfOffset(selectionRange.x + selectionRange.y);

	int startOffset = textWidget.getDocument().getLineOffset(startLine);
	IRegion endRegion = textWidget.getDocument().getLineInformation(endLine);
	int endOffset = endRegion.getOffset() + endRegion.getLength();
	return new Region(startOffset, endOffset - startOffset);
}
 
Example 9
Source File: TLACompletionProcessor.java    From tlaplus with MIT License 5 votes vote down vote up
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
	// Retrieve selected range
	final Point selectedRange = viewer.getSelectedRange();
	if (selectedRange.y > 0) {
		// Text is selected. Create a context information array.
		final IContextInformation[] contextInfos = new ContextInformation[ITLAReserveredWords.ALL_WORDS_ARRAY.length];

		// Create one context information item for each style
		for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++) {
			contextInfos[i] = new ContextInformation(null, ITLAReserveredWords.ALL_WORDS_ARRAY[i] + " Style");
		}
		return contextInfos;
	}
	return new ContextInformation[0];
}
 
Example 10
Source File: ToolboxCompletionProcessor.java    From tlaplus with MIT License 5 votes vote down vote up
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
	// Retrieve selected range
	final Point selectedRange = viewer.getSelectedRange();
	if (selectedRange.y > 0) {
		// Text is selected. Create a context information array.
		final IContextInformation[] contextInfos = new ContextInformation[ITLAReserveredWords.ALL_WORDS_ARRAY.length];

		// Create one context information item for each style
		for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++) {
			contextInfos[i] = new ContextInformation(null, ITLAReserveredWords.ALL_WORDS_ARRAY[i] + " Style");
		}
		return contextInfos;
	}
	return new ContextInformation[0];
}
 
Example 11
Source File: ToolboxCompletionProcessor.java    From tlaplus with MIT License 5 votes vote down vote up
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
	final IDocument document = viewer.getDocument();
	// get the selection range
	final Point selectedRange = viewer.getSelectedRange();

	final List<ICompletionProposal> propList = new ArrayList<ICompletionProposal>();
	try {
		// The zero-based row index of the caret.
		final int caretRowIndex = document.getLineOfOffset(offset);
		// The zero-based column index of the caret.
		final int carretColumnIndex = offset - document.getLineOffset(caretRowIndex);
		if (selectedRange.y > 0) {
			// the range is non-empty
			final String text = document.get(selectedRange.x, selectedRange.y);
			computeWordProposals(text, offset, carretColumnIndex, propList);
		} else {
			// the range is empty, no selection in the editor

			// get the region
			final IRegion wordRegion = DocumentHelper.getRegionExpandedBackwards(document, offset,
					DocumentHelper.getDefaultWordDetector());
			final String word = document.get(wordRegion.getOffset(), wordRegion.getLength());
			computeWordProposals(word, offset, carretColumnIndex, propList);
		}
	} catch (final BadLocationException ignore) {
	}
	return propList.toArray(new ICompletionProposal[propList.size()]);
}
 
Example 12
Source File: TexCompletionProcessor.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public IContextInformation[] computeContextInformation(ITextViewer viewer,
		int offset) {

	// FIXME -- for testing
	// Retrieve selected range
	Point selectedRange = viewer.getSelectedRange();
	if (selectedRange.y > 0) {

		if (styleManager == null) {
			styleManager = TexStyleCompletionManager.getInstance();
		}
		return styleManager.getStyleContext();
	}
	return new ContextInformation[0];
}
 
Example 13
Source File: AbstractHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IRegion getHoverRegion(final ITextViewer textViewer, final int offset) {
	final Point selection = textViewer.getSelectedRange();
	if (selection.x <= offset && offset < selection.x + selection.y)
		return new Region(selection.x, selection.y);
	return new Region(offset, 0);
}
 
Example 14
Source File: EditorUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Copy of {@link org.eclipse.jface.text.source.MatchingCharacterPainter#getSignedSelection()}
 */
public static final IRegion getSignedSelection(ITextViewer sourceViewer) {
	Point viewerSelection= sourceViewer.getSelectedRange();

	StyledText text= sourceViewer.getTextWidget();
	Point selection= text.getSelectionRange();
	if (text.getCaretOffset() == selection.x) {
		viewerSelection.x= viewerSelection.x + viewerSelection.y;
		viewerSelection.y= -viewerSelection.y;
	}

	return new Region(viewerSelection.x, viewerSelection.y);
}
 
Example 15
Source File: XMLDoubleClickStrategy.java    From http4e with Apache License 2.0 5 votes vote down vote up
public void doubleClicked(ITextViewer part) {
	int pos = part.getSelectedRange().x;

	if (pos < 0)
		return;

	fText = part;

	if (!selectComment(pos)) {
		selectWord(pos);
	}
}
 
Example 16
Source File: CommandExecutionUtils.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
protected static FilterInputProvider getInputProvider(ITextViewer textWidget, CommandElement command,
		InputType inputType) throws BadLocationException
{
	Point selectionRange = textWidget.getSelectedRange();
	switch (inputType)
	{
	// TODO Move this logic into the enum itself
		case UNDEFINED:
		case NONE:
			return CommandExecutionUtils.EOF;
		case SELECTION:
			if (selectionRange.y == 0)
				return null;
			IRegion selectedRegion = getSelectedRegion(textWidget);
			return new CommandExecutionUtils.StringInputProvider(textWidget.getDocument().get(
					selectedRegion.getOffset(), selectedRegion.getLength()));
		case SELECTED_LINES:
			if (selectionRange.y == 0)
				return null;
			IRegion region = getSelectedLinesRegion(textWidget);
			return new CommandExecutionUtils.StringInputProvider(textWidget.getDocument().get(region.getOffset(),
					region.getLength()));
		case DOCUMENT:
			return new CommandExecutionUtils.StringInputProvider(textWidget.getDocument().get());
		case LEFT_CHAR:
			if (getCaretOffset(textWidget) < 1)
				return null;
			return new CommandExecutionUtils.StringInputProvider(textWidget.getDocument().get(
					getCaretOffset(textWidget) - 1, 1));
		case RIGHT_CHAR:
			if (getCaretOffset(textWidget) < getEndOffset(textWidget))
				return new CommandExecutionUtils.StringInputProvider(textWidget.getDocument().get(
						getCaretOffset(textWidget), 1));
			return null;
		case CLIPBOARD:
			String contents = getClipboardContents();
			if (contents == null || contents.trim().length() == 0)
				return null;
			return new CommandExecutionUtils.StringInputProvider(contents);
		case LINE:
			return new CommandExecutionUtils.StringInputProvider(getCurrentLineText(textWidget));
		case WORD:
			String currentWord = findWord(textWidget);
			if (currentWord == null || currentWord.trim().length() == 0)
				return null;
			return new CommandExecutionUtils.StringInputProvider(currentWord);
		case INPUT_FROM_CONSOLE:
			return new CommandExecutionUtils.EclipseConsoleInputProvider(CommandExecutionUtils.DEFAULT_CONSOLE_NAME);
		case INPUT_FROM_FILE:
			return new CommandExecutionUtils.FileInputProvider(command.getInputPath());
	}
	return null;
}
 
Example 17
Source File: CommandExecutionUtils.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private static IRegion getSelectedRegion(ITextViewer textWidget)
{
	return new Region(textWidget.getSelectedRange().x, textWidget.getSelectedRange().y);
}
 
Example 18
Source File: EditorUtils.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static SourceRange getSelectedRange(ITextViewer viewer) {
	Point selectedRange = viewer.getSelectedRange();
	return new SourceRange(selectedRange.x, selectedRange.y);
}
 
Example 19
Source File: MyTextHover.java    From http4e with Apache License 2.0 4 votes vote down vote up
public IRegion getHoverRegion( ITextViewer textViewer, int offset){
   Point selection = textViewer.getSelectedRange();
   if (selection.x <= offset && offset < selection.x + selection.y)
      return new Region(selection.x, selection.y);
   return new Region(offset, 0);
}
 
Example 20
Source File: SmartBackspaceManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int getCaretOffset() {
	ITextViewer viewer= fViewer;
	Point point= viewer.getSelectedRange();
	return point.x;
}