當前位置: 首頁>>代碼示例>>Java>>正文


Java ITextSelection.isEmpty方法代碼示例

本文整理匯總了Java中org.eclipse.jface.text.ITextSelection.isEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java ITextSelection.isEmpty方法的具體用法?Java ITextSelection.isEmpty怎麽用?Java ITextSelection.isEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jface.text.ITextSelection的用法示例。


在下文中一共展示了ITextSelection.isEmpty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
public void run()
{
    VelocityEditor editor = (VelocityEditor) getTextEditor();
    if (editor.fMouseListener.fActiveRegion != null)
    {
        // If the user is using the ctrl-alt mouse click feature, then
        // goto the definition under the mouse, and not under the current cursor location
        editor.gotoDefinition(editor.fMouseListener.fActiveRegion);
        return;
    }
    
    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
    if (!selection.isEmpty())
    {
        
        editor.gotoDefinition(new Region(selection.getOffset(), selection.getLength()));
    }
}
 
開發者ID:ninneko,項目名稱:velocity-edit,代碼行數:19,代碼來源:GotoDefinitionAction.java

示例2: isValidSelection

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
 * Returns if the current selection is valid, i.e. whether it is empty and
 * the caret in the whitespace at the start of a line, or covers multiple
 * lines.
 * 
 * @return <code>true</code> if the selection is valid for an indent
 *         operation
 */
private boolean isValidSelection() {
	ITextSelection selection = getSelection();
	if (selection.isEmpty())
		return false;

	int offset = selection.getOffset();
	int length = selection.getLength();

	IDocument document = getDocument();
	if (document == null)
		return false;

	try {
		IRegion firstLine = document.getLineInformationOfOffset(offset);
		int lineOffset = firstLine.getOffset();

		// either the selection has to be empty and the caret in the WS at
		// the line start
		// or the selection has to extend over multiple lines
		if (length == 0)
			return document.get(lineOffset, offset - lineOffset).trim().length() == 0;
		else
			// return lineOffset + firstLine.getLength() < offset + length;
			return false; // only enable for empty selections for now

	} catch (BadLocationException e) {
	}

	return false;
}
 
開發者ID:angelozerr,項目名稱:typescript.java,代碼行數:39,代碼來源:IndentAction.java


注:本文中的org.eclipse.jface.text.ITextSelection.isEmpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。