Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(909)

Unified Diff: Source/devtools/front_end/sources/TargetsToolbar.js

Issue 338283004: DevTools: Use TargetsToolbar instead of ThreadToolbar (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address vsevik's comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5b0a4a9db1fc530fce59aed57ca8a63b482062f3
--- /dev/null
+++ b/Source/devtools/front_end/sources/TargetsToolbar.js
@@ -0,0 +1,78 @@
+// 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 targets-toolbar hidden";
+ 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.context.addFlavorChangeListener(WebInspector.Target, 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.context.flavor(WebInspector.Target) === target)
+ this._comboBox.select(option);
+
+ this._updateVisibility();
+ },
+
+ /**
+ * @param {!WebInspector.Target} target
+ */
+ targetRemoved: function(target)
+ {
+ var option = this._targetToOption.remove(target);
+ this._comboBox.removeOption(option);
+ this._updateVisibility();
+ },
+
+ _onComboBoxSelectionChange: function()
+ {
+ var selectedOption = this._comboBox.selectedOption();
+ if (!selectedOption)
+ return;
+
+ WebInspector.context.setFlavor(WebInspector.Target, selectedOption.__target);
+ },
+
+ _updateVisibility: function()
+ {
+ var hidden = this._comboBox.size() === 1;
+ this.element.classList.toggle("hidden", hidden);
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _targetChangedExternally: function(event)
+ {
+ var target = /** @type {?WebInspector.Target} */ (event.data);
+ if (target) {
+ var option = /** @type {!Element} */ (this._targetToOption.get(target));
+ this._comboBox.select(option);
+ }
+ }
+
+}
« no previous file with comments | « Source/devtools/front_end/sources/SourcesPanel.js ('k') | Source/devtools/front_end/sources/ThreadsToolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698