void () { if (myConnection == null) { myDisposable = Disposer.newDisposable(); Disposer.register(myProject, myDisposable); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(myListener, myDisposable); myConnection = ApplicationManager.getApplication().getMessageBus().connect(myProject); myConnection.subscribe(FileDocumentManagerListener.TOPIC, new FileDocumentManagerListener() { @Override public void beforeAllDocumentsSaving() { myDocumentSavingInProgress = true; ApplicationManager.getApplication().invokeLater(() -> myDocumentSavingInProgress = false, ModalityState.any()); } }); myConnection.subscribe(LookupManagerListener.TOPIC, new LookupManagerListener() { @Override public void activeLookupChanged(@Nullable Lookup oldLookup, @Nullable Lookup newLookup) { if (newLookup == null && !myChangedFiles.isEmpty()) { myAlarm.cancelAndRequest(); } } }); myAlarm = new SingleAlarm(new MyRunnable(), myDelayMillis, Alarm.ThreadToUse.SWING_THREAD, myDisposable); } }