From 41340e8009c54c6bfc10dedb55aff2abc25d8015 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 5 Apr 2010 11:37:27 -0300 Subject: [PATCH] Added a "selected" property with the selected message; changed the signatures for mark_all_read and clear_posts, since they are not triggered from widgets anymore. --- mitterlib/ui/helpers/gtk_messagegrid.py | 34 +++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mitterlib/ui/helpers/gtk_messagegrid.py b/mitterlib/ui/helpers/gtk_messagegrid.py index 1a4326a..fe2d6ef 100644 --- a/mitterlib/ui/helpers/gtk_messagegrid.py +++ b/mitterlib/ui/helpers/gtk_messagegrid.py @@ -86,6 +86,17 @@ class MessageGrid(gtk.ScrolledWindow, gobject.GObject): self.emit('count-changed', messages) return + @property + def selected(self): + """Return the selected message or None if there is no selected + message.""" + (model, iter) = view.get_selection().get_selected() + if not iter: + return None + + data = model.get_value(iter, 0) + return data + def __init__(self, avatar_cache): super(MessageGrid, self).__init__() @@ -212,21 +223,16 @@ class MessageGrid(gtk.ScrolledWindow, gobject.GObject): # Widget callbacks #----------------------------------------------------------------------- def _message_selected(self, view, user_data=None): - """Callback when a row in the list is selected. Mostly, we'll check - if the message is from the logged user and we change de "sensitive" - property of the message actions to reflect what the user can and - cannot do.""" + """Callback when a row in the list is selected.""" + message = self.selected + if not message: + return 0 - (model, iter) = view.get_selection().get_selected() - if not iter: - return - - data = model.get_value(iter, 0) - if not data.read: + if not message.read: self.count -= 1 - data.read = True - self.emit('message-changed', data) + message.read = True + self.emit('message-changed', message) return 0 def _click_message(self, widget, event, user_data=None): @@ -351,13 +357,13 @@ class MessageGrid(gtk.ScrolledWindow, gobject.GObject): self.count += len(messages) return - def clear_posts(self, widget, user_data=None): + def clear_posts(self): """Clear the list of posts from the grid.""" self._grid.get_model().clear() self.count = 0; return - def mark_all_read(self, widget, user_data=None): + def mark_all_read(self): """Mark all messages as read.""" model = self._grid.get_model() if len(model) == 0: