Eclipse插件可以精细地监控编辑器的更改 [英] Eclipse Plugin to granularly monitor editor changes

查看:156
本文介绍了Eclipse插件可以精细地监控编辑器的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在开发一个用于Eclipse 4.2的插件,用于监视用户对其文件进行的编辑。

So, I'm looking to develop a plugin for Eclipse 4.2 that monitors edits that a user makes to their files.

这是我的第一个Eclipse插件,为了准备,我浏览了Eclipse插件开发作弊表(HelloWorld),并在help.eclipse.org上查看了几个小时文档和API。我想我有一些想法,我需要什么工具,但我不知道如何把这些工具在一起做我想要的。

This is my first Eclipse plugin, and to prepare, I walked through the Eclipse plugin development cheat sheet (HelloWorld) and spent many hours on help.eclipse.org looking through the documentation and the API. I think I have some idea of what tools I need, but I'm not sure how to put those tools together to do what I want.

期望的结果:有一个插件被添加到(Java)编辑器和任何和所有删除的每个新信件被通知。这包括Eclipse所做的事情(自动完成变量,花括号)以及用户类型。

Desired Results: Have a plugin that's kept apprised of every new letter added to a (Java) editor and any and all deletes. This includes things that Eclipse does (auto-completing variables, curly braces) as well as what the user types.

可能有助于的工具:我认为,一个 IResourceChangeListener 将有助于,因为它提供了一个 IResourceChangeEvent ,可以访问表示工作空间更改的 IResourceDelta 。另外,由于编辑器扩展了EditorPart,所以我认为添加一个 IPropertyChangeListener 到相关的编辑器也是有用的。

Tools that might help: I'm thinking that a IResourceChangeListener will assist, as it gives me a IResourceChangeEvent, with an accessible IResourceDelta which represents workspace changes. Also, since editors extend EditorPart, I'm thinking that adding a IPropertyChangeListener to the relevant editor may be useful as well.

我想我我已经得到了正确的工具,但是我不知道如何组装它们来做我想做的事。

I think I've got the right tools, but I've got no idea how to go about assembling them to do as I wish.

问题

上面列出的工具是否适合工作?

如何获取所有打开的或将被打开的编辑器的列表,并向其添加监听器?

有关学习如何编程Eclipse插件的资源的其他提示?

Questions:
Are the tools listed above the proper ones for the job?
How can I get a list of all editors opened or that will be opened and add listeners to them?
Any additional tips for resources on learning how to program Eclipse plugins?

推荐答案

Krumelur的提示给了我一个很好的起点。由 IDocumentListener 返回的 DocumentEvent 是足够细致的,可以通过字符分析发生了什么。 >

Krumelur's tip gave me a good starting point. The DocumentEvents returned by IDocumentListener are granular enough to give me a character by character analysis of what happened.

IEditorPart editor = ...;  
IEditorInput input = editor.getEditorInput();  
IDocument document=(((ITextEditor)editor).getDocumentProvider()).getDocument();

document.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentChanged(DocumentEvent event) 
        {
            System.out.println("Change happened: " + event.toString());
        }

        @Override
        public void documentAboutToBeChanged(DocumentEvent event) {
            System.out.println("I predict that the following change will occur: "+event.toString());


        }
    };
});

就我应该扩展的,我扩展了 org.eclipse.ui .startup ,并添加了一系列的听众,直到我得到的代码看起来像我以上所述。

As far as what I should extend, I extended org.eclipse.ui.startup and added a series of listeners until I got to the code that looks like what I've got above.

我希望这有助于任何其他人正在寻找我是什么。

I hope this helps anybody else who is looking for what I was.

这篇关于Eclipse插件可以精细地监控编辑器的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆