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

Lucian Branescu lucian.branescu at gmail.com
Thu Jul 22 09:05:42 EDT 2010


Could you please attach a patch against mainline master HEAD? (not
inline in the email)

Also, does it still crash?

On 1 July 2010 21:02, anishmangal2002 <anishmangal2002 at gmail.com> wrote:
> 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/tab-add.svg |   12 ++++++++++++
>  webactivity.py    |   17 +++++++++++++++--
>  webtoolbar.py     |   33 ++++++++++++++++++++++-----------
>  3 files changed, 49 insertions(+), 13 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..877f182 100644
> --- a/webactivity.py
> +++ b/webactivity.py
> @@ -154,6 +154,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
> @@ -194,6 +195,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)
> @@ -258,6 +260,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 +359,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 +462,8 @@ 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":
> +                self._load_homepage(new_tab=True)
>             else:
>                 return False
>
> diff --git a/webtoolbar.py b/webtoolbar.py
> index e7c20be..1f718d5 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
> @@ -68,7 +66,7 @@ class WebEntry(AddressEntry):
>            recognize changes caused directly by user actions"""
>         self.handler_block(self._change_hid)
>         try:
> -            self.props.text = text
> +            self.props.text = text
>         finally:
>             self.handler_unblock(self._change_hid)
>         self.set_position(-1)
> @@ -177,7 +175,7 @@ class WebEntry(AddressEntry):
>             if selected is None:
>                 selection.select_iter(model[-1].iter)
>                 self._set_text(model[-1][0])
> -            else:
> +            else:
>                 index = model.get_path(selected)[0]
>                 if index > 0:
>                     selection.select_path(index - 1)
> @@ -186,10 +184,10 @@ class WebEntry(AddressEntry):
>         elif keyname == 'Down':
>             if selected is None:
>                 down_iter = model.get_iter_first()
> -            else:
> +            else:
>                 down_iter = model.iter_next(selected)
>             if down_iter:
> -                selection.select_iter(down_iter)
> +                selection.select_iter(down_iter)
>                 self._set_text(model.get(down_iter, 0)[0])
>             return True
>         elif keyname == 'Return':
> @@ -218,13 +216,15 @@ 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,
>                      ([]))
>     }
>
> @@ -234,7 +234,7 @@ class PrimaryToolbar(ToolbarBox):
>         self._activity = act
>
>         self._tabbed_view = tabbed_view
> -
> +
>         self._loading = False
>
>         activity_button = ActivityToolbarButton(self._activity)
> @@ -252,7 +252,7 @@ class PrimaryToolbar(ToolbarBox):
>         entry_item.set_expand(True)
>         entry_item.add(self.entry)
>         self.entry.show()
> -
> +
>         self.toolbar.insert(entry_item, -1)
>         entry_item.show()
>
> @@ -262,7 +262,7 @@ class PrimaryToolbar(ToolbarBox):
>         self._back.connect('clicked', self._go_back_cb)
>         self.toolbar.insert(self._back, -1)
>         self._back.show()
> -
> +
>         self._forward = ToolButton('go-next-paired')
>         self._forward.set_tooltip(_('Forward'))
>         self._forward.props.sensitive = False
> @@ -270,6 +270,13 @@ class PrimaryToolbar(ToolbarBox):
>         self.toolbar.insert(self._forward, -1)
>         self._forward.show()
>
> +        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,10 +395,13 @@ 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()
> -
> +
>     def _go_forward_cb(self, button):
>         browser = self._tabbed_view.props.current_browser
>         browser.web_navigation.goForward()
> @@ -460,3 +470,4 @@ class PrimaryToolbar(ToolbarBox):
>
>     def _link_add_clicked_cb(self, button):
>         self.emit('add-link')
> +
> --
> 1.7.0.1
>
>


More information about the Sugar-devel mailing list