代码之家  ›  专栏  ›  技术社区  ›  Imaskar

Eclipse RCP-内容辅助故障[已关闭]

  •  0
  • Imaskar  · 技术社区  · 17 年前

    我正在尝试向我的编辑器添加内容辅助。我补充说

        public IContentAssistant getContentAssistant(ISourceViewer sv) {
        ContentAssistant ca = new ContentAssistant();
        IContentAssistProcessor pr = new TagCompletionProcessor();
        ca.setContentAssistProcessor(pr, XMLPartitionScanner.XML_TAG);
        ca.setContentAssistProcessor(pr, IDocument.DEFAULT_CONTENT_TYPE);
        return ca;
    }
    

    到编辑器配置,然后生成完成处理器类:

    public class TagCompletionProcessor implements IContentAssistProcessor {
    private ITypedRegion wordRegion;
    private String currentWord;
    private SmartTreeSet tags;
    public TagCompletionProcessor() {
        tags = new SmartTreeSet();
        //filling tags skipped
    }
    @Override
    public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
            int offset) {
        System.out.println("compute");
        wordRegion = viewer.getDocument().getDocumentPartitioner().getPartition(offset);
        try {
            int offs = wordRegion.getOffset();
            int len = wordRegion.getLength();
            currentWord = viewer.getDocument().get(offs, len);
            return tags.getProposals(currentWord.toLowerCase(), offs, len);
        } catch (BadLocationException e) {
            return null;
        }
    }
    @Override
    public IContextInformation[] computeContextInformation(ITextViewer viewer,
            int offset) {
        return null;
    }
    @Override
    public char[] getCompletionProposalAutoActivationCharacters() {
        return new char[] {'<'};
    }
    @Override
    public char[] getContextInformationAutoActivationCharacters() {
        return null;
    }
    @Override
    public IContextInformationValidator getContextInformationValidator() {
        return null;
    }
    @Override
    public String getErrorMessage() {
        return "No tags found";
    }
    

    }

    ... 但它不起作用。初始化正常,但自动激活不起作用,当我按ctrl-space(我已将org.eclipse.ui.edit.text.contentAssist.Propositions命令添加到Bindings ext point)时,会出现空列表(它也不在光标附近,而是在某个固定位置)。我做错了什么?

    3 回复  |  直到 17 年前
        1
  •  0
  •   Martin Lazar    17 年前

    如果您的文档实现

    ca.setDocumentPartitioning(MyPartitionScanner.MyPartitioning);
    

    希望这有帮助

        2
  •  0
  •   Nikolay Krasko Nikolay Krasko    17 年前

    您应该在编辑器中注册您的操作并替换默认操作。 下面是一个如何使用内容辅助操作的示例。

    http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_actions.htm

        3
  •  0
  •   Imaskar    15 年前

    对不起,中间有一些空输出。多么失败啊=(