Subscribe to Diff Editor Close Event
Answered
Is it possible to listen to the Diff editor close event?
I am opening a diff editor like this:
DiffManager.getInstance().showDiff(e.getProject(), request);
I need to perform some actions when the diff editor is closed
Thanks
Please sign in to leave a comment.
There are no such API at the moment.
You can try passing `showDiff(..., new DiffDialogHints(... Consumer<WindowWrapper> windowConsumer))` and register `UIUtil.runWhenWindowClosed(wrapper.window, someCallback)` in it.
But there are no guarantee, that windowConsumer will be called at all (ex: there are no IDE window created, external diff tool was spawned instead).
So it shouldn't be used to release resources and similar stuff.
It might be possible to introduce a better way to do this in future releases.
Could you share your use case?
Many thanks for helping. What you suggested is working and I am able to proceed.
We have two very large json files ( over a million files long) which we need to compare. Because of the size of the files, I am generating temporary files which only have the json elements which have changed and showing the diff of those files in the diff editor. However, if the user changes the files in the diff editor the changes now somehow need to be merged back in the original files. For this, I needed an event to be fired when the diff editor is closed.
You can also try to propagate these changes on the fly (as soon as one of the documents is changed), if these large files can be incrementally modified.
Something similar is done in https://github.com/JetBrains/intellij-community/blob/master/platform/diff-impl/src/com/intellij/diff/actions/DocumentFragmentContent.java#L127
It is used, for example, in "Compare [Selection] with Clipboard" action.
Yes, I thought about it but when there are many updates, my approach may perform a bit better.