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


Java TextSelection.getStartLine方法代碼示例

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


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

示例1: toggleBreakpoints

import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
    if (part instanceof BaseEditor && selection instanceof TextSelection
            && PyToggleTargetAdapter.canToggleFor((BaseEditor) part)) {
        TextSelection textSelection = (TextSelection) selection;
        BaseEditor pyEdit = (BaseEditor) part;
        int startLine = textSelection.getStartLine();

        List<IMarker> markersFromCurrentFile = PyBreakpointRulerAction.getMarkersFromCurrentFile(pyEdit, startLine);
        if (markersFromCurrentFile.size() > 0) {
            PyBreakpointRulerAction.removeMarkers(markersFromCurrentFile);
        } else {
            PyBreakpointRulerAction.addBreakpointMarker(pyEdit.getDocument(), startLine + 1, pyEdit,
                    PyBreakpoint.PY_BREAK_TYPE_DJANGO);
        }
    }
}
 
開發者ID:fabioz,項目名稱:Pydev,代碼行數:18,代碼來源:PyToggleTargetAdapter.java

示例2: toggleBreakpoints

import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
    if (part instanceof PyEdit && selection instanceof TextSelection) {
        TextSelection textSelection = (TextSelection) selection;
        PyEdit pyEdit = (PyEdit) part;
        int startLine = textSelection.getStartLine();

        List<IMarker> markersFromCurrentFile = PyBreakpointRulerAction.getMarkersFromCurrentFile(pyEdit, startLine);
        if (markersFromCurrentFile.size() > 0) {
            PyBreakpointRulerAction.removeMarkers(markersFromCurrentFile);
        } else {
            PyBreakpointRulerAction.addBreakpointMarker(pyEdit.getDocument(), startLine + 1, pyEdit,
                    PyBreakpoint.PY_BREAK_TYPE_PYTHON);
        }

    }

}
 
開發者ID:fabioz,項目名稱:Pydev,代碼行數:19,代碼來源:PyToggleBreakpointsTarget.java

示例3: getLinkedBookmarks

import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public List<Bookmark> getLinkedBookmarks(IWorkbenchPart part, ISelection selection) {
	ITextEditor textEditor = Adapters.adapt(part, ITextEditor.class);
	if (textEditor == null) {
		return Collections.emptyList();
	}
	if (textEditor != part) {
		selection = textEditor.getSelectionProvider().getSelection();
	}
	if (!(selection instanceof TextSelection)) {
		return Collections.emptyList();
	}
	TextSelection textSelection = (TextSelection) selection;
	int line = textSelection.getStartLine();
	return getLinkedBookmarks(textEditor, line);
}
 
開發者ID:cchabanois,項目名稱:mesfavoris,代碼行數:16,代碼來源:GetLinkedBookmarksOperation.java

示例4: execute

import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public @Nullable Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
	IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
	if (!(editorPart instanceof RustEditor)) {
		return null;
	}
	RustEditor editor = (RustEditor) editorPart;
	TextSelection  sel = (TextSelection) editor.getSelectionProvider().getSelection();
	int startLine = sel.getStartLine();
	Optional<IDocument> docOpt = editor.getDocumentOpt();
	if (!docOpt.isPresent()) {
		return null;
	}
	IDocument doc = docOpt.get();
	
	try {
		int startOffset = doc.getLineOffset(startLine);
		int endOffset = sel.getOffset() + sel.getLength();
		int len = endOffset - startOffset;
		String text = doc.get(startOffset, len);
		
		
		if (text.matches("^(//(.*)(\\r?\\n|\\r))*//.*$")) {
			// remove comments
			text = text.substring(2).replaceAll("(\\r?\\n|\\r)//", "$1");
		} else {
			// add comments
			text = "//" + text.replaceAll("(\\r?\\n|\\r)", "$1//");
			
		}
		
		doc.replace(startOffset, len, text);
		// select new text
		editor.selectAndReveal(startOffset, text.length());
		
	} catch (BadLocationException e) {
		throw new RuntimeException(e);
	}
	return null;
}
 
開發者ID:peq,項目名稱:rustyeclipse,代碼行數:41,代碼來源:ToggleCommentHandler.java

示例5: execute

import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbench wb = PlatformUI.getWorkbench();
	IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
	IWorkbenchPage page = win.getActivePage();
	NCLEditor editor = ((NCLMultiPageEditor) page.getActiveEditor())
			.getNCLEditor();

	TextSelection selection = (TextSelection) editor.getSelectionProvider()
			.getSelection();
	IDocument doc = editor.getInputDocument();

	String commentBegin = "<!--";
	String commentEnd = "-->";

	// TODO: Check if the line is already commented. If it is uncomment the
	// line(off

	if (selection.getLength() > 0) {
		try {
			int offset;

			int line = selection.getStartLine();
			offset = doc.getLineOffset(line);
			
			String rest = doc.get(offset, selection.getOffset() - offset);
			int index = rest.indexOf(commentBegin);
			if (index != -1){
				doc.replace(offset + index, commentBegin.length(), "");
				
				line = selection.getEndLine();
				offset = doc.getLineOffset(line) + doc.getLineLength(line);
				rest = doc.get (selection.getOffset() + selection.getLength() - 
									commentBegin.length(), offset);
				
				index = rest.indexOf(commentEnd);
				if (index != -1)
					doc.replace(selection.getOffset() + selection.getLength()  - 
							commentBegin.length() + index, commentEnd.length(), "");
				return null;
			}
			
			offset = selection.getOffset();
			doc.replace(offset, 0, commentBegin);
			offset += selection.getLength() + commentBegin.length();
			doc.replace(offset, 0, commentEnd);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
	} else {
		// TODO: Comment the range!
		System.out.println("Comment the range!");
	}

	return null;
}
 
開發者ID:ncleclipse,項目名稱:ncl30-eclipse,代碼行數:57,代碼來源:CommentSelection.java

示例6: run

import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public void run(IAction action) {
	IWorkbench wb = PlatformUI.getWorkbench();
	IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
	IWorkbenchPage page = win.getActivePage();
	NCLEditor editor = ((NCLMultiPageEditor) page.getActiveEditor())
			.getNCLEditor();

	TextSelection selection = (TextSelection) editor.getSelectionProvider()
			.getSelection();
	IDocument doc = editor.getInputDocument();

	String commentBegin = "<!--";
	String commentEnd = "-->";
	
	int startLine  = selection.getStartLine();
	int endLine = selection.getEndLine();

	if (selection.getLength() > 0) {
		try {
			int offset;
			offset = selection.getOffset();
			IRegion region = doc.getLineInformationOfOffset(offset);
			String text = doc.get(doc.getLineOffset(startLine), offset - region.getOffset());
			
			int index = text.lastIndexOf(commentBegin);
			if (index != -1)
				doc.replace(doc.getLineOffset(startLine) + index, commentBegin.length(), "");
			else{
				text = selection.getText();
				index = text.indexOf(commentBegin);
				doc.replace(offset + index, commentBegin.length(), "");
			}
			
			offset += selection.getLength();
			region = doc.getLineInformationOfOffset(offset);
			text = doc.get(offset, doc.getLineLength(endLine) - (offset - region.getOffset()) );
			index = text.indexOf(commentEnd);
			if (index != -1)
				doc.replace(offset, commentEnd.length(), "");
			else{
				text = selection.getText();
				index = text.lastIndexOf(commentEnd);
				if (index != -1)
					doc.replace(selection.getOffset() + index, commentEnd.length(), "");
			}
			
			
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
	} else {
		// TODO: Comment the range!
		System.out.println("Comment the range!");
	}

	return;
}
 
開發者ID:ncleclipse,項目名稱:ncl30-eclipse,代碼行數:59,代碼來源:UncommentSelection.java

示例7: run

import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@SuppressWarnings("restriction")
@Override
public void run(IAction action) {
	TextSelection textSelection = CodeMarkerFactory.getTextSelection();
	TreeSelection treeSelection = CodeMarkerFactory.getTreeSelection();
	MappingElement map = null;
	if (textSelection != null) {
		IFile file = (IFile) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor().getEditorInput().getAdapter(IFile.class);
		int startLine = textSelection.getStartLine();
		int endLine = textSelection.getEndLine();
		int offset = textSelection.getOffset();
		MarkerHandler.getInstance().removeMarker(file, startLine, endLine);
		map = new MappingElement("", file.getName(),
				JavaElements.CODE_FRAGMENT, file.getFullPath().toString(),
				textSelection.getText(), startLine, endLine, offset);
	} else if (treeSelection != null) {
		String elementName;
		IPath elementPath;
		JavaElements elementType = null;
		IProject project;
		Object selectedElement = treeSelection.getFirstElement();
		IJavaProject javaProject = null;
		org.eclipse.jdt.internal.core.JavaElement element = null;
		if (selectedElement instanceof org.eclipse.jdt.internal.core.PackageFragment) {
			element = ((org.eclipse.jdt.internal.core.PackageFragment) treeSelection
					.getFirstElement());
			elementType = JavaElements.PACKAGE;
			IJavaElement[] children = null;
			try {
				children = element.getChildren();
			} catch (JavaModelException e1) {
				e1.printStackTrace();
			}
			for (IJavaElement child : children) {
				deleteMarkersOfFile(child.getResource());
			}
		} else if (selectedElement instanceof org.eclipse.jdt.internal.core.CompilationUnit) {
			element = ((org.eclipse.jdt.internal.core.CompilationUnit) treeSelection
					.getFirstElement());
			elementType = JavaElements.CLASS;
			deleteMarkersOfFile(element.getResource());
		} else if (selectedElement instanceof org.eclipse.jdt.internal.core.SourceType) {
			element = ((org.eclipse.jdt.internal.core.SourceType) treeSelection
					.getFirstElement());
			elementType = JavaElements.CLASS;
			deleteMarkersOfFile(element.getResource());
		} else if (selectedElement instanceof org.eclipse.jdt.internal.core.SourceMethod) {
			element = ((org.eclipse.jdt.internal.core.SourceMethod) treeSelection
					.getFirstElement());
			elementType = JavaElements.METHOD;
			// not yet implemented
		}
		javaProject = element.getJavaProject();
		elementPath = element.getPath();
		elementName = element.getElementName();
		project = javaProject.getProject();
		map = new MappingElement("", elementName, elementType,
				elementPath.toString(), project.getLocation().toFile()
						.getAbsolutePath());
	}
	ControllerHandler.getInstance().getFeatureController()
			.removeMapping(map);
}
 
開發者ID:1Tristan,項目名稱:VariantSync,代碼行數:66,代碼來源:RemoveMarkers.java


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