From af97f9efae084bbe9ec394c2afc205dfd84e75ee Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Thu, 11 Aug 2016 07:44:11 +1000 Subject: [PATCH 1/2] Add add_undo parameter for closing tabs By default, closed tabs should be undoable, but when a tab is detached :undo should not reopen that tab in the old window. --- qutebrowser/browser/commands.py | 2 +- qutebrowser/mainwindow/tabbedbrowser.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 699546c6e..2964b6113 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -427,7 +427,7 @@ class CommandDispatcher: url = self._current_url() self._open(url, window=True) cur_widget = self._current_widget() - self._tabbed_browser.close_tab(cur_widget) + self._tabbed_browser.close_tab(cur_widget, add_undo=False) def _back_forward(self, tab, bg, window, count, forward): """Helper function for :back/:forward.""" diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 9fa1dcf59..b5dfcb5d9 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -217,11 +217,12 @@ class TabbedBrowser(tabwidget.TabWidget): for tab in self.widgets(): self._remove_tab(tab) - def close_tab(self, tab): + def close_tab(self, tab, add_undo=True): """Close a tab. Args: tab: The QWebView to be closed. + add_undo: Whether the tab close can be undone. """ last_close = config.get('tabs', 'last-close') count = self.count() @@ -229,7 +230,7 @@ class TabbedBrowser(tabwidget.TabWidget): if last_close == 'ignore' and count == 1: return - self._remove_tab(tab) + self._remove_tab(tab, add_undo=add_undo) if count == 1: # We just closed the last tab above. if last_close == 'close': @@ -243,11 +244,12 @@ class TabbedBrowser(tabwidget.TabWidget): url = config.get('general', 'default-page') self.openurl(url, newtab=True) - def _remove_tab(self, tab): + def _remove_tab(self, tab, add_undo=True): """Remove a tab from the tab list and delete it properly. Args: tab: The QWebView to be closed. + add_undo: Whether the tab close can be undone. """ idx = self.indexOf(tab) if idx == -1: @@ -261,8 +263,9 @@ class TabbedBrowser(tabwidget.TabWidget): window=self._win_id) if tab.url().isValid(): history_data = tab.history.serialize() - entry = UndoEntry(tab.url(), history_data, idx) - self._undo_stack.append(entry) + if add_undo: + entry = UndoEntry(tab.url(), history_data, idx) + self._undo_stack.append(entry) elif tab.url().isEmpty(): # There are some good reasons why a URL could be empty # (target="_blank" with a download, see [1]), so we silently ignore From ed137c01aa987f3b8c100570d795911059294322 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Thu, 11 Aug 2016 14:34:00 +1000 Subject: [PATCH 2/2] Make add_undo for tab close a keyword arg --- qutebrowser/mainwindow/tabbedbrowser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index b5dfcb5d9..1f0055df1 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -217,7 +217,7 @@ class TabbedBrowser(tabwidget.TabWidget): for tab in self.widgets(): self._remove_tab(tab) - def close_tab(self, tab, add_undo=True): + def close_tab(self, tab, *, add_undo=True): """Close a tab. Args: @@ -244,7 +244,7 @@ class TabbedBrowser(tabwidget.TabWidget): url = config.get('general', 'default-page') self.openurl(url, newtab=True) - def _remove_tab(self, tab, add_undo=True): + def _remove_tab(self, tab, *, add_undo=True): """Remove a tab from the tab list and delete it properly. Args: