2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.xdebugger.impl.ui;
18 import com.intellij.debugger.ui.DebuggerContentInfo;
19 import com.intellij.execution.ExecutionManager;
20 import com.intellij.execution.configurations.RunConfigurationBase;
21 import com.intellij.execution.configurations.RunProfile;
22 import com.intellij.execution.executors.DefaultDebugExecutor;
23 import com.intellij.execution.runners.RunContentBuilder;
24 import com.intellij.execution.runners.RunTab;
25 import com.intellij.execution.ui.ConsoleViewContentType;
26 import com.intellij.execution.ui.ExecutionConsole;
27 import com.intellij.execution.ui.ObservableConsoleView;
28 import com.intellij.execution.ui.layout.LayoutAttractionPolicy;
29 import com.intellij.execution.ui.layout.LayoutViewOptions;
30 import com.intellij.ide.impl.ProjectUtil;
31 import com.intellij.ide.ui.customization.CustomActionsSchema;
32 import com.intellij.openapi.actionSystem.ActionGroup;
33 import com.intellij.openapi.application.ApplicationManager;
34 import com.intellij.openapi.project.Project;
35 import com.intellij.openapi.util.registry.Registry;
36 import com.intellij.openapi.wm.ToolWindow;
37 import com.intellij.psi.search.GlobalSearchScope;
38 import com.intellij.ui.AppIcon;
39 import com.intellij.ui.content.Content;
40 import com.intellij.ui.content.ContentManager;
41 import com.intellij.util.ArrayUtil;
42 import com.intellij.util.ui.UIUtil;
43 import com.intellij.xdebugger.XDebuggerBundle;
44 import org.jetbrains.annotations.NotNull;
45 import org.jetbrains.annotations.Nullable;
47 import java.util.Collection;
52 public abstract class DebuggerSessionTabBase extends RunTab {
53 protected ExecutionConsole myConsole;
55 public DebuggerSessionTabBase(@NotNull Project project, @NotNull String runnerId, @NotNull String sessionName, @NotNull GlobalSearchScope searchScope) {
56 super(project, searchScope, runnerId, XDebuggerBundle.message("xdebugger.default.content.title"), sessionName);
59 .initTabDefaults(0, XDebuggerBundle.message("xdebugger.debugger.tab.title"), null)
60 .initFocusContent(DebuggerContentInfo.FRAME_CONTENT, XDebuggerUIConstants.LAYOUT_VIEW_BREAKPOINT_CONDITION)
61 .initFocusContent(DebuggerContentInfo.CONSOLE_CONTENT, LayoutViewOptions.STARTUP, new LayoutAttractionPolicy.FocusOnce(false));
64 protected static ActionGroup getCustomizedActionGroup(final String id) {
65 return (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(id);
68 protected void attachNotificationTo(final Content content) {
69 if (myConsole instanceof ObservableConsoleView) {
70 ObservableConsoleView observable = (ObservableConsoleView)myConsole;
71 observable.addChangeListener(new ObservableConsoleView.ChangeListener() {
73 public void contentAdded(final Collection<ConsoleViewContentType> types) {
74 if (types.contains(ConsoleViewContentType.ERROR_OUTPUT) || types.contains(ConsoleViewContentType.NORMAL_OUTPUT)) {
79 RunProfile profile = getRunProfile();
80 if (profile instanceof RunConfigurationBase && !ApplicationManager.getApplication().isUnitTestMode()) {
81 observable.addChangeListener(new RunContentBuilder.ConsoleToFrontListener((RunConfigurationBase)profile,
83 DefaultDebugExecutor.getDebugExecutorInstance(),
84 myRunContentDescriptor,
92 protected RunProfile getRunProfile() {
93 return myEnvironment != null ? myEnvironment.getRunProfile() : null;
97 public void select() {
98 if (ApplicationManager.getApplication().isUnitTestMode()) return;
100 UIUtil.invokeLaterIfNeeded(new Runnable() {
103 if (myRunContentDescriptor != null) {
104 ToolWindow toolWindow = ExecutionManager.getInstance(myProject).getContentManager()
105 .getToolWindowByDescriptor(myRunContentDescriptor);
106 Content content = myRunContentDescriptor.getAttachedContent();
107 if (toolWindow == null || content == null) return;
108 ContentManager manager = toolWindow.getContentManager();
109 if (ArrayUtil.contains(content, manager.getContents()) && !manager.isSelected(content)) {
110 manager.setSelectedContent(content);
117 public void toFront(boolean focus, @Nullable final Runnable onShowCallback) {
118 if (ApplicationManager.getApplication().isUnitTestMode()) return;
120 ApplicationManager.getApplication().invokeLater(new Runnable() {
123 if (myRunContentDescriptor != null) {
124 ToolWindow toolWindow = ExecutionManager.getInstance(myProject).getContentManager()
125 .getToolWindowByDescriptor(myRunContentDescriptor);
126 if (toolWindow != null) {
127 if (!toolWindow.isVisible()) {
128 toolWindow.show(onShowCallback);
130 //noinspection ConstantConditions
131 toolWindow.getContentManager().setSelectedContent(myRunContentDescriptor.getAttachedContent());
138 ApplicationManager.getApplication().invokeLater(new Runnable() {
141 boolean focusWnd = Registry.is("debugger.mayBringFrameToFrontOnBreakpoint");
142 ProjectUtil.focusProjectWindow(myProject, focusWnd);
144 AppIcon.getInstance().requestAttention(myProject, true);