org.eclipse.jface.text.link.LinkedModeUI.ExitFlags Java Examples

The following examples show how to use org.eclipse.jface.text.link.LinkedModeUI.ExitFlags. 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: IdentifierExitPolicy.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * If the entered character is not a valid identifier part, it is processed after linked editing has been quit.
 * Exceptions are the {@link #exitCharacters} that have been passed into the constructor.
 */
@Override
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {
	if (event.character == '\0')
		return null;
	for (char c : exitCharacters) {
		if (event.character == c) {
			return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
		}
	}
	switch (event.character) {
	case SWT.CR:
		return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
	default: {
		if (!Character.isJavaIdentifierPart(event.character)) {
			return new ExitFlags(ILinkedModeListener.UPDATE_CARET, true);
		}
		return null;
	}
	}
}
 
Example #2
Source File: ConfigurableCompletionProposal.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {
	if (event.character == '\0')
		return null;
	for (char c: exitCharacters) {
		if (event.character == c) {
			return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
		}
	}

	switch (event.character) {
		case SWT.CR:
			return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
		default:
			return null;
	}
}
 
Example #3
Source File: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	showPreview = (event.stateMask & SWT.CTRL) != 0 && (event.character == SWT.CR || event.character == SWT.LF);
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position = model.findPosition(new LinkedPosition(document, offset, 0,
				LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					// skip backspace at beginning of linked position
					event.doit = false;
				}
			} else /* event.character == SWT.DEL */{
				if (offset + 1 > position.getOffset() + position.getLength()) {
					// skip delete at end of linked position
					event.doit = false;
				}
			}
		}
	}
	return null; // don't change behavior
}
 
Example #4
Source File: BracketInserter.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
    
    if (fSize == fStack.size() && !isMasked(offset)) {
        if (event.character == fExitCharacter) {
            BracketLevel level= (BracketLevel) fStack.peek();
            if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
                return null;
            if (level.fSecondPosition.offset == offset && length == 0)
                // don't enter the character if if its the closing peer
                return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        }
        // when entering an anonymous class between the parenthesis', we don't want
        // to jump after the closing parenthesis when return is pressed
        if (event.character == SWT.CR && offset > 0) {
            IDocument document= sourceViewer.getDocument();
            try {
                if (document.getChar(offset - 1) == '{')
                    return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
            } catch (BadLocationException e) {
            }
        }
    }
    return null;
}
 
Example #5
Source File: LinkedNamesAssistProposal.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
Example #6
Source File: BracketInserter.java    From typescript.java with MIT License 6 votes vote down vote up
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {

			if (fSize == fStack.size() && !isMasked(offset)) {
				if (event.character == fExitCharacter) {
					BracketLevel level = (BracketLevel) fStack.peek();
					if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
						return null;
					if (level.fSecondPosition.offset == offset && length == 0)
						// don't enter the character if if its the closing peer
						return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
				}
				// when entering an anonymous class between the parenthesis', we
				// don't want
				// to jump after the closing parenthesis when return is pressed
				if (event.character == SWT.CR && offset > 0) {
					IDocument document = getSourceViewer().getDocument();
					try {
						if (document.getChar(offset - 1) == '{')
							return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
					} catch (BadLocationException e) {
					}
				}
			}
			return null;
		}
 
Example #7
Source File: ExitPolicy.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length)
{
	if (shouldInsertNewline())
	{
		if (event.character == '\n' || event.character == '\r')
		{
			return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
		}
	}

	if (event.character != fExitCharacter)
		return null;

	if (fSize == fStack.size() && !isEscaped(offset))
	{
		BracketLevel level = fStack.peek();
		if (offset < level.fFirstPosition.offset || level.fSecondPosition.offset < offset)
			return null;
		if (level.fSecondPosition.offset == offset && length == 0)
			// don't enter the character if it is the closing peer
			return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
	}

	return null;
}
 
Example #8
Source File: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {

			if (fSize == fStack.size() && !isMasked(offset)) {
				if (event.character == fExitCharacter) {
					BracketLevel level= fStack.peek();
					if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
						return null;
					if (level.fSecondPosition.offset == offset && length == 0)
						// don't enter the character if if its the closing peer
						return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
				}
				// when entering an anonymous class between the parenthesis', we don't want
				// to jump after the closing parenthesis when return is pressed
				if (event.character == SWT.CR && offset > 0) {
					IDocument document= getSourceViewer().getDocument();
					try {
						if (document.getChar(offset - 1) == '{')
							return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
					} catch (BadLocationException e) {
					}
				}
			}
			return null;
		}
 
Example #9
Source File: LinkedNamesAssistProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
Example #10
Source File: DeleteBlockingExitPolicy.java    From eclipse-multicursor with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
Example #11
Source File: TypeScriptCompletionProposal.java    From typescript.java with MIT License 5 votes vote down vote up
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {

			if (event.character == fExitCharacter) {
				if (environment.anyPositionContains(offset))
					return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
				else
					return new ExitFlags(ILinkedModeListener.UPDATE_CARET, true);
			}

			switch (event.character) {
			case ';':
				return new ExitFlags(ILinkedModeListener.NONE, true);
			case SWT.CR:
				// when entering an anonymous class as a parameter, we don't
				// want
				// to jump after the parenthesis when return is pressed
				if (offset > 0) {
					try {
						if (fDocument.getChar(offset - 1) == '{')
							return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
					} catch (BadLocationException e) {
					}
				}
				return null;
			default:
				return null;
			}
		}
 
Example #12
Source File: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {

			if (event.character == fExitCharacter) {
				if (environment.anyPositionContains(offset))
					return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
				else
					return new ExitFlags(ILinkedModeListener.UPDATE_CARET, true);
			}

			switch (event.character) {
				case ';':
					return new ExitFlags(ILinkedModeListener.NONE, true);
				case SWT.CR:
					// 1) when entering an anonymous class as a parameter, we don't want
					// to jump after the parenthesis when return is pressed
					// 2) after auto completion of methods without parameters, exit from linked mode when return is pressed
					if (offset > 0) {
						try {
							char prevOffsetChar= fDocument.getChar(offset - 1);
							if (prevOffsetChar == '{' || prevOffsetChar == ';')
								return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
						} catch (BadLocationException e) {
						}
					}
					return null;
				default:
					return null;
			}
		}
 
Example #13
Source File: LangCompletionProposal.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	switch (event.character) {
	case SWT.CR:
		int endOfReplacement = getReplaceOffset() + getEffectiveReplaceString(false).length();
		if(offset == endOfReplacement) {
			return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
		}
		return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
	}
	return null;
}
 
Example #14
Source File: RenameLinkedMode.java    From typescript.java with MIT License 4 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	fShowPreview = (event.stateMask & SWT.CTRL) != 0
			&& (event.character == SWT.CR || event.character == SWT.LF);
	return super.doExit(model, event, offset, length);
}
 
Example #15
Source File: RenameLinkedMode.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	fShowPreview= (event.stateMask & SWT.CTRL) != 0
					&& (event.character == SWT.CR || event.character == SWT.LF);
	return super.doExit(model, event, offset, length);
}
 
Example #16
Source File: LinkedProposalModelPresenter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (event.character  == '=') {
		return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
	}
	return null;
}