[Sugar-devel] [PATCH sugar] Journal: add alert to confirm before erasing an entry

Manuel Quiñones manuq at laptop.org
Mon Aug 20 22:14:35 EDT 2012


2012/8/19 Simon Schampijer <simon at schampijer.de>:
> Erasing an entry in the Journal does not ask for confirmation
> before doing the erase. This patch adds an alert to the ListView
> and the DetailView that asks for confirmation before doing the
> erase. This is part of the touch interaction work [1].
>
> Signed-off-by: Simon Schampijer <simon at laptop.org>

Acked-by: Manuel Quiñones <manuq at laptop.org>

> [1] http://wiki.sugarlabs.org/go/Features/Touch/Development#Journal
> ---
>  src/jarabe/journal/journaltoolbox.py | 26 ++++++++++++++++++++------
>  src/jarabe/journal/palettes.py       | 17 ++++++++++++++++-
>  2 files changed, 36 insertions(+), 7 deletions(-)
>
> diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
> index 2aa4153..5572668 100644
> --- a/src/jarabe/journal/journaltoolbox.py
> +++ b/src/jarabe/journal/journaltoolbox.py
> @@ -36,6 +36,7 @@ from sugar.graphics.combobox import ComboBox
>  from sugar.graphics.menuitem import MenuItem
>  from sugar.graphics.icon import Icon
>  from sugar.graphics.xocolor import XoColor
> +from sugar.graphics.alert import ConfirmationAlert
>  from sugar.graphics import iconentry
>  from sugar.graphics import style
>  from sugar import mime
> @@ -45,6 +46,7 @@ from jarabe.journal import misc
>  from jarabe.journal import model
>  from jarabe.journal.palettes import ClipboardMenu
>  from jarabe.journal.palettes import VolumeMenu
> +from jarabe.journal import journalwindow
>
>
>  _AUTOSEARCH_TIMEOUT = 1000
> @@ -438,12 +440,24 @@ class EntryToolbar(gtk.Toolbar):
>                        _('Error'))
>
>      def _erase_button_clicked_cb(self, button):
> -        registry = bundleregistry.get_registry()
> -
> -        bundle = misc.get_bundle(self._metadata)
> -        if bundle is not None and registry.is_installed(bundle):
> -            registry.uninstall(bundle)
> -        model.delete(self._metadata['uid'])
> +        alert = ConfirmationAlert()
> +        alert.props.title = _('Erase \"%s\"') % self._metadata['title']
> +        alert.props.msg = _('This will erase the entry \"%s\" perminantely.') \
> +            % self._metadata['title']
> +        alert.connect('response', self.__erase_alert_response_cb)
> +        journalwindow.get_journal_window().add_alert(alert)
> +        alert.show()
> +
> +    def __erase_alert_response_cb(self, alert, response_id):
> +        if response_id is gtk.RESPONSE_OK:
> +            journalwindow.get_journal_window().remove_alert(alert)
> +            registry = bundleregistry.get_registry()
> +            bundle = misc.get_bundle(self._metadata)
> +            if bundle is not None and registry.is_installed(bundle):
> +                registry.uninstall(bundle)
> +            model.delete(self._metadata['uid'])
> +        elif response_id is gtk.RESPONSE_CANCEL:
> +            journalwindow.get_journal_window().remove_alert(alert)

This remove_alert() call can be moved out of the if clause, and the
elif can be removed to avoid duplication.

>      def _resume_menu_item_activate_cb(self, menu_item, service_name):
>          misc.resume(self._metadata, service_name)
> diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
> index 8fc1e5d..90f5dee 100644
> --- a/src/jarabe/journal/palettes.py
> +++ b/src/jarabe/journal/palettes.py
> @@ -29,6 +29,7 @@ from sugar.graphics.palette import Palette
>  from sugar.graphics.menuitem import MenuItem
>  from sugar.graphics.icon import Icon
>  from sugar.graphics.xocolor import XoColor
> +from sugar.graphics.alert import ConfirmationAlert
>  from sugar import mime
>
>  from jarabe.model import friends
> @@ -36,6 +37,7 @@ from jarabe.model import filetransfer
>  from jarabe.model import mimeregistry
>  from jarabe.journal import misc
>  from jarabe.journal import model
> +from jarabe.journal import journalwindow
>
>
>  class ObjectPalette(Palette):
> @@ -142,7 +144,20 @@ class ObjectPalette(Palette):
>                        _('Error'))
>
>      def __erase_activate_cb(self, menu_item):
> -        model.delete(self._metadata['uid'])
> +        alert = ConfirmationAlert()
> +        alert.props.title = _('Erase \"%s\"') % self._metadata['title']
> +        alert.props.msg = _('This will erase the entry \"%s\" perminantely.') \
> +            % self._metadata['title']
> +        alert.connect('response', self.__erase_alert_response_cb)
> +        journalwindow.get_journal_window().add_alert(alert)
> +        alert.show()
> +
> +    def __erase_alert_response_cb(self, alert, response_id):
> +        if response_id is gtk.RESPONSE_OK:
> +            journalwindow.get_journal_window().remove_alert(alert)
> +            model.delete(self._metadata['uid'])
> +        elif response_id is gtk.RESPONSE_CANCEL:
> +            journalwindow.get_journal_window().remove_alert(alert)

Same here.  This is just styling so you can choose to push as-is, all
looks good.

>      def __detail_activate_cb(self, menu_item):
>          self.emit('detail-clicked', self._metadata['uid'])
> --
> 1.7.11.4
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel



-- 
.. manuq ..


More information about the Sugar-devel mailing list