[Xfce4-commits] <postler:master> Allow multiple selection and deletion of messages
Christian Dywan
noreply at xfce.org
Sat May 29 19:34:01 CEST 2010
Updating branch refs/heads/master
to ba6e00a03588bb77d1af7fde0907be0750f5cde9 (commit)
from b3501ada850617b0525b826835f0861b354ebfd3 (commit)
commit ba6e00a03588bb77d1af7fde0907be0750f5cde9
Author: Christian Dywan <christian at twotoasts.de>
Date: Sat May 29 17:55:31 2010 +0200
Allow multiple selection and deletion of messages
postler/postler-messages.vala | 70 ++++++++++++++++++++++++++++-------------
1 files changed, 48 insertions(+), 22 deletions(-)
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index ebda4ec..c461dbe 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -35,15 +35,27 @@ public class Postler.Messages : Gtk.TreeView {
TIMESTAMP
}
+ void selection_changed () {
+ GLib.List<Gtk.TreePath> paths = get_selection ().get_selected_rows (null);
+ var path = paths.nth_data (0);
+ string location = null;
+ if (path != null) {
+ Gtk.TreeIter sort_iter;
+ if (sort.get_iter (out sort_iter, path))
+ sort.get (sort_iter, Columns.LOCATION, out location, -1);
+ }
+ selected_location = location;
+ }
+
public Messages () {
- /* TreeModelSort m*/
store = new Gtk.TreeStore (10, typeof (string), typeof (string),
typeof (string), typeof (string), typeof (int), typeof (string),
typeof (string), typeof (string), typeof (string), typeof (ulong));
sort = new Gtk.TreeModelSort.with_model (store);
set_model (sort);
set_search_column (Columns.SUBJECT); /* FIXME doesn't work atm */
- /* TODO: Allow multiple selections */
+ get_selection ().set_mode (Gtk.SelectionMode.MULTIPLE);
+ get_selection ().changed.connect (selection_changed);
insert_column_with_attributes (-1, _("Flagged"),
new Gtk.CellRendererPixbuf (), "stock-id", Columns.FLAGGED, null);
insert_column_with_attributes (-1, _("Status"),
@@ -127,7 +139,6 @@ public class Postler.Messages : Gtk.TreeView {
public void clear () {
store.clear ();
- selected_location = null;
content.clear ();
}
@@ -273,30 +284,41 @@ public class Postler.Messages : Gtk.TreeView {
public void delete_selected () {
/* TODO: Optionally move to waste bin if deleting from inbox */
- Gtk.TreeIter sort_iter;
- if (get_selection ().get_selected (null, out sort_iter)) {
- string location;
- sort.get (sort_iter, Columns.LOCATION, out location, -1);
- var file = File.new_for_path (location);
- try {
- file.delete (null);
- Gtk.TreeIter child_iter;
- sort.convert_iter_to_child_iter (out child_iter, sort_iter);
- store.remove (child_iter);
- selected_location = null;
- content.clear ();
- /* Restore selection */
- } catch (GLib.Error error) {
- GLib.critical (_("Failed to delete message \"%s\": %s"),
- location, error.message);
+ GLib.List<Gtk.TreePath> paths;
+ var references = new GLib.List<Gtk.TreeRowReference> ();
+
+ paths = get_selection ().get_selected_rows (null);
+ foreach (var path in paths)
+ references.prepend (new Gtk.TreeRowReference (sort, path));
+
+ foreach (var reference in references) {
+ var path = reference.get_path ();
+ Gtk.TreeIter sort_iter;
+ if (sort.get_iter (out sort_iter, path)) {
+ string location;
+ sort.get (sort_iter, Columns.LOCATION, out location, -1);
+ var file = File.new_for_path (location);
+ try {
+ file.delete (null);
+ Gtk.TreeIter child_iter;
+ sort.convert_iter_to_child_iter (out child_iter, sort_iter);
+ store.remove (child_iter);
+ content.clear ();
+ /* Restore selection */
+ } catch (GLib.Error error) {
+ GLib.critical (_("Failed to delete message \"%s\": %s"),
+ location, error.message);
+ }
}
}
}
override bool button_press_event (Gdk.EventButton event) {
if (event.type == Gdk.EventType.2BUTTON_PRESS) {
+ GLib.List<Gtk.TreePath> paths = get_selection ().get_selected_rows (null);
Gtk.TreeIter sort_iter;
- if (get_selection ().get_selected (null, out sort_iter)) {
+ var path = paths.nth_data (0);
+ if (sort.get_iter (out sort_iter, path)) {
string location;
sort.get (sort_iter, Columns.LOCATION, out location, -1);
Postler.App.spawn_module ("content", location);
@@ -306,10 +328,14 @@ public class Postler.Messages : Gtk.TreeView {
}
override bool button_release_event (Gdk.EventButton event) {
+ if (event.state != Gdk.ModifierType.BUTTON1_MASK)
+ return base.button_release_event (event);
+
+ GLib.List<Gtk.TreePath> paths = get_selection ().get_selected_rows (null);
Gtk.TreeIter sort_iter;
- if (get_selection ().get_selected (null, out sort_iter)) {
+ var path = paths.nth_data (0);
+ if (sort.get_iter (out sort_iter, path))
display_message (sort_iter);
- }
return base.button_release_event (event);
}
More information about the Xfce4-commits
mailing list