public TorrentTreeView() : base() { Torrents = new ListStore(typeof(Download), typeof(string), typeof(string), typeof(int), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string)); FilterModel = new Gtk.TreeModelFilter(Torrents, null); FilterModel.VisibleFunc = delegate(TreeModel model, TreeIter iter) { return(Filter == null ? true : Filter((Download)model.GetValue(iter, 0))); }; Model = FilterModel; this.torrentController = ServiceManager.Get <TorrentController> (); buildColumns(); Reorderable = true; HeadersVisible = true; HeadersClickable = true; Selection.Mode = SelectionMode.Multiple; Selection.Changed += Event.Wrap(delegate(object o, EventArgs e) { TreeIter iter; TreePath [] selectedTorrents = Selection.GetSelectedRows(); List <Download> downloads = new List <Download> (); foreach (TreePath path in Selection.GetSelectedRows()) { if (Torrents.GetIter(out iter, path)) { downloads.Add((Download)Torrents.GetValue(iter, 0)); } } torrentController.Select(downloads); }); sourceEntries = new TargetEntry [] { new TargetEntry(RowAtom.Name, TargetFlags.App, 0) }; targetEntries = new TargetEntry [] { new TargetEntry(RowAtom.Name, TargetFlags.Widget, 0), new TargetEntry(FileAtom.Name, TargetFlags.OtherApp, 0) }; EnableModelDragSource(Gdk.ModifierType.Button1Mask, sourceEntries, Gdk.DragAction.Copy); EnableModelDragDest(targetEntries, Gdk.DragAction.Copy); DragDataGet += OnTorrentDragDataGet; menu = new TorrentContextMenu(); torrentController.Added += delegate(object sender, DownloadAddedEventArgs e) { AddDownload(e.Download); }; torrentController.Removed += delegate(object sender, DownloadAddedEventArgs e) { RemoveDownload(e.Download); }; LabelController lc = ServiceManager.Get <LabelController> (); lc.SelectionChanged += delegate { TorrentLabel label = lc.Selection; Filter = delegate(Download download) { return(label.Torrents.Contains(download)); }; }; // FIXME: This shouldn't be necessary torrentController.Torrents.ForEach(AddDownload); }
public TorrentTreeView() : base() { Torrents = new ListStore (typeof (Download), typeof (string), typeof (string), typeof (int), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string)); FilterModel = new Gtk.TreeModelFilter (Torrents, null); FilterModel.VisibleFunc = delegate (TreeModel model, TreeIter iter) { return Filter == null ? true : Filter ((Download) model.GetValue (iter, 0)); }; Model = FilterModel; this.torrentController = ServiceManager.Get <TorrentController> (); buildColumns(); Reorderable = true; HeadersVisible = true; HeadersClickable = true; Selection.Mode = SelectionMode.Multiple; Selection.Changed += Event.Wrap (delegate (object o, EventArgs e) { TreeIter iter; TreePath [] selectedTorrents = Selection.GetSelectedRows (); List <Download> downloads = new List<Download> (); foreach (TreePath path in Selection.GetSelectedRows ()) { if (Torrents.GetIter (out iter, path)) { downloads.Add ((Download) Torrents.GetValue (iter, 0)); } } torrentController.Select (downloads); }); sourceEntries = new TargetEntry [] { new TargetEntry(RowAtom.Name, TargetFlags.App, 0) }; targetEntries = new TargetEntry [] { new TargetEntry(RowAtom.Name, TargetFlags.Widget, 0), new TargetEntry(FileAtom.Name, TargetFlags.OtherApp, 0) }; EnableModelDragSource(Gdk.ModifierType.Button1Mask, sourceEntries, Gdk.DragAction.Copy); EnableModelDragDest(targetEntries, Gdk.DragAction.Copy); DragDataGet += OnTorrentDragDataGet; menu = new TorrentContextMenu (); torrentController.Added += delegate(object sender, DownloadAddedEventArgs e) { AddDownload (e.Download); }; torrentController.Removed += delegate(object sender, DownloadAddedEventArgs e) { RemoveDownload (e.Download); }; LabelController lc = ServiceManager.Get <LabelController> (); lc.SelectionChanged += delegate { TorrentLabel label = lc.Selection; Filter = delegate (Download download) { return label.Torrents.Contains (download); }; }; // FIXME: This shouldn't be necessary torrentController.Torrents.ForEach (AddDownload); }