Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a hook for Ctrl+S event in eclipse?

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?

like image 470
Mr Coder Avatar asked Nov 14 '11 13:11

Mr Coder


1 Answers

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 the org.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.

like image 62
Paul Webster Avatar answered Sep 21 '22 05:09

Paul Webster