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!