[Sugar-devel] [PATCH Browse] Undo close tab SL #3534

Manuel Kaufmann humitos at gmail.com
Mon Sep 24 12:50:01 EDT 2012


Browse manages a list of 10 recently closed tab to be able to re-open
them (the most recently closed is opened firstly) by pressing
Ctrl+Shift+T.

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 browser.py     | 13 +++++++++++++
 webactivity.py | 11 +++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/browser.py b/browser.py
index de546f2..8f960cc 100644
--- a/browser.py
+++ b/browser.py
@@ -19,6 +19,7 @@
 import os
 import time
 import re
+import collections
 from gettext import gettext as _
 
 from gi.repository import GObject
@@ -99,6 +100,16 @@ class TabbedView(BrowserNotebook):
         self._update_closing_buttons()
         self._update_tab_sizes()
 
+        # LIFO queue of closed tabs (10 tabs max)
+        self.closed_tabs = collections.deque(maxlen=10)
+
+    def get_last_closed_tab(self):
+        try:
+            uri = self.closed_tabs.pop()
+        except IndexError:
+            uri = None
+        return uri
+
     def normalize_or_autosearch_url(self, url):
         """Normalize the url input or return a url for search.
 
@@ -164,6 +175,8 @@ class TabbedView(BrowserNotebook):
         self._update_tab_sizes()
 
     def __page_removed_cb(self, notebook, child, pagenum):
+        self.closed_tabs.append(child._browser.props.uri)
+
         if self.get_n_pages():
             self._update_closing_buttons()
             self._update_tab_sizes()
diff --git a/webactivity.py b/webactivity.py
index 24f3b44..2559fa7 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -428,8 +428,15 @@ class WebActivity(activity.Activity):
     def _key_press_cb(self, widget, event):
         key_name = Gdk.keyval_name(event.keyval)
         browser = self._tabbed_view.props.current_browser
-
-        if event.get_state() & Gdk.ModifierType.CONTROL_MASK:
+        state = event.get_state()
+
+        if state & Gdk.ModifierType.CONTROL_MASK:
+            if state & Gdk.ModifierType.SHIFT_MASK:
+                if key_name == 'T':
+                    uri = self._tabbed_view.get_last_closed_tab()
+                    if uri is not None:
+                        self._tabbed_view.current_browser.emit('new-tab', uri)
+                    return True
 
             if key_name == 'd':
                 self._add_link()
-- 
1.7.11.4



More information about the Sugar-devel mailing list