【JfaceTextFramework学习笔记之二】内容提示
来源:互联网 发布:开源的数据库防火墙 编辑:程序博客网 时间:2024/05/01 22:40
来完成一段句子。也可以用来对特定的文本提供额外的相关信息。
2-实现内容提示是可选的,默认情况下SourceViewerConfiguration 并不提供内容提示,因为并不清楚要编辑的具体内容。
3- 要实现内容提示,编辑器的source viewer configuration 必须要被配置.
在Java例子中的JavaSourceViewerConfiguration中是这么做的:
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistant assistant= new ContentAssistant();
assistant.setContentAssistProcessor(new JavaCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
assistant.setContentAssistProcessor(new JavaDocCompletionProcessor(), JavaPartitionScanner.JAVA_DOC);
...
return assistant;
}
4-IContentAssistant接口,建立内容提示content assistant和语法高亮很相似.
assistant对象要被针对不同的内容类型配置对应的phrase completion strategies
5-IContentAssistProcessor 接口定义了完成策略,提示完成信息,和环境信息,根据一个特定的内容类型中的位移(因为在同一类型的分区中不同的位移可能有不同的提示)
6-并不是所有的分区都需要提示,
Java例子中:JavaCompletionProcessor 对关键字进行提示,
所以关键字被定义在一个属性变量中,
JavaCompletionProcessor :
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {7- 内容提示的激发,用户主动请求(alt+/)或者碰到.或者(
ICompletionProposal[] result= new ICompletionProposal[fgProposals.length];
for (int i= 0; i < fgProposals.length; i++) {
IContextInformation info= new ContextInformation(fgProposals[i], MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
result[i]= new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i]})); //$NON-NLS-1$
}
return result;
}
public char[] getCompletionProposalAutoActivationCharacters() {return new char[] { '.', '(' };}
8-内容提示之外JavaCompletionProcessor 还定义可以被用户请求的环境信息
In the Java editor example, the information is not really contextual. An array containing five similar context information objects is computed for the current offset when the user requests context info. All of these context information objects define a context that contains the five characters in front of the offset and the five after the offset. If any one of these five proposals is selected, the detailed information will appear near the cursor and will stay as long as the cursor is within the context of the five characters around the offset.
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {IContextInformation[] result= new IContextInformation[5];for (int i= 0; i < result.length; i++)result[i]= new ContextInformation(MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"), new Object[] { new Integer(i), new Integer(documentOffset) }),MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"), new Object[] { new Integer(i), new Integer(documentOffset - 5), new Integer(documentOffset + 5)}));return result;}
当输入#时显示环境信息
public char[] getContextInformationAutoActivationCharacters() {return new char[] { '#' };}
9-可以使用IContentAssistant来配置内容提示的外观和行为。
比如,可以配置自动激发的时间,提示方向,和信息弹出的颜色
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistant assistant= new ContentAssistant();
...
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(500);
assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
assistant.setContextInformationPopupBackground(JavaEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
return assistant;
}
10-为了允许用户调用内容提示,必须创建一个Action
一般在子类重写的 AbstractTextEditor.createActions()
中进行创建:
protected void createActions() {...IAction action= new ContentAssistAction(aResourceBundle, "ContentAssistProposal.", this); //$NON-NLS-1$action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);setAction(actionId, action); //$NON-NLS-1$markAsStateDependentAction(actionId, true); //$NON-NLS-1$PlatformUI.getWorkbench().getHelpSystem().setHelp(action, helpContextId);...}在编辑器的主菜单中显示该Action
private RetargetTextEditorAction fContentAssist;public MyEditorActionContributor() {fContentAssist= new RetargetTextEditorAction();String commandId= ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS;fContentAssist.setActionDefinitionId(commandId);}public void contributeToMenu(IMenuManager menu) {IMenuManager editMenu= menu.findMenuUsingPath(M_EDIT);editMenu.appendToGroup(MB_ADDITIONS, fContentAssist);}public void setActiveEditor(IEditorPart part) {IAction editorAction= getAction(part, "ContentAssist");fContentAssist.setAction(editorAction);}...
- 【JfaceTextFramework学习笔记之二】内容提示
- 【JfaceTextFramework学习笔记之三】大纲视图
- 【JfaceTextFramework学习笔记之五】积累
- 【JfaceTextFramework学习笔记之四】TextViewer实现原理简单分析
- 【JfaceTextFramework学习笔记之一】语法高亮
- 【JfaceTextFramework学习笔记之六】Jface提供的Rule基类总结
- Android学习笔记二十八之AlertDialog提示对话框和几个常用的提示框
- Android学习笔记二十八之AlertDialog提示对话框和几个常用的提示框
- 推荐系统学习笔记之二 基于内容的推荐系统(CBRS)+Collaborative Filtering 协同过滤
- 高级软件工程师学习内容体系之二
- Android学习笔记二十一之AutoCompleteTextView(自动提示文本框)和MutiAutoCompleteTextView(多提示项的自动提示文本框)
- Android学习笔记二十一之AutoCompleteTextView(自动提示文本框)和MutiAutoCompleteTextView(多提示项的自动提示文本框)
- jquery Select2 学习笔记之中文提示
- Bootstrap3 工具提示之个人学习笔记
- Jabber学习笔记 之二
- SDL学习笔记之二
- Jabber学习笔记 之二
- WinCE学习笔记之二
- 学习PetShop3.0(3)模仿购物车的简单可变类
- 理解并扩展 ASP.NET 2.0 中的站点导航系统
- Linux下编辑十六进制文件
- zlib 库和libpng 的安装:
- 几种常见算法的介绍及复杂度分析
- 【JfaceTextFramework学习笔记之二】内容提示
- 一段判断多种浏览器类型及版本号的脚本代码
- IIS 日志的学习
- Actionscript高质量编程 -- 1 (参照并复制 林锐博士的 《高质量c/c++的编程指南》,只是把c的代码改成了as,其他不变)
- oracle table()函数用法
- JavaScript 读写文件
- TCP/IP-端口大全
- 学习PetShop3.0(4)购物车
- 打印gridview中的内容