[Sugar-devel] [PATCH] Browse: Add support for creating multiple tabs

anishmangal2002 anishmangal2002 at gmail.com
Sat Jul 24 10:03:04 EDT 2010


This patch adds support to create multiple tabbed windows
in Browse. A tab may be added by either clicking the add tab
('+') icon in the activity toolbar or by pressing 'ctrl+t'.

HACK: Currently, the multiple tabs feature crashes the Browse activity
on cairo versions 1.8.10 or later. The exact cause for this
isn't exactly known. Thus, this patch disables the multiple tabs feature
if we are using cairo versions >= 1.08.10
More information can be found here:
[1] http://lists.sugarlabs.org/archive/sugar-devel/2010-July/025187.html

Signed-off-by: anishmangal2002 <anishmangal2002 at gmail.com>
---
 icons/tab-add.svg |   12 ++++++++++++
 webactivity.py    |   35 ++++++++++++++++++++++++++++++++---
 webtoolbar.py     |   19 +++++++++++++++----
 3 files changed, 59 insertions(+), 7 deletions(-)
 create mode 100644 icons/tab-add.svg

diff --git a/icons/tab-add.svg b/icons/tab-add.svg
new file mode 100644
index 0000000..c1457bd
--- /dev/null
+++ b/icons/tab-add.svg
@@ -0,0 +1,12 @@
+<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'[
+	<!ENTITY stroke_color "#010101">
+	<!ENTITY fill_color "#FFFFFF">
+]><svg enable-background="new 0 0 55.125 55" height="55px" version="1.1" viewBox="0 0 55.125 55" width="55.125px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px">
+<g display="block" id="tab-add">
+    <g transform="scale(.80)">
+    <g transform="translate(6.5, 6.5)">
+	<path d="M0,50 l55,0 l0,-15 l-5,0 l0,-25 q0,-5 -5,-5 l-35,0 q-5,0 -5,5 l0,25 l-5,0z M30.768,38.767c-0.002,1.774-1.438,3.216-3.214,3.214c-0.889,0.001-1.693-0.359-2.275-0.941c-0.582-0.581-0.94-1.385-0.94-2.27   l0-8.146h-8.146c-0.886-0.001-1.689-0.359-2.271-0.94c-0.582-0.583-0.942-1.388-0.942-2.276c0-1.773,1.439-3.213,3.217-3.211h8.143   v-8.143c-0.003-1.776,1.438-3.217,3.212-3.217c1.774,0,3.218,1.438,3.215,3.215l0.001,8.145l8.146,0.001   c1.775-0.005,3.212,1.438,3.213,3.213c0.002,1.775-1.441,3.214-3.215,3.215h-8.143V38.767z" fill="&fill_color;"/>
+    </g>
+    </g>
+</g>
+</svg>
\ No newline at end of file
diff --git a/webactivity.py b/webactivity.py
index d7d8651..bba1032 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -31,6 +31,7 @@ import sqlite3
 import cjson
 import gconf
 import locale
+import cairo
 
 # HACK: Needed by http://dev.sugarlabs.org/ticket/456
 import gnome
@@ -154,6 +155,7 @@ def _set_accept_languages():
     logging.debug('LANG set')
 
 from browser import TabbedView
+from browser import Browser
 from webtoolbar import PrimaryToolbar
 from edittoolbar import EditToolbar
 from viewtoolbar import ViewToolbar
@@ -192,9 +194,24 @@ class WebActivity(activity.Activity):
         branch = pref_service.getBranch("mozilla.widget.")
         branch.setBoolPref("disable-native-theme", True)
 
-        self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self)
+        # HACK
+        # Currently, the multiple tabs feature crashes the Browse activity
+        # on cairo versions 1.8.10 or later. The exact cause for this
+        # isn't exactly known. Thus, disable the multiple tabs feature
+        # if we come across cairo versions >= 1.08.10
+        # More information can be found here:
+        # [1] http://lists.sugarlabs.org/archive/sugar-devel/2010-July/025187.html
+        self._disable_multiple_tabs = cairo.cairo_version() >= 10810
+        if self._disable_multiple_tabs:
+            logging.warning('Not enabling the multiple tabs feature due'
+                ' to a bug in cairo/mozilla')
+
+        self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self,
+                self._disable_multiple_tabs)
         self._primary_toolbar.connect('add-link', self._link_add_button_cb)
 
+        self._primary_toolbar.connect('add-tab', self._new_tab_cb)
+
         self._tray = HTray()
         self.set_tray(self._tray, gtk.POS_BOTTOM)
         self._tray.show()
@@ -258,6 +275,9 @@ class WebActivity(activity.Activity):
         else:
             _logger.debug('Created activity')
 
+    def _new_tab_cb(self, gobject):
+        self._load_homepage(new_tab=True)
+
     def _shared_cb(self, activity_):
         _logger.debug('My activity was shared')
         self.initiating = True
@@ -354,8 +374,14 @@ class WebActivity(activity.Activity):
             self.messenger = Messenger(self.tube_conn, self.initiating,
                                        self.model)
 
-    def _load_homepage(self):
-        browser = self._tabbed_view.current_browser
+    def _load_homepage(self, new_tab=False):
+        # If new_tab is True, open the homepage in a new tab.
+        if new_tab:
+            browser = Browser()
+            self._tabbed_view._append_tab(browser)
+        else:
+            browser = self._tabbed_view.current_browser
+
         if os.path.isfile(_LIBRARY_PATH):
             browser.load_uri('file://' + _LIBRARY_PATH)
         else:
@@ -451,6 +477,9 @@ class WebActivity(activity.Activity):
             elif key_name == 'r':
                 flags = components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE
                 browser.web_navigation.reload(flags)
+            elif gtk.gdk.keyval_name(event.keyval) == "t":
+                if not self._disable_multiple_tabs:
+                    self._load_homepage(new_tab=True)
             else:
                 return False
 
diff --git a/webtoolbar.py b/webtoolbar.py
index e7c20be..69a3c8e 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -35,10 +35,8 @@ from sugar.activity import activity
 import filepicker
 import places
 
-
 _MAX_HISTORY_ENTRIES = 15
 
-
 class WebEntry(AddressEntry):
     _COL_ADDRESS = 0
     _COL_TITLE = 1
@@ -218,17 +216,19 @@ class WebEntry(AddressEntry):
         else:
             self._search_popup()
 
-
 class PrimaryToolbar(ToolbarBox):
     __gtype_name__ = 'PrimaryToolbar'
 
     __gsignals__ = {
         'add-link': (gobject.SIGNAL_RUN_FIRST,
                      gobject.TYPE_NONE,
+                     ([])),
+        'add-tab': (gobject.SIGNAL_RUN_FIRST,
+                     gobject.TYPE_NONE,
                      ([]))
     }
 
-    def __init__(self, tabbed_view, act):
+    def __init__(self, tabbed_view, act, disable_multiple_tabs):
         ToolbarBox.__init__(self)
 
         self._activity = act
@@ -270,6 +270,14 @@ class PrimaryToolbar(ToolbarBox):
         self.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)
+            self.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)
@@ -388,6 +396,9 @@ class PrimaryToolbar(ToolbarBox):
         browser.load_uri(entry.props.text)
         browser.grab_focus()
 
+    def _add_tab_cb(self, button):
+        self.emit('add-tab')
+
     def _go_back_cb(self, button):
         browser = self._tabbed_view.props.current_browser
         browser.web_navigation.goBack()
-- 
1.7.1



More information about the Sugar-devel mailing list