Move removing of a tab out of close_tab.
This commit is contained in:
parent
2ef3733f21
commit
cda0f561aa
@ -225,40 +225,44 @@ class TabbedBrowser(TabWidget):
|
|||||||
for tab in self.widgets:
|
for tab in self.widgets:
|
||||||
self._tabs.remove(tab)
|
self._tabs.remove(tab)
|
||||||
|
|
||||||
def close_tab(self, tab_or_idx):
|
def close_tab(self, tab):
|
||||||
"""Close a tab with either index or tab given.
|
"""Close a tab with either index or tab given.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tab_or_index: Either the QWebView to be closed or an index.
|
tab: The QWebView to be closed.
|
||||||
"""
|
"""
|
||||||
try:
|
last_close = config.get('tabbar', 'last-close')
|
||||||
idx = int(tab_or_idx)
|
if self.count() > 1:
|
||||||
except TypeError:
|
self._remove_tab(tab)
|
||||||
tab = tab_or_idx
|
elif last_close == 'quit':
|
||||||
idx = self.indexOf(tab_or_idx)
|
self._remove_tab(tab)
|
||||||
if idx == -1:
|
self.quit.emit()
|
||||||
raise ValueError("tab {} is not contained in "
|
elif last_close == 'blank':
|
||||||
"TabbedWidget!".format(tab))
|
tab.openurl('about:blank')
|
||||||
else:
|
|
||||||
tab = self.widget(idx)
|
def _remove_tab(self, tab):
|
||||||
if tab is None:
|
"""Remove a tab from the tab list and delete it properly.
|
||||||
raise ValueError("invalid index {}!".format(idx))
|
|
||||||
|
Args:
|
||||||
|
tab: The QWebView to be closed.
|
||||||
|
|
||||||
|
Raise:
|
||||||
|
ValueError if the tab is not in the QTabWidget.
|
||||||
|
"""
|
||||||
|
idx = self.indexOf(tab)
|
||||||
|
if idx == -1:
|
||||||
|
raise ValueError("tab {} is not contained in TabbedWidget!".format(
|
||||||
|
tab))
|
||||||
if tab is self._now_focused:
|
if tab is self._now_focused:
|
||||||
self._now_focused = None
|
self._now_focused = None
|
||||||
if tab is self.last_focused:
|
if tab is self.last_focused:
|
||||||
self.last_focused = None
|
self.last_focused = None
|
||||||
last_close = config.get('tabbar', 'last-close')
|
url = tab.url()
|
||||||
if self.count() > 1:
|
if not url.isEmpty():
|
||||||
url = tab.url()
|
qt_ensure_valid(url)
|
||||||
if not url.isEmpty():
|
self.url_stack.append(url)
|
||||||
qt_ensure_valid(url)
|
self._tabs.remove(tab)
|
||||||
self.url_stack.append(url)
|
self.removeTab(idx)
|
||||||
self._tabs.remove(tab)
|
|
||||||
self.removeTab(idx)
|
|
||||||
elif last_close == 'quit':
|
|
||||||
self.quit.emit()
|
|
||||||
elif last_close == 'blank':
|
|
||||||
tab.openurl('about:blank')
|
|
||||||
|
|
||||||
@pyqtSlot('QUrl', bool)
|
@pyqtSlot('QUrl', bool)
|
||||||
def openurl(self, url, newtab):
|
def openurl(self, url, newtab):
|
||||||
|
Loading…
Reference in New Issue
Block a user