From 7b42a2eb587fd921b68095e2c86931dc8ca10d57 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 b03b0e3..16a2d2d 100644 --- a/browser.py +++ b/browser.py @@ -289,20 +289,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 < \ @@ -310,7 +302,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 c74f54a..43267e2 100644 --- a/webactivity.py +++ b/webactivity.py @@ -539,6 +539,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