From 683788dc91474f3de17e469c9dec50d55c82d54d Mon Sep 17 00:00:00 2001 From: Pootle daemon Date: Thu, 12 Jan 2012 05:32:29 +0000 Subject: Merge branch 'master' of git.sugarlabs.org:browse/mainline --- diff --git a/edittoolbar.py b/edittoolbar.py index 5c70546..958b6ad 100644 --- a/edittoolbar.py +++ b/edittoolbar.py @@ -20,15 +20,15 @@ from gi.repository import Gtk from gi.repository import Gdk from gettext import gettext as _ -from sugar3.activity import activity +from sugar3.activity.widgets import EditToolbar as BaseEditToolbar from sugar3.graphics import iconentry from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics import style -class EditToolbar(activity.EditToolbar): +class EditToolbar(BaseEditToolbar): def __init__(self, act): - activity.EditToolbar.__init__(self) + BaseEditToolbar.__init__(self) self._activity = act self._browser = None diff --git a/webactivity.py b/webactivity.py index 34f9b59..d3beb8b 100644 --- a/webactivity.py +++ b/webactivity.py @@ -260,10 +260,8 @@ class WebActivity(activity.Activity): _logger.debug('Offline') self.initiating = None - if self._shared_activity is not None: - _logger.debug('shared: %s', self._shared_activity.props.joined) - - if self._shared_activity is not None: + if self.get_shared_activity() is not None: + _logger.debug('shared: %s', self.get_shared()) # We are joining the activity _logger.debug('Joined activity') self.connect('joined', self._joined_cb) @@ -286,12 +284,12 @@ class WebActivity(activity.Activity): {}) def _setup(self): - if self._shared_activity is None: + if self.get_shared_activity() is None: _logger.debug('Failed to share or join activity') return bus_name, conn_path, channel_paths = \ - self._shared_activity.get_channels() + self.get_shared_activity().get_channels() # Work out what our room is called and whether we have Tubes already room = None @@ -343,7 +341,7 @@ class WebActivity(activity.Activity): _logger.debug('ListTubes() failed: %s', e) def _joined_cb(self, activity_): - if not self._shared_activity: + if not self.get_shared_activity(): return _logger.debug('Joined an existing shared activity') @@ -425,7 +423,7 @@ class WebActivity(activity.Activity): browser = self._tabbed_view.current_browser if not self._jobject.metadata['title_set_by_user'] == '1': - if browser.props.title == None: + if browser.props.title is None: self.metadata['title'] = _('Untitled') else: self.metadata['title'] = browser.props.title diff --git a/webtoolbar.py b/webtoolbar.py index badaf5d..ffc2864 100644 --- a/webtoolbar.py +++ b/webtoolbar.py @@ -365,6 +365,8 @@ class PrimaryToolbar(ToolbarBase): can_go_forward = self._browser.can_go_forward() self._forward.props.sensitive = can_go_forward + self._reload_session_history() + def _entry_activate_cb(self, entry): url = entry.props.text effective_url = self._tabbed_view.normalize_or_autosearch_url(url) @@ -403,46 +405,50 @@ class PrimaryToolbar(ToolbarBase): else: self._show_reload_icon() - def _reload_session_history(self, current_page_index=None): - browser = self._tabbed_view.props.current_browser - session_history = browser.web_navigation.sessionHistory - if current_page_index is None: - current_page_index = session_history.index + def _reload_session_history(self): + back_forward_list = self._browser.get_back_forward_list() + item_index = 0 # The index of the history item + # Clear menus in palettes: for palette in (self._back.get_palette(), self._forward.get_palette()): for menu_item in palette.menu.get_children(): palette.menu.remove(menu_item) - if current_page_index > _MAX_HISTORY_ENTRIES: - bottom = current_page_index - _MAX_HISTORY_ENTRIES - else: - bottom = 0 - if (session_history.count - current_page_index) > \ - _MAX_HISTORY_ENTRIES: - top = current_page_index + _MAX_HISTORY_ENTRIES + 1 - else: - top = session_history.count - - for i in range(bottom, top): - if i == current_page_index: - continue - - entry = session_history.getEntryAtIndex(i, False) - menu_item = MenuItem(entry.title, text_maxlen=60) - menu_item.connect('activate', self._history_item_activated_cb, i) - - if i < current_page_index: - palette = self._back.get_palette() - palette.menu.prepend(menu_item) - elif i > current_page_index: - palette = self._forward.get_palette() - palette.menu.append(menu_item) - + def create_menu_item(history_item, item_index): + """Create a MenuItem for the back or forward palettes.""" + title = history_item.get_title() + if not isinstance(title, unicode): + title = unicode(title, 'utf-8') + menu_item = MenuItem(title, text_maxlen=60) + menu_item.connect('activate', self._history_item_activated_cb, + item_index) + return menu_item + + back_list = back_forward_list.get_back_list_with_limit( + _MAX_HISTORY_ENTRIES) + back_list.reverse() + for item in back_list: + menu_item = create_menu_item(item, item_index) + palette = self._back.get_palette() + palette.menu.prepend(menu_item) + menu_item.show() + item_index += 1 + + # Increment the item index to count the current page: + item_index += 1 + + forward_list = back_forward_list.get_forward_list_with_limit( + _MAX_HISTORY_ENTRIES) + forward_list.reverse() + for item in forward_list: + menu_item = create_menu_item(item, item_index) + palette = self._forward.get_palette() + palette.menu.append(menu_item) menu_item.show() + item_index += 1 def _history_item_activated_cb(self, menu_item, index): - browser = self._tabbed_view.props.current_browser - browser.web_navigation.gotoIndex(index) + self._browser.set_history_index(index) def _link_add_clicked_cb(self, button): self.emit('add-link') -- cgit v0.9.1