void (@NotNull AnActionEvent e) { Project project = e.getProject(); if (project != null && myConnection == null) { myConnection = project.getMessageBus().connect(); myConnection.subscribe(XDebuggerManager.TOPIC, new XDebuggerManagerListener() { @Override public void processStarted(@NotNull XDebugProcess debugProcess) { processEvent(debugProcess, true); } @Override public void processStopped(@NotNull XDebugProcess debugProcess) { processEvent(debugProcess, false); } void processEvent(@NotNull XDebugProcess debugProcess, boolean started) { if (debugProcess instanceof JavaDebugProcess) { RemoteConnection connection = ((JavaDebugProcess)debugProcess).getDebuggerSession().getProcess().getConnection(); if (connection instanceof PidRemoteConnection) { if (((PidRemoteConnection)connection).getPid() .equals(String.valueOf(OSProcessUtil.getProcessID(myProcessHandler.getProcess())))) { myAttachedSession.set(started ? debugProcess.getSession() : null); } } } } }); } if (myAttachedSession.get() != null || myProcessHandler.isProcessTerminated()) { e.getPresentation().setEnabled(false); return; } e.getPresentation().setEnabledAndVisible(Boolean.TRUE.equals(myEnabled.get())); }