Title: [184971] trunk/Source/WebInspectorUI
Revision
184971
Author
[email protected]
Date
2015-05-28 17:20:40 -0700 (Thu, 28 May 2015)

Log Message

Web Inspector: NewTabContentView should update button disabled state as other tabs are added/removed
https://bugs.webkit.org/show_bug.cgi?id=145448

Patch by Joseph Pecoraro <[email protected]> on 2015-05-28
Reviewed by Timothy Hatcher.

* UserInterface/Views/NewTabContentView.js:
(WebInspector.NewTabContentView):
Always add a click listener and add the type as a private property on the element.

(WebInspector.NewTabContentView.prototype.shown):
(WebInspector.NewTabContentView.prototype.hidden):
Add / remove event listeners for tab changes. Also update the view when shown.

(WebInspector.NewTabContentView.prototype._createNewTab):
A disabled button an now be clicked. Do nothing if a new tab of this type is not allowed.

(WebInspector.NewTabContentView.prototype._updateTabItems):
Refresh the disabled state for each of the buttons.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (184970 => 184971)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-05-29 00:15:24 UTC (rev 184970)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-05-29 00:20:40 UTC (rev 184971)
@@ -1,3 +1,24 @@
+2015-05-28  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: NewTabContentView should update button disabled state as other tabs are added/removed
+        https://bugs.webkit.org/show_bug.cgi?id=145448
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/NewTabContentView.js:
+        (WebInspector.NewTabContentView):
+        Always add a click listener and add the type as a private property on the element.
+
+        (WebInspector.NewTabContentView.prototype.shown):
+        (WebInspector.NewTabContentView.prototype.hidden):
+        Add / remove event listeners for tab changes. Also update the view when shown.
+        
+        (WebInspector.NewTabContentView.prototype._createNewTab):
+        A disabled button an now be clicked. Do nothing if a new tab of this type is not allowed.
+
+        (WebInspector.NewTabContentView.prototype._updateTabItems):
+        Refresh the disabled state for each of the buttons.
+
 2015-05-27  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Show Page Source does not switch to Resources tab if inspector was closed

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/NewTabContentView.js (184970 => 184971)


--- trunk/Source/WebInspectorUI/UserInterface/Views/NewTabContentView.js	2015-05-29 00:15:24 UTC (rev 184970)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/NewTabContentView.js	2015-05-29 00:20:40 UTC (rev 184971)
@@ -43,13 +43,10 @@
             continue;
 
         var tabItemElement = document.createElement("div");
-        tabItemElement.classList.add("tab-item");
+        tabItemElement.classList.add(WebInspector.NewTabContentView.TabItemStyleClassName);
+        tabItemElement.addEventListener("click", this._createNewTab.bind(this, info.type));
+        tabItemElement[WebInspector.NewTabContentView.TypeSymbol] = info.type;
 
-        if (WebInspector.isNewTabWithTypeAllowed(info.type))
-            tabItemElement.addEventListener("click", this._createNewTab.bind(this, info.type));
-        else
-            tabItemElement.classList.add("disabled");
-
         var boxElement = tabItemElement.appendChild(document.createElement("div"));
         boxElement.classList.add("box");
 
@@ -74,12 +71,42 @@
         return WebInspector.NewTabContentView.Type;
     },
 
+    shown()
+    {
+        WebInspector.tabBrowser.tabBar.addEventListener(WebInspector.TabBar.Event.TabBarItemAdded, this._updateTabItems, this);
+        WebInspector.tabBrowser.tabBar.addEventListener(WebInspector.TabBar.Event.TabBarItemRemoved, this._updateTabItems, this);
+
+        this._updateTabItems();
+    },
+
+    hidden()
+    {
+        WebInspector.tabBrowser.tabBar.removeEventListener(null, null, this);
+    },
+
     // Private
 
-    _createNewTab: function(tabType, event)
+    _createNewTab(tabType, event)
     {
+        if (!WebInspector.isNewTabWithTypeAllowed(tabType))
+            return;
+
         WebInspector.createNewTab(tabType, this);
+    },
+
+    _updateTabItems()
+    {
+        var tabItemElements = Array.from(this.element.querySelectorAll("." + WebInspector.NewTabContentView.TabItemStyleClassName));
+        for (var tabItemElement of tabItemElements) {
+            var type = tabItemElement[WebInspector.NewTabContentView.TypeSymbol];
+            var allowed = WebInspector.isNewTabWithTypeAllowed(type);
+            tabItemElement.classList.toggle(WebInspector.NewTabContentView.DisabledStyleClassName, !allowed);
+        }
     }
 };
 
 WebInspector.NewTabContentView.Type = "new-tab";
+WebInspector.NewTabContentView.TypeSymbol = Symbol("type");
+
+WebInspector.NewTabContentView.TabItemStyleClassName = "tab-item";
+WebInspector.NewTabContentView.DisabledStyleClassName = "disabled";
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to