Any way to determine whether a save was an explicit user action or not?

My custom language plugin reacts to VirtualFileListener.contentsChanged() events to propagate saved files to an external system.  There are many situations where the IDE saves files as a side-effect of another operation, e.g., focus lost (if so configured), settings changed, line status marker marking a file as unchanged, etc.  Because this is pushing data to an external system, I'd really only like to do this when the user explicitly saves (key binding, toolbar button, or menu item) and not as an implicit side-effect of another operation.  Is there any way to detect this?  And I'm not talking about VirtualFileEvent.isFromRefresh() vs. isFromSave().  That takes care of one specific instance of this issue when a file is synced from disk, but it doesn't address all of these other operations.

Along these lines, I'd also like to do this every time the user explicitly requests a save even if the IDE doesn't see the current file as modified.

I've tried reacting to FileDocumentManagerListener.beforeAllDocumentsSaving() and can reconcile the selected text editor and unsaved documents to know whether the user is trying to force save, but unfortunately that event is also fired for all the same implicit side-effect save operations as described above.  I've hit a bit of a wall trying to filter out ones that shouldn't cause the operation.

I imagine I could do most (all?) of this by totally replacing SaveAllAction with my own action and remapping keys, toolbar buttons, and menu items, but that seems like a scary proposition to me.  Is that the only viable way to do this?  Thanks in advance!

2 comments
Comment actions Permalink

Please don't. When working in IntelliJ IDEA, it's perfectly normal to never invoke the Save action manually. If you want to give the user an explicit way to trigger the operation in your system, please make it your own action, and don't tie it to the "Save" button.

0
Comment actions Permalink

Yeah, I found another thread from a few years back on a related topic and the response was similar.  The users of my plugin definitely like the deploy-on-save functionality so I'll just keep it the way it is now and wait for any additional feedback from users on how to evolve it.  For what it's worth, I already have separate actions for incremental and full deployment of the project contents to the external system that are bound to distinct keys and menu items.  The deploy-on-save functionality is just a nice convenience as users are working.  Thanks for the feedback!

0

Please sign in to leave a comment.