From 8c9130e7533e41d637a7bc1cc70307e8bf945808 Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Thu, 05 Sep 2013 14:02:03 +0000 Subject: Add shortcut to close the current tab And improve the code of the tab close Fixes #4590 --- diff --git a/browser.py b/browser.py index 397b4fd..18c16ab 100644 --- a/browser.py +++ b/browser.py @@ -286,20 +286,12 @@ class TabbedView(BrowserNotebook): def on_add_tab(self, gobject): self.add_tab() - def __tab_close_cb(self, label, tab_page): - if tab_page.props.browser == self.props.current_browser: - # Current browser was just closed. The next tab of it has - # to take the focus. - current_page_num = self.page_num(tab_page) - - if self.get_n_pages() - 1 == current_page_num: - # This tab was the last. Grab the left one. - page_to_focus = current_page_num - 1 - else: - # This tab was in the middle. Grab the right one. - page_to_focus = current_page_num + 1 - nth_page = self.get_nth_page(page_to_focus) - nth_page.props.browser.grab_focus() + def close_tab(self, tab_page=None): + if self.get_n_pages() == 1: + return + + if tab_page is None: + tab_page = self.get_nth_page(self.get_current_page()) if isinstance(tab_page, PDFTabPage): if tab_page.props.browser.props.load_status < \ @@ -307,7 +299,12 @@ class TabbedView(BrowserNotebook): tab_page.cancel_download() self.remove_page(self.page_num(tab_page)) - tab_page.destroy() + + current_page = self.get_nth_page(self.get_current_page()) + current_page.props.browser.grab_focus() + + def __tab_close_cb(self, label, tab_page): + self.close_tab(tab_page) def _update_tab_sizes(self): """Update tab widths based in the amount of tabs.""" diff --git a/webactivity.py b/webactivity.py index 3c0d337..3232f9d 100644 --- a/webactivity.py +++ b/webactivity.py @@ -505,6 +505,9 @@ class WebActivity(activity.Activity): browser.reload() elif Gdk.keyval_name(event.keyval) == "t": self._tabbed_view.add_tab() + elif key_name == 'w': + _logger.debug('keyboard: close tab') + self._tabbed_view.close_tab() else: return False -- cgit v0.9.1