void () { myConsole.getProject().getMessageBus().connect(myConsole).subscribe(FileDocumentManagerListener.TOPIC, new FileDocumentManagerListener() { @Override public void beforeDocumentSaving(@NotNull Document document) { if (document == myConsole.getEditorDocument()) { saveHistory(); } } }); ConsoleHistoryController original = ControllerRegistry.getInstance().controllers.put(myConsole, this); LOG.assertTrue(original == null, "History controller already installed for: " + myConsole.getTitle()); Disposer.register(myConsole, this); Disposer.register(this, new Disposable() { @Override public void dispose() { ConsoleHistoryController controller = getController(myConsole); if (controller == ConsoleHistoryController.this) { ControllerRegistry controllerRegistry = ApplicationManager.getApplication().getServiceIfCreated(ControllerRegistry.class); if (controllerRegistry != null) { controllerRegistry.controllers.remove(myConsole); } } saveHistory(); } }); if (myHelper.getModel().getHistorySize() == 0) { loadHistory(myHelper.getId()); } configureActions(); myLastSaveStamp = getCurrentTimeStamp(); }