CEditor里鼠标悬停在word上显示对应声明代码的提示框的代码
2014-04-15 19:26
459 查看
org.eclipse.jface.text.TextViewerHoverManager
org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover
相关类:
org.eclipse.jface.text.AbstractInformationControlManager
org.eclipse.cdt.internal.ui.text.c.hover.BestMatchHover
org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor
org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverProxy
org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover
org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover.ComputeSourceRunnable
org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl
org.eclipse.jface.text.TextViewerHoverManager
/** * Determines all necessary details and delegates the computation into * a background thread. */ protected void computeInformation() { if (!fProcessMouseHoverEvent) { setInformation(null, null); return; } Point location= getHoverEventLocation(); int offset= computeOffsetAtLocation(location.x, location.y); if (offset == -1) { setInformation(null, null); return; } final ITextHover hover= fTextViewer.getTextHover(offset, getHoverEventStateMask()); if (hover == null) { setInformation(null, null); return; } final IRegion region= hover.getHoverRegion(fTextViewer, offset); if (region == null) { setInformation(null, null); return; } final Rectangle area= JFaceTextUtil.computeArea(region, fTextViewer); if (area == null || area.isEmpty()) { setInformation(null, null); return; } if (fThread != null) { setInformation(null, null); return; } fThread= new Thread("Text Viewer Hover Presenter") { //$NON-NLS-1$ public void run() { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=17693 boolean hasFinished= false; try { if (fThread != null) { Object information; try { //此处获取提示信息 if (hover instanceof ITextHoverExtension2) information= ((ITextHoverExtension2)hover).getHoverInfo2(fTextViewer, region); else information= hover.getHoverInfo(fTextViewer, region); } catch (ArrayIndexOutOfBoundsException x) { /* * This code runs in a separate thread which can * lead to text offsets being out of bounds when * computing the hover info (see bug 32848). */ information= null; } if (hover instanceof ITextHoverExtension) setCustomInformationControlCreator(((ITextHoverExtension) hover).getHoverControlCreator()); else setCustomInformationControlCreator(null); setInformation(information, area);//此处设置提示信息 if (information != null) fTextHover= hover; } else { setInformation(null, null); } hasFinished= true; } catch (RuntimeException ex) { String PLUGIN_ID= "org.eclipse.jface.text"; //$NON-NLS-1$ ILog log= Platform.getLog(Platform.getBundle(PLUGIN_ID)); log.log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, "Unexpected runtime error while computing a text hover", ex)); //$NON-NLS-1$ } finally { synchronized (fMutex) { if (fTextViewer != null) fTextViewer.removeTextListener(fStopper); fThread= null; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=44756 if (!hasFinished) setInformation(null, null); } } } }; fThread.setDaemon(true); fThread.setPriority(Thread.MIN_PRIORITY); synchronized (fMutex) { fTextViewer.addTextListener(fStopper); fThread.start(); } }
org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { IEditorPart editor = getEditor(); if (editor != null) { IEditorInput input= editor.getEditorInput(); IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager(); IWorkingCopy copy = manager.getWorkingCopy(input); try { if (copy == null || !copy.isConsistent()) { return null; } } catch (CModelException exc) { return null; } String expression; try { expression = textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength()); expression = expression.trim(); if (expression.length() == 0) return null; //Before trying a search lets make sure that the user is not hovering over a keyword if (selectionIsKeyword(expression)) return null; String source= null; // Try with the indexer 在indexer中查找 source= searchInIndex(copy, hoverRegion); if (source == null || source.trim().length() == 0) return null; // we are actually interested in the comments, too. // source= removeLeadingComments(source); String delim= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ String[] sourceLines= Strings.convertIntoLines(source); String firstLine= sourceLines[0]; boolean ignoreFirstLine = firstLine.length() > 0 && !Character.isWhitespace(firstLine.charAt(0)); Strings.trimIndentation(sourceLines, getTabWidth(), getTabWidth(), !ignoreFirstLine); source = Strings.concatenate(sourceLines, delim); return source; } catch (BadLocationException e) { } } return null; }
相关类:
org.eclipse.jface.text.AbstractInformationControlManager
org.eclipse.cdt.internal.ui.text.c.hover.BestMatchHover
org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor
org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverProxy
org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover
org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover.ComputeSourceRunnable
org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl
org.eclipse.jface.text.TextViewerHoverManager
相关文章推荐
- Spring 3.0参考手册之SpEL
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
- 初识springMVC
- Struts2提交表单中文乱码问题解决
- C# WinForm多线程开发(一) Thread类库
- C# WinForm多线程开发(一) Thread类库
- java继承
- androd—Intent操作ContentProvider获取电话号码
- C#迁移之callXBFLibrary - ADO.net
- java对象的行为
- 在Qt Widget中使用QPainter之外的引擎进行绘图
- 【甘道夫】win7环境下eclipse连接hadoop报错简单解决:重编译FileUtil.java
- Eclipse中要导出jar包中引用了第三方jar包怎么办【】
- Eclipse翻Wall及Android SDK 下载更新问题
- 旋转字符串问题
- 入门级的病毒源码[VC++]
- lua工具库penlight--06数据(二)
- lua工具库penlight--06数据(一)
- struts和struts2的区别
- selenium2.0关于python的常用函数