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

anishmangal2002 anishmangal2002 at gmail.com
Thu Jul 1 09:14:51 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'.

Signed-off-by: anishmangal2002 <anishmangal2002 at gmail.com>
---
 icons/add-tab.svg |   40 ++++++++++++++++++++++++++++++++++++++++
 webactivity.py    |   20 +++++++++++++++++---
 webtoolbar.py     |   13 +++++++++++++
 3 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 icons/add-tab.svg

diff --git a/icons/add-tab.svg b/icons/add-tab.svg
new file mode 100644
index 0000000..d8eaea8
--- /dev/null
+++ b/icons/add-tab.svg
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   version="1.1"
+   width="55"
+   height="55"
+   id="svg2">
+  <defs
+     id="defs4" />
+  <g
+     transform="translate(0,-997.36218)"
+     id="layer1">
+    <rect
+       width="55"
+       height="55"
+       x="0"
+       y="0"
+       transform="translate(0,997.36218)"
+       id="rect2818"
+       style="fill:none;stroke:none" />
+    <rect
+       width="9"
+       height="38"
+       x="23"
+       y="1005.8622"
+       id="rect3599"
+       style="fill:#ffffff;fill-opacity:1;stroke:none" />
+    <rect
+       width="8.94349"
+       height="37.99044"
+       x="1020.3485"
+       y="-47.595592"
+       transform="matrix(-0.00107369,0.99999942,-0.99999889,-0.00148761,0,0)"
+       id="rect3599-4"
+       style="fill:#ffffff;fill-opacity:1;stroke:none" />
+  </g>
+</svg>
diff --git a/webactivity.py b/webactivity.py
index 4be551e..38ec51a 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -152,6 +152,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
@@ -182,7 +183,7 @@ class WebActivity(activity.Activity):
 
         _set_accept_languages()
         _seed_xs_cookie()
-        
+
         # don't pick up the sugar theme - use the native mozilla one instead
         cls = components.classes['@mozilla.org/preferences-service;1']
         pref_service = cls.getService(components.interfaces.nsIPrefService)
@@ -191,6 +192,7 @@ class WebActivity(activity.Activity):
 
         self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self)
         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)
@@ -254,6 +256,9 @@ class WebActivity(activity.Activity):
                 self._joined_cb()
         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')        
@@ -351,8 +356,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:
@@ -443,6 +454,9 @@ class WebActivity(activity.Activity):
                 _logger.debug('keyboard: Zoom in')
                 self._tabbed_view.props.current_browser.zoom_in()
                 return True
+            elif gtk.gdk.keyval_name(event.keyval) == "t":
+                self._load_homepage(new_tab=True)
+
         return False
 
     def _add_link(self):
diff --git a/webtoolbar.py b/webtoolbar.py
index 854345c..5634083 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -222,6 +222,9 @@ class PrimaryToolbar(ToolbarBox):
     __gsignals__ = {
         'add-link': (gobject.SIGNAL_RUN_FIRST,
                      gobject.TYPE_NONE,
+                     ([])),
+        'add-tab': (gobject.SIGNAL_RUN_FIRST,
+                     gobject.TYPE_NONE,
                      ([]))
     }
 
@@ -267,6 +270,13 @@ class PrimaryToolbar(ToolbarBox):
         self.toolbar.insert(self._forward, -1)
         self._forward.show()
 
+        self._add_tab = ToolButton('add-tab')
+        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)
@@ -385,6 +395,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.0.1



More information about the Sugar-devel mailing list