Title: [211064] trunk/Source/WebInspectorUI
Revision
211064
Author
[email protected]
Date
2017-01-23 15:06:26 -0800 (Mon, 23 Jan 2017)

Log Message

Web Inspector: long press on New Tab Tab Item should show context menu with recently closed tabs that are still closed
https://bugs.webkit.org/show_bug.cgi?id=166901

Patch by Devin Rousso <[email protected]> on 2017-01-23
Reviewed by Joseph Pecoraro.

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Views/TabBar.js:
(WebInspector.TabBar.Event):
(WebInspector.TabBar.prototype._handleNewTabContextMenu):
Add listener dispatch for contextmenu event on New Tab tab item.

(WebInspector.TabBar.prototype.get newTabTabBarItem): Deleted.
Unused.

* UserInterface/Views/TabBrowser.js:
(WebInspector.TabBrowser):
(WebInspector.TabBrowser.prototype._tabBarItemAdded):
(WebInspector.TabBrowser.prototype._tabBarItemRemoved):
(WebInspector.TabBrowser.prototype._handleNewTabContextMenu): Added.
Create an array that keeps track of tabs as they are closed, and populate the contextmenu
of the New Tab tab item with entries for each of these tabs.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (211063 => 211064)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-01-23 22:49:26 UTC (rev 211063)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-01-23 23:06:26 UTC (rev 211064)
@@ -1,5 +1,29 @@
 2017-01-23  Devin Rousso  <[email protected]>
 
+        Web Inspector: long press on New Tab Tab Item should show context menu with recently closed tabs that are still closed
+        https://bugs.webkit.org/show_bug.cgi?id=166901
+
+        Reviewed by Joseph Pecoraro.
+
+        * Localizations/en.lproj/localizedStrings.js:
+        * UserInterface/Views/TabBar.js:
+        (WebInspector.TabBar.Event):
+        (WebInspector.TabBar.prototype._handleNewTabContextMenu):
+        Add listener dispatch for contextmenu event on New Tab tab item.
+
+        (WebInspector.TabBar.prototype.get newTabTabBarItem): Deleted.
+        Unused.
+
+        * UserInterface/Views/TabBrowser.js:
+        (WebInspector.TabBrowser):
+        (WebInspector.TabBrowser.prototype._tabBarItemAdded):
+        (WebInspector.TabBrowser.prototype._tabBarItemRemoved):
+        (WebInspector.TabBrowser.prototype._handleNewTabContextMenu): Added.
+        Create an array that keeps track of tabs as they are closed, and populate the contextmenu
+        of the New Tab tab item with entries for each of these tabs.
+
+2017-01-23  Devin Rousso  <[email protected]>
+
         Web Inspector: tree elements with depth > 1 should have context menu "expand all"/"collapse all" commands
         https://bugs.webkit.org/show_bug.cgi?id=135590
 

Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (211063 => 211064)


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2017-01-23 22:49:26 UTC (rev 211063)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2017-01-23 23:06:26 UTC (rev 211064)
@@ -609,6 +609,7 @@
 localizedStrings["Range Issue"] = "Range Issue";
 localizedStrings["Readonly"] = "Readonly";
 localizedStrings["Reasons for compositing:"] = "Reasons for compositing:";
+localizedStrings["Recently Closed Tabs"] = "Recently Closed Tabs";
 localizedStrings["Recording Timeline Data"] = "Recording Timeline Data";
 localizedStrings["Reference Issue"] = "Reference Issue";
 localizedStrings["Reflection"] = "Reflection";

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TabBar.js (211063 => 211064)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TabBar.js	2017-01-23 22:49:26 UTC (rev 211063)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TabBar.js	2017-01-23 23:06:26 UTC (rev 211064)
@@ -49,13 +49,12 @@
         this._newTabTabBarItem = new WebInspector.PinnedTabBarItem("Images/NewTabPlus.svg", WebInspector.UIString("Create a new tab"));
         this._newTabTabBarItem.element.addEventListener("mouseenter", this._handleNewTabMouseEnter.bind(this));
         this._newTabTabBarItem.element.addEventListener("click", this._handleNewTabClick.bind(this));
+        this._newTabTabBarItem.element.addEventListener("contextmenu", this._handleNewTabContextMenu.bind(this));
         this.addTabBarItem(this._newTabTabBarItem, true);
     }
 
     // Public
 
-    get newTabTabBarItem() { return this._newTabTabBarItem; }
-
     updateNewTabTabBarItemState()
     {
         let newTabExists = !WebInspector.isNewTabWithTypeAllowed(WebInspector.NewTabContentView.Type);
@@ -730,6 +729,13 @@
         WebInspector.showNewTabTab(shouldAnimate);
     }
 
+    _handleNewTabContextMenu(event)
+    {
+        let contextMenu = WebInspector.ContextMenu.createFromEvent(event);
+
+        this.dispatchEventToListeners(WebInspector.TabBar.Event.NewTabContextMenu, {contextMenu});
+    }
+
     _handleNewTabMouseEnter(event)
     {
         if (!this._tabAnimatedClosedSinceMouseEnter || !this.element.classList.contains("static-layout") || this.element.classList.contains("animating"))
@@ -744,5 +750,6 @@
     TabBarItemAdded: "tab-bar-tab-bar-item-added",
     TabBarItemRemoved: "tab-bar-tab-bar-item-removed",
     TabBarItemsReordered: "tab-bar-tab-bar-items-reordered",
+    NewTabContextMenu: "tab-bar-new-tab-contextmenu",
     OpenDefaultTab: "tab-bar-open-default-tab"
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TabBrowser.js (211063 => 211064)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TabBrowser.js	2017-01-23 22:49:26 UTC (rev 211063)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TabBrowser.js	2017-01-23 23:06:26 UTC (rev 211064)
@@ -72,9 +72,12 @@
         this._showPreviousTabKeyboardShortcut3.implicitlyPreventsDefault = false;
 
         this._tabBar.addEventListener(WebInspector.TabBar.Event.TabBarItemSelected, this._tabBarItemSelected, this);
+        this._tabBar.addEventListener(WebInspector.TabBar.Event.TabBarItemAdded, this._tabBarItemAdded, this);
         this._tabBar.addEventListener(WebInspector.TabBar.Event.TabBarItemRemoved, this._tabBarItemRemoved, this);
+        this._tabBar.addEventListener(WebInspector.TabBar.Event.NewTabContextMenu, this._handleNewTabContextMenu, this);
 
         this._recentTabContentViews = [];
+        this._closedTabClasses = new Set;
     }
 
     // Public
@@ -246,6 +249,17 @@
         this.dispatchEventToListeners(WebInspector.TabBrowser.Event.SelectedTabContentViewDidChange);
     }
 
+    _tabBarItemAdded(event)
+    {
+        let tabContentView = event.data.tabBarItem.representedObject;
+
+        console.assert(tabContentView);
+        if (!tabContentView)
+            return;
+
+        this._closedTabClasses.delete(tabContentView.constructor);
+    }
+
     _tabBarItemRemoved(event)
     {
         let tabContentView = event.data.tabBarItem.representedObject;
@@ -255,6 +269,10 @@
             return;
 
         this._recentTabContentViews.remove(tabContentView);
+
+        if (!tabContentView.constructor.isEphemeral())
+            this._closedTabClasses.add(tabContentView.constructor);
+
         this._contentViewContainer.closeContentView(tabContentView);
 
         tabContentView.parentTabBrowser = null;
@@ -263,6 +281,35 @@
         console.assert(!this.selectedTabContentView || this.selectedTabContentView === this._recentTabContentViews[0]);
     }
 
+    _handleNewTabContextMenu(event)
+    {
+        // The array must be reversed because Sets insert into the end, and we want to display the
+        // most recently closed item first (which is the last item added to the set).
+        let closedTabClasses = Array.from(this._closedTabClasses).reverse();
+        let allTabClasses = Array.from(WebInspector.knownTabClasses());
+        let tabClassesToDisplay = closedTabClasses.concat(allTabClasses.filter((tabClass) => {
+            if (closedTabClasses.includes(tabClass))
+                return false;
+
+            if (tabClass.isEphemeral())
+                return false;
+
+            return WebInspector.isNewTabWithTypeAllowed(tabClass.Type);
+        }));
+        if (!tabClassesToDisplay.length)
+            return;
+
+        let contextMenu = event.data.contextMenu;
+
+        contextMenu.appendItem(WebInspector.UIString("Recently Closed Tabs"), null, true);
+
+        for (let tabClass of tabClassesToDisplay) {
+            contextMenu.appendItem(tabClass.tabInfo().title, () => {
+                WebInspector.createNewTabWithType(tabClass.Type, {shouldShowNewTab: true});
+            });
+        }
+    }
+
     _sidebarPanelSelected(event)
     {
         if (this._ignoreSidebarEvents)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to