Eclipse Plugin to granularly monitor editor changes(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 DocumentEvent
s 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 插件,用于精细监控编辑器更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Eclipse 插件,用于精细监控编辑器更改
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01