2 * Copyright 2000-2009 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
.DefaultExecutionResult
;
20 import com
.intellij
.execution
.ExecutionManager
;
21 import com
.intellij
.execution
.ExecutionResult
;
22 import com
.intellij
.execution
.Executor
;
23 import com
.intellij
.execution
.configurations
.RunProfile
;
24 import com
.intellij
.execution
.executors
.DefaultDebugExecutor
;
25 import com
.intellij
.execution
.process
.ProcessAdapter
;
26 import com
.intellij
.execution
.process
.ProcessEvent
;
27 import com
.intellij
.execution
.process
.ProcessHandler
;
28 import com
.intellij
.execution
.runners
.ExecutionEnvironment
;
29 import com
.intellij
.execution
.runners
.ProgramRunner
;
30 import com
.intellij
.execution
.runners
.RestartAction
;
31 import com
.intellij
.execution
.ui
.*;
32 import com
.intellij
.execution
.ui
.actions
.CloseAction
;
33 import com
.intellij
.execution
.ui
.layout
.PlaceInGrid
;
34 import com
.intellij
.ide
.CommonActionsManager
;
35 import com
.intellij
.ide
.actions
.ContextHelpAction
;
36 import com
.intellij
.openapi
.actionSystem
.*;
37 import com
.intellij
.openapi
.application
.ApplicationManager
;
38 import com
.intellij
.openapi
.project
.Project
;
39 import com
.intellij
.openapi
.wm
.ex
.WindowManagerEx
;
40 import com
.intellij
.ui
.content
.Content
;
41 import com
.intellij
.ui
.content
.tabs
.PinToolwindowTabAction
;
42 import com
.intellij
.xdebugger
.XDebugProcess
;
43 import com
.intellij
.xdebugger
.XDebugSession
;
44 import com
.intellij
.xdebugger
.XDebuggerBundle
;
45 import com
.intellij
.xdebugger
.impl
.XDebugSessionImpl
;
46 import com
.intellij
.xdebugger
.impl
.actions
.XDebuggerActions
;
47 import com
.intellij
.xdebugger
.impl
.frame
.XDebugViewBase
;
48 import com
.intellij
.xdebugger
.impl
.frame
.XFramesView
;
49 import com
.intellij
.xdebugger
.impl
.frame
.XVariablesView
;
50 import com
.intellij
.xdebugger
.impl
.frame
.XWatchesView
;
51 import org
.jetbrains
.annotations
.NotNull
;
52 import org
.jetbrains
.annotations
.Nullable
;
54 import java
.util
.ArrayList
;
55 import java
.util
.Collection
;
56 import java
.util
.List
;
61 public class XDebugSessionTab
extends DebuggerLogConsoleManagerBase
{
62 private final String mySessionName
;
63 private final RunnerLayoutUi myUi
;
64 private RunContentDescriptor myRunContentDescriptor
;
65 private ExecutionConsole myConsole
;
66 private XWatchesView myWatchesView
;
67 private final List
<XDebugViewBase
> myViews
= new ArrayList
<XDebugViewBase
>();
69 public XDebugSessionTab(@NotNull final Project project
, @NotNull final String sessionName
) {
71 mySessionName
= sessionName
;
73 myUi
= RunnerLayoutUi
.Factory
.getInstance(project
).create("Debug", "unknown!", sessionName
, this);
74 myUi
.getDefaults().initTabDefaults(0, "Debug", null);
76 myUi
.getOptions().setTopToolbar(createTopToolbar(), ActionPlaces
.DEBUGGER_TOOLBAR
);
79 private Content
createConsoleContent() {
80 return myUi
.createContent(DebuggerContentInfo
.CONSOLE_CONTENT
, myConsole
.getComponent(),
81 XDebuggerBundle
.message("debugger.session.tab.console.content.name"), XDebuggerUIConstants
.CONSOLE_TAB_ICON
,
82 myConsole
.getPreferredFocusableComponent());
85 private Content
createVariablesContent(final XDebugSession session
) {
86 final XVariablesView variablesView
= new XVariablesView(session
, this);
87 myViews
.add(variablesView
);
88 return myUi
.createContent(DebuggerContentInfo
.VARIABLES_CONTENT
, variablesView
.getPanel(),
89 XDebuggerBundle
.message("debugger.session.tab.variables.title"), XDebuggerUIConstants
.VARIABLES_TAB_ICON
, null);
92 private Content
createWatchesContent(final XDebugSession session
, final XDebugSessionData sessionData
) {
93 myWatchesView
= new XWatchesView(session
, this, sessionData
);
94 myViews
.add(myWatchesView
);
95 Content watchesContent
= myUi
.createContent(DebuggerContentInfo
.WATCHES_CONTENT
, myWatchesView
.getMainPanel(),
96 XDebuggerBundle
.message("debugger.session.tab.watches.title"), XDebuggerUIConstants
.WATCHES_TAB_ICON
, null);
98 ActionGroup group
= (ActionGroup
)ActionManager
.getInstance().getAction(XDebuggerActions
.WATCHES_TREE_TOOLBAR_GROUP
);
99 watchesContent
.setActions(group
, ActionPlaces
.DEBUGGER_TOOLBAR
, myWatchesView
.getTree());
100 return watchesContent
;
103 private Content
createFramesContent(final XDebugSession session
) {
104 final XFramesView framesView
= new XFramesView(session
, this);
105 myViews
.add(framesView
);
106 Content framesContent
= myUi
.createContent(DebuggerContentInfo
.FRAME_CONTENT
, framesView
.getMainPanel(),
107 XDebuggerBundle
.message("debugger.session.tab.frames.title"), XDebuggerUIConstants
.FRAMES_TAB_ICON
, null);
108 final DefaultActionGroup framesGroup
= new DefaultActionGroup();
110 CommonActionsManager actionsManager
= CommonActionsManager
.getInstance();
111 framesGroup
.add(actionsManager
.createPrevOccurenceAction(framesView
.getFramesList()));
112 framesGroup
.add(actionsManager
.createNextOccurenceAction(framesView
.getFramesList()));
114 framesContent
.setActions(framesGroup
, ActionPlaces
.DEBUGGER_TOOLBAR
, framesView
.getFramesList());
115 return framesContent
;
118 private static DefaultActionGroup
createTopToolbar() {
119 DefaultActionGroup stepping
= new DefaultActionGroup();
120 ActionManager actionManager
= ActionManager
.getInstance();
121 stepping
.add(actionManager
.getAction(XDebuggerActions
.SHOW_EXECUTION_POINT
));
122 stepping
.addSeparator();
123 stepping
.add(actionManager
.getAction(XDebuggerActions
.STEP_OVER
));
124 stepping
.add(actionManager
.getAction(XDebuggerActions
.STEP_INTO
));
125 stepping
.add(actionManager
.getAction(XDebuggerActions
.FORCE_STEP_INTO
));
126 stepping
.add(actionManager
.getAction(XDebuggerActions
.STEP_OUT
));
127 stepping
.addSeparator();
128 stepping
.add(actionManager
.getAction(XDebuggerActions
.RUN_TO_CURSOR
));
132 public XDebugSessionData
saveData() {
133 final List
<String
> watchExpressions
= myWatchesView
.getWatchExpressions();
134 return new XDebugSessionData(watchExpressions
.toArray(new String
[watchExpressions
.size()]));
137 public ExecutionConsole
getConsole() {
141 public String
getSessionName() {
142 return mySessionName
;
145 public void rebuildViews() {
146 for (XDebugViewBase view
: myViews
) {
151 public RunContentDescriptor
attachToSession(final @NotNull XDebugSession session
, final @Nullable ProgramRunner runner
,
152 final @Nullable ExecutionEnvironment env
,
153 final @NotNull XDebugSessionData sessionData
) {
154 return initUI(session
, sessionData
, env
, runner
);
158 private static ExecutionResult
createExecutionResult(@NotNull final XDebugSession session
) {
159 final XDebugProcess debugProcess
= session
.getDebugProcess();
160 ProcessHandler processHandler
= debugProcess
.getProcessHandler();
161 processHandler
.addProcessListener(new ProcessAdapter() {
162 public void processTerminated(final ProcessEvent event
) {
163 ((XDebugSessionImpl
)session
).stopImpl();
166 return new DefaultExecutionResult(debugProcess
.createConsole(), processHandler
);
169 public XWatchesView
getWatchesView() {
170 return myWatchesView
;
173 private RunContentDescriptor
initUI(final @NotNull XDebugSession session
, final @NotNull XDebugSessionData sessionData
,
174 final @Nullable ExecutionEnvironment environment
, final @Nullable ProgramRunner runner
) {
175 ExecutionResult executionResult
= createExecutionResult(session
);
176 myConsole
= executionResult
.getExecutionConsole();
178 myUi
.addContent(createFramesContent(session
), 0, PlaceInGrid
.left
, false);
179 myUi
.addContent(createVariablesContent(session
), 0, PlaceInGrid
.center
, false);
180 myUi
.addContent(createWatchesContent(session
, sessionData
), 0, PlaceInGrid
.right
, false);
181 final Content consoleContent
= createConsoleContent();
182 myUi
.addContent(consoleContent
, 1, PlaceInGrid
.bottom
, false);
183 if (myConsole
instanceof ObservableConsoleView
) {
184 ObservableConsoleView observable
= (ObservableConsoleView
)myConsole
;
185 observable
.addChangeListener(new ObservableConsoleView
.ChangeListener() {
186 public void contentAdded(final Collection
<ConsoleViewContentType
> types
) {
187 if (types
.contains(ConsoleViewContentType
.ERROR_OUTPUT
) || types
.contains(ConsoleViewContentType
.SYSTEM_OUTPUT
)) {
188 consoleContent
.fireAlert();
195 myRunContentDescriptor
= new RunContentDescriptor(myConsole
, executionResult
.getProcessHandler(), myUi
.getComponent(), getSessionName());
197 if (ApplicationManager
.getApplication().isUnitTestMode()) {
198 return myRunContentDescriptor
;
201 DefaultActionGroup group
= new DefaultActionGroup();
202 final Executor executor
= DefaultDebugExecutor
.getDebugExecutorInstance();
203 if (runner
!= null && environment
!= null) {
204 RestartAction restarAction
= new RestartAction(executor
, runner
, myRunContentDescriptor
.getProcessHandler(), XDebuggerUIConstants
.DEBUG_AGAIN_ICON
,
205 myRunContentDescriptor
, environment
);
206 group
.add(restarAction
);
207 restarAction
.registerShortcut(myUi
.getComponent());
210 addActionToGroup(group
, XDebuggerActions
.RESUME
);
211 addActionToGroup(group
, XDebuggerActions
.PAUSE
);
212 addActionToGroup(group
, IdeActions
.ACTION_STOP_PROGRAM
);
214 group
.addSeparator();
216 addActionToGroup(group
, XDebuggerActions
.VIEW_BREAKPOINTS
);
217 addActionToGroup(group
, XDebuggerActions
.MUTE_BREAKPOINTS
);
219 group
.addSeparator();
220 //addAction(group, DebuggerActions.EXPORT_THREADS);
221 group
.addSeparator();
223 group
.add(myUi
.getOptions().getLayoutActions());
225 group
.addSeparator();
227 group
.add(PinToolwindowTabAction
.getPinAction());
228 group
.add(new CloseAction(executor
, myRunContentDescriptor
, getProject()));
229 group
.add(new ContextHelpAction(executor
.getHelpId()));
231 myUi
.getOptions().setLeftToolbar(group
, ActionPlaces
.DEBUGGER_TOOLBAR
);
233 if (environment
!= null) {
234 final RunProfile runConfiguration
= environment
.getRunProfile();
235 registerFileMatcher(runConfiguration
);
236 initLogConsoles(runConfiguration
, myRunContentDescriptor
.getProcessHandler());
241 return myRunContentDescriptor
;
244 private static void addActionToGroup(final DefaultActionGroup group
, final String actionId
) {
245 AnAction action
= ActionManager
.getInstance().getAction(actionId
);
246 if (action
!= null) group
.add(action
);
249 public RunnerLayoutUi
getUi() {
254 public RunContentDescriptor
getRunContentDescriptor() {
255 return myRunContentDescriptor
;
258 public void toFront() {
259 ApplicationManager
.getApplication().invokeLater(new Runnable() {
261 WindowManagerEx
.getInstanceEx().getFrame(getProject()).toFront();
262 ExecutionManager
.getInstance(getProject()).getContentManager().toFrontRunContent(DefaultDebugExecutor
.getDebugExecutorInstance(), myRunContentDescriptor
);