Repository: qutebrowser/qutebrowser

Issue:
Closing a pinned tab via click does not warn before close
On current master. I'll prepare a PR to fix this, so hopefully I'll submit that soon :smile: 


Discussion:

Resolving patch:
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -227,19 +227,6 @@ def _tab_close(self, tab, prev=False, next_=False, opposite=False):
             self._tabbed_browser.close_tab(tab)
             tabbar.setSelectionBehaviorOnRemove(old_selection_behavior)
 
-    def _tab_close_prompt_if_pinned(self, tab, force, yes_action):
-        """Helper method for tab_close.
-
-        If tab is pinned, prompt. If everything is good, run yes_action.
-        """
-        if tab.data.pinned and not force:
-            message.confirm_async(
-                title='Pinned Tab',
-                text="Are you sure you want to close a pinned tab?",
-                yes_action=yes_action, default=False)
-        else:
-            yes_action()
-
     @cmdutils.register(instance='command-dispatcher', scope='window')
     @cmdutils.argument('count', count=True)
     def tab_close(self, prev=False, next_=False, opposite=False,
@@ -260,7 +247,7 @@ def tab_close(self, prev=False, next_=False, opposite=False,
         close = functools.partial(self._tab_close, tab, prev,
                                   next_, opposite)
 
-        self._tab_close_prompt_if_pinned(tab, force, close)
+        self._tabbed_browser.tab_close_prompt_if_pinned(tab, force, close)
 
     @cmdutils.register(instance='command-dispatcher', scope='window',
                        name='tab-pin')
@@ -918,8 +905,9 @@ def _to_close(i):
         if not force:
             for i, tab in enumerate(self._tabbed_browser.widgets()):
                 if _to_close(i) and tab.data.pinned:
-                    self._tab_close_prompt_if_pinned(
-                        tab, force,
+                    self._tabbed_browser.tab_close_prompt_if_pinned(
+                        tab,
+                        force,
                         lambda: self.tab_only(
                             prev=prev, next_=next_, force=True))
                     return
diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py
--- a/qutebrowser/mainwindow/tabbedbrowser.py
+++ b/qutebrowser/mainwindow/tabbedbrowser.py
@@ -232,6 +232,19 @@ def shutdown(self):
         for tab in self.widgets():
             self._remove_tab(tab)
 
+    def tab_close_prompt_if_pinned(self, tab, force, yes_action):
+        """Helper method for tab_close.
+
+        If tab is pinned, prompt. If everything is good, run yes_action.
+        """
+        if tab.data.pinned and not force:
+            message.confirm_async(
+                title='Pinned Tab',
+                text="Are you sure you want to close a pinned tab?",
+                yes_action=yes_action, default=False)
+        else:
+            yes_action()
+
     def close_tab(self, tab, *, add_undo=True):
         """Close a tab.
 
@@ -366,7 +379,8 @@ def on_tab_close_requested(self, idx):
             log.webview.debug("Got invalid tab {} for index {}!".format(
                 tab, idx))
             return
-        self.close_tab(tab)
+        self.tab_close_prompt_if_pinned(
+            tab, False, lambda: self.close_tab(tab))
 
     @pyqtSlot(browsertab.AbstractTab)
     def on_window_close_requested(self, widget):


Test patch: