如何在 Eclipse 中添加 Ctrl+S 事件的钩子?
每当我在 Eclipse 中按 Ctrl + S 来保存源代码时,我希望 shell 上的一些自定义 CMD 在我的 CentOS 主机上运行。我怎样才能做到这一点?
Whenever I press Ctrl + S in eclipse to save source code I want some custom CMD on shell to run on my CentOS host. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最好的选择是向您的项目添加外部构建器。您可以选择使用您选择的参数运行 ant 脚本或任意程序(如 /bin/bash)。每次保存项目资源(如文件)时,您的构建器都会运行。请参阅 Ant项目构建者 有关外部构建者的讨论。
Java 编辑器具有可以激活和自定义的保存操作,但据我所知,它们不包括运行程序的功能。请参阅
首选项>爪哇>编辑器
。如果您会编写插件,还可以向 org.eclipse.ui.commands.ICommandService 添加一个 org.eclipse.core.commands.IExecutionListener 并监听 Save命令(
org.eclipse.ui.IWorkbenchCommandConstants.FILE_SAVE
)。然后你就可以做任何你能用java编写的事情了。但外部项目构建者可能是实现您想要的最快方法。Your best bet is to add an external builder to your project. You can choose to run an ant script or an arbitrary program (like /bin/bash) with arguments of your choice. Every time a project resource is saved (like a file) your builder will be run. See Ant Project Builders for a discussion on external builders.
The Java Editor has Save Actions that can be activated and customized, but AFAIK they don't include the ability to run a program. See
Preferences > Java > Editors
.If you can write plugins, you can also add an
org.eclipse.core.commands.IExecutionListener
to theorg.eclipse.ui.commands.ICommandService
and listen for the Save command (org.eclipse.ui.IWorkbenchCommandConstants.FILE_SAVE
). Then you can do anything that you can write in java. But the external project builders are probably the fastest way to what you want.假设您是 Eclipse 中的 Java...不。
Java 本身无法挂钩键盘或鼠标。注册密钥的唯一方法是当 java 应用程序获得焦点时。
C 或 C++ 是使用 hooks 的方法。
您可以搜索包装 C/C++ 挂钩的 Java 包装器。这确实是唯一的办法。
Assuming you're Java in Eclipse... no.
Java natively can't hook keyboards or mouses. The only way to register keys is when the java app is focused.
C or C++ is the way to go for hooks.
You could do some searching for a Java wrapper that wraps a C/C++ hook. That's the only way really.
确切的答案是不可能的......但你可以实现类似的目标。
您将需要安装和配置 CI 服务器 来经常轮询存储库更改并在每次提交时执行。
您可以在 eclipse Key pref 页面上提供“commit”的快捷键,因此您可以在 Ctrl+S 之后立即使用它。
有一个 适用于 Jenkins 的 XShell 插件,您可能会发现它对您的脚本编写很有用。
The exact answer is that is not possible...but you can achieve sth similar.
Yo will need to install and configure a CI server to poll for repository changes often and execute on every commit.
You can provide a key shortcut for "commit" on the eclipse Key pref page, so you might use it right after Ctrl+S
There is a XShell plugin for Jenkins which you may find useful for your scripting.