[Sugar-devel] [PATCH] Browse: Set and restore index in the history - Fix OLPC #10779

Rafael Ortiz rafael at activitycentral.com
Tue Jun 7 13:30:53 EDT 2011


On Mon, Jun 6, 2011 at 3:31 PM, <godiard at sugarlabs.org> wrote:

> From: Gonzalo Odiard <godiard at gmail.com>
>
> If the user go back, or select any page in the history and
> close the activity, need restore at the next start, the history,
> and the index in the history too.
> ---
>  browser.py     |    6 ++++++
>  webactivity.py |   24 ++++++++++--------------
>  2 files changed, 16 insertions(+), 14 deletions(-)
>
> diff --git a/browser.py b/browser.py
> index b9c1f69..9bb7a1b 100644
> --- a/browser.py
> +++ b/browser.py
> @@ -351,6 +351,12 @@ class Browser(WebView):
>                     interfaces.nsIMarkupDocumentViewer)
>             markupDocumentViewer.fullZoom -= _ZOOM_AMOUNT
>
> +    def get_history_index(self):
> +        return self.web_navigation.sessionHistory.index
> +
> +    def set_history_index(self, index):
> +        self.web_navigation.gotoIndex(index)
> +
>
>  class PopupDialog(gtk.Window):
>     def __init__(self):
> diff --git a/webactivity.py b/webactivity.py
> index 48cb3ed..8619144 100644
> --- a/webactivity.py
> +++ b/webactivity.py
> @@ -458,6 +458,12 @@ class WebActivity(activity.Activity):
>                                       link['owner'], -1, link['hash'])
>             logging.debug('########## reading %s', data)
>             self._tabbed_view.set_session(self.model.data['history'])
> +            tab_number = 0
> +            for current in self.model.data['currents']:
> +                browser = self._tabbed_view.get_nth_page(tab_number)
> +                browser.set_history_index(current['index'])
> +                tab_number = tab_number + 1
> +
>
> self._tabbed_view.set_current_page(self.model.data['current_tab'])
>         elif self.metadata['mime_type'] == 'text/uri-list':
>             data = self._get_data_from_file_path(file_path)
> @@ -469,19 +475,6 @@ class WebActivity(activity.Activity):
>                               'list of multiple uris by now.')
>         else:
>             self._tabbed_view.props.current_browser.load_uri(file_path)
> -        self._load_urls()
> -
> -    def _load_urls(self):
> -        if self.model.data['currents'] != None:
> -            first = True
> -            for current_tab in self.model.data['currents']:
> -                if first:
> -                    browser = self._tabbed_view.current_browser
> -                    first = False
> -                else:
> -                    browser = Browser()
> -                    self._tabbed_view._append_tab(browser)
> -                browser.load_uri(current_tab['url'])
>
>     def write_file(self, file_path):
>         if not self.metadata['mime_type']:
> @@ -505,7 +498,10 @@ class WebActivity(activity.Activity):
>                 if n_browser != None:
>                     nsiuri = browser.progress.location
>                     ui_uri = browser.get_url_from_nsiuri(nsiuri)
> -                    info = {'title': browser.props.title, 'url': ui_uri}
> +                    index = browser.get_history_index()
> +                    info = {'title': browser.props.title, 'url': ui_uri,
> +                            'index': index}
> +
>                     self.model.data['currents'].append(info)
>
>             f = open(file_path, 'w')
> --
> 1.7.4.4
>
>
Tested and works as expected.

Thanks and cheers.

>  _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20110607/e0a21cf3/attachment-0001.html>


More information about the Sugar-devel mailing list