void () { // 1. load default touchbar actions for all opened projects for (Project project : ProjectUtil.getOpenProjects()) { registerTouchbarActions(project); } // 2. listen for projects ourConnection = ApplicationManager.getApplication().getMessageBus().simpleConnect(); ourConnection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() { @Override public void projectOpened(@NotNull Project project) { registerTouchbarActions(project); } @Override public void projectClosed(@NotNull Project project) { LOG.debug("closed project: %s", project); final JFrame frame = WindowManager.getInstance().getFrame(project); if (frame == null) { // can be when frame is closing (and project is disposing) LOG.debug("null frame for project: %s", project); return; } TouchBarsManager.unregister(frame); // remove project-default action group } }); // 3. schedule to collect run/debug actions fillRunDebugGroup(); }