[Sugar-devel] [PATCH 1/4] Restore close tabs functionality

Manuel Quiñones manuq at laptop.org
Tue Nov 29 23:41:40 EST 2011


Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 browser.py |   53 ++++++++++++++++++++---------------------------------
 1 files changed, 20 insertions(+), 33 deletions(-)

diff --git a/browser.py b/browser.py
index 58bc614..f3c3f50 100644
--- a/browser.py
+++ b/browser.py
@@ -167,6 +167,7 @@ class TabbedView(BrowserNotebook):
             return browser.containerWindow
         else:
             browser = Browser()
+            browser.show()
             browser.connect('new-tab', self.__new_tab_cb)
             self._append_tab(browser)
 
@@ -191,9 +192,7 @@ class TabbedView(BrowserNotebook):
     def add_tab(self, next_to_current=False):
         browser = Browser()
         browser.connect('new-tab', self.__new_tab_cb)
-
-        label = TabLabel(browser)
-        label.connect('tab-close', self.__tab_close_cb)
+        browser.show()
 
         if next_to_current:
             self._insert_tab_next(browser)
@@ -204,36 +203,34 @@ class TabbedView(BrowserNotebook):
         return browser
 
     def _insert_tab_next(self, browser):
-        label = TabLabel(browser)
-        label.connect('tab-close', self.__tab_close_cb)
-
         scrolled_window = Gtk.ScrolledWindow()
         scrolled_window.show()
         scrolled_window.add(browser)
 
+        label = TabLabel(scrolled_window)
+        label.connect('tab-close', self.__tab_close_cb)
+
         next_index = self.get_current_page() + 1
         self.insert_page(scrolled_window, label, next_index)
-        browser.show()
         self.set_current_page(next_index)
 
     def _append_tab(self, browser):
-        label = TabLabel(browser)
-        label.connect('tab-close', self.__tab_close_cb)
-
         scrolled_window = Gtk.ScrolledWindow()
         scrolled_window.show()
         scrolled_window.add(browser)
 
+        label = TabLabel(scrolled_window)
+        label.connect('tab-close', self.__tab_close_cb)
+
         self.append_page(scrolled_window, label)
-        browser.show()
         self.set_current_page(-1)
 
     def on_add_tab(self, gobject):
         self.add_tab()
 
-    def __tab_close_cb(self, label, browser):
-        self.remove_page(self.page_num(browser))
-        browser.destroy()
+    def __tab_close_cb(self, label, browser_window):
+        self.remove_page(self.page_num(browser_window))
+        browser_window.destroy()
 
     def _update_tab_sizes(self):
         """Update ta widths based in the amount of tabs."""
@@ -305,6 +302,7 @@ class TabbedView(BrowserNotebook):
 
         for tab_session in tab_sessions:
             browser = Browser()
+            browser.show()
             browser.connect('new-tab', self.__new_tab_cb)
             self._append_tab(browser)
             sessionstore.set_session(browser, tab_session)
@@ -327,11 +325,12 @@ class TabLabel(Gtk.HBox):
                       ([object])),
     }
 
-    def __init__(self, browser):
+    def __init__(self, browser_window):
         GObject.GObject.__init__(self)
 
-        self._browser = browser
-        self._browser.connect('is-setup', self.__browser_is_setup_cb)
+        self._browser_window = browser_window
+        browser = browser_window.get_child()
+        browser.connect('notify::title', self.__title_changed_cb)
 
         self._label = Gtk.Label(label=_('Untitled'))
         self._label.set_ellipsize(Pango.EllipsizeMode.END)
@@ -364,25 +363,13 @@ class TabLabel(Gtk.HBox):
         self._close_button.show()
 
     def __button_clicked_cb(self, button):
-        self.emit('tab-close', self._browser)
+        self.emit('tab-close', self._browser_window)
 
-    def __browser_is_setup_cb(self, browser):
-        browser.progress.connect('notify::location',
-                                 self.__location_changed_cb)
-        browser.connect('notify::title', self.__title_changed_cb)
-
-    def __location_changed_cb(self, progress_listener, pspec):
-        url = self._browser.get_url_from_nsiuri(progress_listener.location)
-        if url == 'about:blank':
-            self._label.set_text(_('Loading...'))
+    def __title_changed_cb(self, widget, param):
+        if widget.props.title:
+            self._label.set_text(widget.props.title)
         else:
-            self._label.set_text(url)
-
-    def __title_changed_cb(self, browser, pspec):
-        if browser.props.title == "":
             self._label.set_text(_('Untitled'))
-        else:
-            self._label.set_text(browser.props.title)
 
 
 class Browser(WebKit.WebView):
-- 
1.7.7.3



More information about the Sugar-devel mailing list