Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel QuiƱones <manuq@laptop.org>2013-09-05 14:02:03 (GMT)
committer Manuel QuiƱones <manuq@laptop.org>2013-09-05 14:03:53 (GMT)
commit8c9130e7533e41d637a7bc1cc70307e8bf945808 (patch)
tree11b261d9136c801313b65d2f2b6f959ff7ec8b8e
parent890de598bea714651c2a750f4312a1ab39790e2a (diff)
Add shortcut to close the current tab
And improve the code of the tab close Fixes #4590
-rw-r--r--browser.py27
-rw-r--r--webactivity.py3
2 files changed, 15 insertions, 15 deletions
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