package jetbrains.mps.debugger.api.ui;
/*Generated by MPS */
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.debug.api.AbstractDebugSession;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import jetbrains.mps.debug.api.evaluation.IEvaluationProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.execution.ui.RunContentManager;
import jetbrains.mps.debug.api.DebugSessionManagerComponent;
import com.intellij.execution.ExecutionManager;
import com.intellij.execution.executors.DefaultDebugExecutor;
public class DebugActionsUtil {
public DebugActionsUtil() {
}
@Nullable
public static AbstractDebugSession getDebugSession(AnActionEvent event) {
DataContext dataContext = event.getDataContext();
return DebugActionsUtil.getDebugSession(dataContext);
}
@Nullable
public static IEvaluationProvider getEvaluationProvider(AnActionEvent event) {
AbstractDebugSession debugSession = DebugActionsUtil.getDebugSession(event);
if (debugSession != null) {
return debugSession.getEvaluationProvider();
}
return null;
}
@Nullable
public static AbstractDebugSession getDebugSession(DataContext dataContext) {
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return null;
}
RunContentDescriptor runContentDescriptor = RunContentManager.RUN_CONTENT_DESCRIPTOR.getData(dataContext);
if (runContentDescriptor != null) {
// tool window
return DebugSessionManagerComponent.getInstance(project).getDebugSession(runContentDescriptor.getProcessHandler());
}
// main menu
RunContentDescriptor selectedContent = ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
if (selectedContent == null) {
// when Debug is first started for the first time, the debug tool window is shown but not activated
// here we deal with this situation
selectedContent = ExecutionManager.getInstance(project).getContentManager().getSelectedContent(DefaultDebugExecutor.getDebugExecutorInstance());
if (selectedContent == null) {
return null;
}
}
return DebugSessionManagerComponent.getInstance(project).getDebugSession(selectedContent.getProcessHandler());
}
}