[Sugar-devel] [PATCH 2/2] Browse: relocate Add Tab button next to the tab labels

Manuel Quiñones manuq at laptop.org
Sun Sep 4 17:11:59 EDT 2011


This is the same behaviour as in Firefox.  Removing Add Tab buttom
from the toolbar has the adventage that it left more space for the URL
entry.  This change was approved in the Design meeting of 28th August.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 browser.py     |   26 +++++++++-------
 webactivity.py |    8 +----
 webtoolbar.py  |   16 +---------
 widgets.py     |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 33 deletions(-)
 create mode 100644 widgets.py

diff --git a/browser.py b/browser.py
index c9a80c3..8cd00c6 100644
--- a/browser.py
+++ b/browser.py
@@ -31,11 +31,13 @@ from hulahop.webview import WebView
 from sugar import env
 from sugar.activity import activity
 from sugar.graphics import style
+from sugar.graphics.icon import Icon
 
 import sessionstore
 from palettes import ContentInvoker
 from sessionhistory import HistoryListener
 from progresslistener import ProgressListener
+from widgets import BrowserNotebook
 
 _ZOOM_AMOUNT = 0.1
 _LIBRARY_PATH = '/usr/share/library-common/index.html'
@@ -94,7 +96,7 @@ class CommandListener(object):
         cert_exception.showDialog(self._window)
 
 
-class TabbedView(gtk.Notebook):
+class TabbedView(BrowserNotebook):
     __gtype_name__ = 'TabbedView'
 
     _com_interfaces_ = interfaces.nsIWindowCreator
@@ -105,7 +107,7 @@ class TabbedView(gtk.Notebook):
                               'user-stylesheet.css')
 
     def __init__(self):
-        gobject.GObject.__init__(self)
+        BrowserNotebook.__init__(self)
 
         self.props.show_border = False
         self.props.scrollable = True
@@ -172,9 +174,11 @@ class TabbedView(gtk.Notebook):
 
         self.append_page(browser, label)
         browser.show()
-
         self.set_current_page(-1)
 
+    def on_add_tab(self, gobject):
+        self._load_homepage(new_tab=True)
+
     def __tab_close_cb(self, label, browser):
         self.remove_page(self.page_num(browser))
         browser.destroy()
@@ -250,18 +254,18 @@ class TabLabel(gtk.HBox):
         self.pack_start(self._label)
         self._label.show()
 
+        close_tab_icon = Icon(icon_name='browse-dialog-cancel')
+#        close_tab_icon.set_scale(0.4)
         button = gtk.Button()
-        button.connect('clicked', self.__button_clicked_cb)
-        button.set_name('browse-tab-close')
         button.props.relief = gtk.RELIEF_NONE
         button.props.focus_on_click = False
+        icon_box = gtk.HBox()
+        icon_box.pack_start(close_tab_icon, True, False, 0)
+        button.add(icon_box)
+        button.connect('clicked', self.__button_clicked_cb)
+        button.set_name('browse-tab-close')
         self.pack_start(button)
-        button.show()
-
-        close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE,
-                                               gtk.ICON_SIZE_MENU)
-        button.add(close_image)
-        close_image.show()
+        button.show_all()
 
     def __button_clicked_cb(self, button):
         self.emit('tab-close', self._browser)
diff --git a/webactivity.py b/webactivity.py
index c6dcc13..9999d95 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -230,15 +230,12 @@ class WebActivity(activity.Activity):
         self.set_tray(self._tray, gtk.POS_BOTTOM)
         self._tray.show()
 
-        self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self,
-                    self._disable_multiple_tabs)
+        self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self)
         self._edit_toolbar = EditToolbar(self)
         self._view_toolbar = ViewToolbar(self)
 
         self._primary_toolbar.connect('add-link', self._link_add_button_cb)
 
-        self._primary_toolbar.connect('add-tab', self._new_tab_cb)
-
         self._primary_toolbar.connect('go-home', self._go_home_button_cb)
 
         if NEW_TOOLBARS:
@@ -319,9 +316,6 @@ class WebActivity(activity.Activity):
         else:
             _logger.debug('Created activity')
 
-    def _new_tab_cb(self, gobject):
-        self._tabbed_view._load_homepage(new_tab=True)
-
     def _shared_cb(self, activity_):
         _logger.debug('My activity was shared')
         self.initiating = True
diff --git a/webtoolbar.py b/webtoolbar.py
index c0e097d..a4623be 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -228,15 +228,12 @@ class PrimaryToolbar(ToolbarBase):
         'add-link': (gobject.SIGNAL_RUN_FIRST,
                      gobject.TYPE_NONE,
                      ([])),
-        'add-tab': (gobject.SIGNAL_RUN_FIRST,
-                     gobject.TYPE_NONE,
-                     ([])),
         'go-home': (gobject.SIGNAL_RUN_FIRST,
                      gobject.TYPE_NONE,
                      ([])),
     }
 
-    def __init__(self, tabbed_view, act, disable_multiple_tabs):
+    def __init__(self, tabbed_view, act):
         ToolbarBase.__init__(self)
 
         self._activity = act
@@ -286,14 +283,6 @@ class PrimaryToolbar(ToolbarBase):
         toolbar.insert(self._forward, -1)
         self._forward.show()
 
-        if not disable_multiple_tabs:
-            self._add_tab = ToolButton('tab-add')
-            self._add_tab.set_tooltip(_('Add a tab'))
-            self._add_tab.props.sensitive = True
-            self._add_tab.connect('clicked', self._add_tab_cb)
-            toolbar.insert(self._add_tab, -1)
-            self._add_tab.show()
-
         self._link_add = ToolButton('emblem-favorite')
         self._link_add.set_tooltip(_('Bookmark'))
         self._link_add.connect('clicked', self._link_add_clicked_cb)
@@ -417,9 +406,6 @@ class PrimaryToolbar(ToolbarBase):
         browser.load_uri(entry.props.text)
         browser.grab_focus()
 
-    def _add_tab_cb(self, button):
-        self.emit('add-tab')
-
     def _go_home_cb(self, button):
         self.emit('go-home')
 
diff --git a/widgets.py b/widgets.py
new file mode 100644
index 0000000..8373047
--- /dev/null
+++ b/widgets.py
@@ -0,0 +1,88 @@
+# Copyright (C) 2006, Red Hat, Inc.
+# Copyright (C) 2007, One Laptop Per Child
+# Copyright (C) 2009, Tomeu Vizoso, Simon Schampijer
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+import gobject
+import gtk
+
+from sugar.graphics.notebook import Notebook
+from sugar.graphics.icon import Icon
+
+
+class TabAdd(gtk.HBox):
+    __gtype_name__ = 'TabAdd'
+
+    __gsignals__ = {
+        'tab-add': (gobject.SIGNAL_RUN_FIRST,
+                    gobject.TYPE_NONE,
+                    ([])),
+    }
+
+    def __init__(self):
+        gtk.HBox.__init__(self)
+
+        add_tab_icon = Icon(icon_name='add')
+#        add_tab_icon.set_scale(0.4)
+        button = gtk.Button()
+        button.props.relief = gtk.RELIEF_NONE
+        button.props.focus_on_click = False
+        icon_box = gtk.HBox()
+        icon_box.pack_start(add_tab_icon, True, False, 0)
+        button.add(icon_box)
+        button.connect('clicked', self.__button_clicked_cb)
+        button.set_name('browse-tab-add')
+        self.pack_start(button)
+        button.show_all()
+
+    def __button_clicked_cb(self, button):
+        self.emit('tab-add')
+
+
+class BrowserNotebook(Notebook):
+    """Handle an extra tab at the end with an Add Tab button."""
+
+    def __init__(self):
+        Notebook.__init__(self)
+
+        tab_add = TabAdd()
+        tab_add.connect('tab-add', self.on_add_tab)
+        empty_page = gtk.HBox()
+        self.append_page(empty_page, tab_add)
+        empty_page.show()
+        self.connect('switch-page', self.__on_switch_page)
+
+    def on_add_tab(self, gobject):
+        raise NotImplementedError, "implement this in the subclass"
+
+    def __on_switch_page(self, notebook, page, page_num):
+        """Don't switch to the extra tab at the end."""
+        if page_num == Notebook.get_n_pages(self) - 1:
+            self.stop_emission("switch-page")
+
+    def get_n_pages(self):
+        """Skip the extra tab at the end on the pages count."""
+        return Notebook.get_n_pages(self) - 1
+
+    def append_page(self, page, label):
+        """Append keeping the extra tab at the end."""
+        return self.insert_page(page, label, self.get_n_pages())
+
+    def set_current_page(self, number):
+        """If indexing from the end, skip the extra tab."""
+        if number < 0:
+            number = self.get_n_pages() - 1
+        return Notebook.set_current_page(self, number)
-- 
1.7.4.4



More information about the Sugar-devel mailing list