Chromium Code Reviews| Index: Source/devtools/front_end/sources/TargetsToolbar.js |
| diff --git a/Source/devtools/front_end/sources/TargetsToolbar.js b/Source/devtools/front_end/sources/TargetsToolbar.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e57842f079edc15358bf16559e83349e38075bc8 |
| --- /dev/null |
| +++ b/Source/devtools/front_end/sources/TargetsToolbar.js |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @constructor |
| + * @implements {WebInspector.TargetManager.Observer} |
| + */ |
| +WebInspector.TargetsToolbar = function() |
| +{ |
| + this.element = document.createElement("div"); |
| + this.element.className = "status-bar scripts-debug-toolbar threads-toolbar hidden"; |
|
vsevik
2014/06/18 12:41:32
targets-toolbar
sergeyv
2014/06/18 16:50:08
Done.
|
| + this._comboBox = new WebInspector.StatusBarComboBox(this._onComboBoxSelectionChange.bind(this)); |
| + this.element.appendChild(this._comboBox.element); |
| + |
| + /** @type {!Map.<!WebInspector.Target, !Element>} */ |
| + this._targetToOption = new Map(); |
| + if (!WebInspector.experimentsSettings.workersInMainWindow.isEnabled()) |
| + return; |
| + |
| + WebInspector.executionContextSelector.addTargetChangeListener(this._targetChangedExternally, this); |
| + WebInspector.targetManager.observeTargets(this); |
| +} |
| + |
| +WebInspector.TargetsToolbar.prototype = { |
| + |
| + /** |
| + * @param {!WebInspector.Target} target |
| + */ |
| + targetAdded: function(target) |
| + { |
| + var option = this._comboBox.createOption(target.name()); |
| + option.__target = target; |
| + this._targetToOption.put(target, option); |
| + if (WebInspector.executionContextSelector.currentTarget() === target) |
| + this._comboBox.select(option); |
| + |
| + this._alterVisibility(); |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.Target} target |
| + */ |
| + targetRemoved: function(target) |
| + { |
| + var option = this._targetToOption.remove(target); |
| + this._comboBox.removeOption(option); |
| + this._alterVisibility(); |
| + }, |
| + |
| + _onComboBoxSelectionChange: function() |
| + { |
| + var selectedOption = this._comboBox.selectedOption(); |
| + if (!selectedOption) |
| + return; |
| + |
| + WebInspector.executionContextSelector.setCurrentTarget(selectedOption.__target); |
| + }, |
| + |
| + _alterVisibility: function() |
| + { |
| + var hidden = this._comboBox.size() === 1; |
| + this.element.classList.toggle("hidden", hidden); |
| + }, |
| + |
| + /** |
| + * @param {?WebInspector.Target} target |
| + */ |
| + _targetChangedExternally: function(target) |
| + { |
| + if (target) { |
| + var option = /** @type {!Element} */ (this._targetToOption.get(target)) |
| + this._comboBox.select(option); |
| + } |
| + } |
| + |
| +} |