1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * @extends {WebInspector.SidebarPane}
8 * @implements {WebInspector.TargetManager.Observer}
10 WebInspector.ThreadsSidebarPane = function()
12 WebInspector.SidebarPane.call(this, WebInspector.UIString("Threads"));
13 this.setVisible(false);
15 /** @type {!Map.<!WebInspector.DebuggerModel, !WebInspector.UIList.Item>} */
16 this._debuggerModelToListItems = new Map();
17 /** @type {!Map.<!WebInspector.UIList.Item, !WebInspector.Target>} */
18 this._listItemsToTargets = new Map();
19 /** @type {?WebInspector.UIList.Item} */
20 this._selectedListItem = null;
21 this.threadList = new WebInspector.UIList();
22 this.threadList.show(this.element);
23 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerPaused, this._onDebuggerStateChanged, this);
24 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerResumed, this._onDebuggerStateChanged, this);
25 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._targetChanged, this);
26 WebInspector.targetManager.observeTargets(this);
29 WebInspector.ThreadsSidebarPane.prototype = {
32 * @param {!WebInspector.Target} target
34 targetAdded: function(target)
36 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target)
38 this._updateVisibility();
41 var listItem = new WebInspector.UIList.Item(target.name(), "");
42 listItem.element.addEventListener("click", this._onListItemClick.bind(this, listItem), false);
43 var currentTarget = WebInspector.context.flavor(WebInspector.Target);
44 if (currentTarget === target)
45 this._selectListItem(listItem);
47 this._debuggerModelToListItems.set(debuggerModel, listItem);
48 this._listItemsToTargets.set(listItem, target);
49 this.threadList.addItem(listItem);
50 this._updateDebuggerState(debuggerModel);
51 this._updateVisibility();
54 _updateVisibility: function()
56 this._wasVisibleAtLeastOnce = this._wasVisibleAtLeastOnce || this._debuggerModelToListItems.size > 1;
57 this.setVisible(this._wasVisibleAtLeastOnce);
62 * @param {!WebInspector.Target} target
64 targetRemoved: function(target)
66 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target)
69 var listItem = this._debuggerModelToListItems.remove(debuggerModel);
71 this._listItemsToTargets.remove(listItem);
72 this.threadList.removeItem(listItem);
74 this._updateVisibility();
78 * @param {!WebInspector.Event} event
80 _targetChanged: function(event)
82 var newTarget = /** @type {!WebInspector.Target} */(event.data);
83 var debuggerModel = WebInspector.DebuggerModel.fromTarget(newTarget)
86 var listItem = /** @type {!WebInspector.UIList.Item} */ (this._debuggerModelToListItems.get(debuggerModel));
87 this._selectListItem(listItem);
91 * @param {!WebInspector.Event} event
93 _onDebuggerStateChanged: function(event)
95 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.target);
96 this._updateDebuggerState(debuggerModel);
100 * @param {!WebInspector.DebuggerModel} debuggerModel
102 _updateDebuggerState: function(debuggerModel)
104 var listItem = this._debuggerModelToListItems.get(debuggerModel);
105 listItem.setSubtitle(WebInspector.UIString(debuggerModel.isPaused() ? "paused" : ""));
109 * @param {!WebInspector.UIList.Item} listItem
111 _selectListItem: function(listItem)
113 if (listItem === this._selectedListItem)
116 if (this._selectedListItem)
117 this._selectedListItem.setSelected(false);
119 this._selectedListItem = listItem;
120 listItem.setSelected(true);
124 * @param {!WebInspector.UIList.Item} listItem
126 _onListItemClick: function(listItem)
128 WebInspector.context.setFlavor(WebInspector.Target, this._listItemsToTargets.get(listItem));
129 listItem.element.scrollIntoViewIfNeeded();
133 __proto__: WebInspector.SidebarPane.prototype